-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b1db9d0
commit 07365d3
Showing
10 changed files
with
206 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import { TokenList } from 'types'; | ||
import schema from './tokenlist.schema.json'; | ||
|
||
export * from './types'; | ||
export * from './isVersionUpdate'; | ||
|
||
export function validateTokenList(list: unknown): list is TokenList { | ||
return typeof list === 'object'; | ||
} | ||
export { schema }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Version } from './types'; | ||
|
||
/** | ||
* Returns true if versionB is an update over versionA | ||
*/ | ||
export function isVersionUpdate(versionA: Version, versionB: Version): boolean { | ||
if (versionB.major > versionA.major) { | ||
return true; | ||
} | ||
if (versionB.major < versionA.major) { | ||
return false; | ||
} | ||
if (versionB.minor > versionA.minor) { | ||
return true; | ||
} | ||
if (versionB.minor < versionA.minor) return false; | ||
return versionB.patch > versionA.patch; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { isVersionUpdate } from '../src'; | ||
|
||
describe('#isVersionUpdate', () => { | ||
it('major version increase', () => { | ||
expect( | ||
isVersionUpdate( | ||
{ major: 1, minor: 0, patch: 0 }, | ||
{ major: 2, minor: 0, patch: 0 } | ||
) | ||
).toEqual(true); | ||
expect( | ||
isVersionUpdate( | ||
{ major: 1, minor: 0, patch: 0 }, | ||
{ major: 1, minor: 0, patch: 0 } | ||
) | ||
).toEqual(false); | ||
expect( | ||
isVersionUpdate( | ||
{ major: 1, minor: 0, patch: 0 }, | ||
{ major: 0, minor: 0, patch: 0 } | ||
) | ||
).toEqual(false); | ||
expect( | ||
isVersionUpdate( | ||
{ major: 1, minor: 1, patch: 0 }, | ||
{ major: 2, minor: 0, patch: 0 } | ||
) | ||
).toEqual(true); | ||
}); | ||
|
||
it('minor version increase', () => { | ||
expect( | ||
isVersionUpdate( | ||
{ major: 1, minor: 0, patch: 0 }, | ||
{ major: 1, minor: 1, patch: 0 } | ||
) | ||
).toEqual(true); | ||
expect( | ||
isVersionUpdate( | ||
{ major: 1, minor: 0, patch: 0 }, | ||
{ major: 1, minor: 0, patch: 0 } | ||
) | ||
).toEqual(false); | ||
expect( | ||
isVersionUpdate( | ||
{ major: 1, minor: 1, patch: 0 }, | ||
{ major: 1, minor: 0, patch: 0 } | ||
) | ||
).toEqual(false); | ||
expect( | ||
isVersionUpdate( | ||
{ major: 1, minor: 1, patch: 1 }, | ||
{ major: 1, minor: 2, patch: 0 } | ||
) | ||
).toEqual(true); | ||
}); | ||
|
||
it('patch version', () => { | ||
expect( | ||
isVersionUpdate( | ||
{ major: 1, minor: 0, patch: 0 }, | ||
{ major: 1, minor: 1, patch: 0 } | ||
) | ||
).toEqual(true); | ||
expect( | ||
isVersionUpdate( | ||
{ major: 1, minor: 0, patch: 0 }, | ||
{ major: 1, minor: 0, patch: 0 } | ||
) | ||
).toEqual(false); | ||
expect( | ||
isVersionUpdate( | ||
{ major: 1, minor: 1, patch: 0 }, | ||
{ major: 1, minor: 0, patch: 0 } | ||
) | ||
).toEqual(false); | ||
expect( | ||
isVersionUpdate( | ||
{ major: 1, minor: 1, patch: 1 }, | ||
{ major: 1, minor: 2, patch: 0 } | ||
) | ||
).toEqual(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import Ajv from 'ajv'; | ||
import { schema } from '../src'; | ||
import example from './testschemas/example.tokenlist.json'; | ||
const ajv = new Ajv({ allErrors: true }); | ||
|
||
const validator = ajv.compile(schema); | ||
describe('schema', () => { | ||
it('is valid', () => { | ||
expect(ajv.validateSchema(schema)).toEqual(true); | ||
}); | ||
it('requires name, timestamp, version, tokens', () => { | ||
expect(validator({})).toEqual(false); | ||
expect(validator.errors).toEqual([ | ||
{ | ||
keyword: 'required', | ||
dataPath: '', | ||
schemaPath: '#/required', | ||
params: { missingProperty: 'name' }, | ||
message: "should have required property 'name'", | ||
}, | ||
{ | ||
keyword: 'required', | ||
dataPath: '', | ||
schemaPath: '#/required', | ||
params: { missingProperty: 'timestamp' }, | ||
message: "should have required property 'timestamp'", | ||
}, | ||
{ | ||
keyword: 'required', | ||
dataPath: '', | ||
schemaPath: '#/required', | ||
params: { missingProperty: 'version' }, | ||
message: "should have required property 'version'", | ||
}, | ||
{ | ||
keyword: 'required', | ||
dataPath: '', | ||
schemaPath: '#/required', | ||
params: { missingProperty: 'tokens' }, | ||
message: "should have required property 'tokens'", | ||
}, | ||
]); | ||
}); | ||
it('works for example schema', () => { | ||
expect(validator(example)).toEqual(true); | ||
expect(validator.errors).toBeNull(); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters