Skip to content

Commit

Permalink
MRF Version and Validator Version Mismatch
Browse files Browse the repository at this point in the history
  • Loading branch information
blakehice4 committed Nov 5, 2024
1 parent 8fa73f5 commit e40bc95
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
19 changes: 14 additions & 5 deletions src/SchemaManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,24 @@ export class SchemaManager {
.split('\n')
.map(tag => tag.trim())
.filter(tag => tag.length > 0)
.flatMap(tag => tag.startsWith('v') ? [tag, tag.slice(1)] : [tag]); // Adds both "vX.Y.Z" and "X.Y.Z" formats
if (tags.includes(version)) {
await util.promisify(exec)(`git -C "${this.repoDirectory}" checkout ${version}`);
this._version = version;
.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<string, string>);

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(
`Could not find a schema version named "${version}". Available versions are:\n${Object.keys(tags).join(
'\n'
)}`
);
Expand Down
11 changes: 11 additions & 0 deletions test/SchemaManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,21 @@ describe('SchemaManager', () => {
await expect(schemaManager.useVersion('v0.7')).resolves.toBe(true);
});

it('should resolve to true when the version exists in the repo2', 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 repo2', async () => {
const schemaManager = new SchemaManager(repoDirectory);
await expect(schemaManager.useVersion('0.6')).toReject();
});

});

describe('#useSchema', () => {
Expand Down

0 comments on commit e40bc95

Please sign in to comment.