diff --git a/package-lock.json b/package-lock.json index 487fdd7..2ce3280 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cms-mrf-validator", - "version": "2.1.0", + "version": "2.2.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "cms-mrf-validator", - "version": "2.1.0", + "version": "2.2.0", "license": "Apache-2.0", "dependencies": { "@streamparser/json": "^0.0.21", diff --git a/package.json b/package.json index c88c641..c86161c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cms-mrf-validator", - "version": "2.1.0", + "version": "2.2.0", "description": "Node-based entry point for machine-readable file validator", "main": "out/index.js", "bin": { diff --git a/src/SchemaManager.ts b/src/SchemaManager.ts index a08dcca..50580c3 100644 --- a/src/SchemaManager.ts +++ b/src/SchemaManager.ts @@ -44,17 +44,30 @@ export class SchemaManager { const tags = tagResult.stdout .split('\n') .map(tag => tag.trim()) - .filter(tag => tag.length > 0); - if (tags.includes(version)) { - await util.promisify(exec)(`git -C "${this.repoDirectory}" checkout ${version}`); - this._version = version; + .filter(tag => tag.length > 0) + .reduce( + (acc, tag) => { + if (tag.startsWith('v')) { + acc[tag] = tag; // Key with 'v' prefix + acc[tag.slice(1)] = tag; // Key without 'v' prefix + } else { + acc[tag] = 'v' + tag; // If no 'v' prefix, add one as the value + } + return acc; + }, + {} as Record + ); + + if (version in tags) { + await util.promisify(exec)(`git -C "${this.repoDirectory}" checkout ${tags[version]}`); + this._version = tags[version]; return true; } else { // we didn't find your tag. maybe you mistyped it, so show the available ones. throw new Error( - `Could not find a schema version named "${version}". Available versions are:\n${tags.join( - '\n' - )}` + `Could not find a schema version named "${version}". Available versions are:\n${Object.keys( + tags + ).join('\n')}` ); } } diff --git a/test/SchemaManager.test.ts b/test/SchemaManager.test.ts index fc42167..fb146c5 100644 --- a/test/SchemaManager.test.ts +++ b/test/SchemaManager.test.ts @@ -108,10 +108,20 @@ describe('SchemaManager', () => { await expect(schemaManager.useVersion('v0.7')).resolves.toBe(true); }); + it('should resolve to true when the version exists in the repo with a prefixed v', async () => { + const schemaManager = new SchemaManager(repoDirectory); + await expect(schemaManager.useVersion('0.7')).resolves.toBe(true); + }); + it('should reject when the version does not exist in the repo', async () => { const schemaManager = new SchemaManager(repoDirectory); await expect(schemaManager.useVersion('v0.6')).toReject(); }); + + it('should reject when the version does not exist in the repo with a prefixed v', async () => { + const schemaManager = new SchemaManager(repoDirectory); + await expect(schemaManager.useVersion('0.6')).toReject(); + }); }); describe('#useSchema', () => {