Skip to content

Commit

Permalink
fix(#596) fix issue with semver validation for latest versions
Browse files Browse the repository at this point in the history
* #596 fix issue with semver validation for latest versions

* #596 add uunittest, update function call

* #596 add more tests
  • Loading branch information
1yuv authored Jan 10, 2024
1 parent 958f0b4 commit bf7f647
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/fn/upload-app-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ async function augmentDeclarativeWithNoolsBoilerplate(appSettings) {
return;
}

const actualCoreVersion = await getValidApiVersion(appSettings);
const addNoolsBoilerplate = semver.lt(actualCoreVersion, '4.2.0-dev');
const actualCoreVersion = await getValidApiVersion();
const addNoolsBoilerplate = actualCoreVersion && semver.lt(actualCoreVersion, '4.2.0-dev');
if (addNoolsBoilerplate) {
appSettings.tasks.rules = nools.addBoilerplateToCode(appSettings.tasks.rules);

Expand Down
2 changes: 1 addition & 1 deletion src/lib/get-api-version.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const getApiVersion = async () => {
};

const getValidApiVersion = async () => {
return semver.valid(await getApiVersion());
return semver.valid(semver.coerce(await getApiVersion()));
};

module.exports = { getValidApiVersion };
8 changes: 8 additions & 0 deletions test/fn/upload-app-settings.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ describe('upload-app-settings', () => {

// case when testing on dev
{ coreVersion: '4.2.0-dev.1682192676689', isDeclarative: true, expectNools: false },
// https://github.com/medic/cht-conf/issues/596
{ coreVersion: '4.5.0.6922454971', isDeclarative: false, expectNools: false},
// non-declarative < 4.2
{ coreVersion: '4.1.0.6922454971', isDeclarative: undefined, expectNools: false},
// could not parse correct version
{coreVersion: null, isDeclarative: undefined, expectNools: false },
{coreVersion: null, isDeclarative: true, expectNools: false },
{coreVersion: null, isDeclarative: false, expectNools: false }
];

for (const scenario of scenarios) {
Expand Down

0 comments on commit bf7f647

Please sign in to comment.