Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MRF Version and Validator Version Mismatch #122

Merged
merged 4 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
27 changes: 20 additions & 7 deletions src/SchemaManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

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