Skip to content

Commit

Permalink
fix(core) Stricter semver check for template metadata
Browse files Browse the repository at this point in the history
Signed-off-by: Jerome Simeon <[email protected]>
  • Loading branch information
jeromesimeon committed Dec 16, 2019
1 parent c015f23 commit 65fe46d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
6 changes: 3 additions & 3 deletions packages/cicero-core/src/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ class Metadata {
throw new Error('Failed to find accordproject cicero version in package.json');
}

if(!semver.valid(semver.coerce(packageJson.accordproject.cicero))){
throw new Error('The cicero version must be a valid semantic version (semver) number.');
if(!semver.validRange(packageJson.accordproject.cicero)){
throw new Error('The cicero version must be a valid semantic version (semver) range.');
}

if(!semver.valid(semver.coerce(packageJson.version))){
if(!semver.valid(packageJson.version)){
throw new Error('The template version must be a valid semantic version (semver) number.');
}

Expand Down
17 changes: 15 additions & 2 deletions packages/cicero-core/test/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,20 @@ describe('Metadata', () => {
}, null, {})).should.throw('The template version must be a valid semantic version (semver) number.');
});

it('should throw an error if cicero version is not valid semver ', () => {
it('should throw an error if template version is not valid semver (1.0)', () => {
return (() => new Metadata({
name: 'template',
version: '1.0',
accordproject: {
template: 'clause',
ergo:'0.20.0-alpha.2',
cicero:ciceroVersion,
language: 'ergo'
},
}, null, {})).should.throw('The template version must be a valid semantic version (semver) number.');
});

it('should throw an error if cicero version is not valid semver range', () => {
return (() => new Metadata({
name: 'template',
version: '1.0.0',
Expand All @@ -165,7 +178,7 @@ describe('Metadata', () => {
ergo: 'BLEH',
language: 'ergo'
},
}, null, {})).should.throw('The cicero version must be a valid semantic version (semver) number.');
}, null, {})).should.throw('The cicero version must be a valid semantic version (semver) range.');
});

it('should throw an error if cicero version is not valid semver for current version of cicero', () => {
Expand Down

0 comments on commit 65fe46d

Please sign in to comment.