From 1a1cc0948565eb81050eed3ec7630c3ceff7f130 Mon Sep 17 00:00:00 2001 From: yrimal Date: Fri, 5 Jan 2024 14:42:34 -0500 Subject: [PATCH 1/3] #596 fix issue with semver validation for latest versions --- src/fn/upload-app-settings.js | 2 +- src/lib/get-api-version.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fn/upload-app-settings.js b/src/fn/upload-app-settings.js index 0e5d1e0ef..5758a762b 100644 --- a/src/fn/upload-app-settings.js +++ b/src/fn/upload-app-settings.js @@ -39,7 +39,7 @@ async function augmentDeclarativeWithNoolsBoilerplate(appSettings) { } const actualCoreVersion = await getValidApiVersion(appSettings); - const addNoolsBoilerplate = semver.lt(actualCoreVersion, '4.2.0-dev'); + const addNoolsBoilerplate = actualCoreVersion && semver.lt(actualCoreVersion, '4.2.0-dev'); if (addNoolsBoilerplate) { appSettings.tasks.rules = nools.addBoilerplateToCode(appSettings.tasks.rules); diff --git a/src/lib/get-api-version.js b/src/lib/get-api-version.js index 7e5cffcf4..410957cc0 100644 --- a/src/lib/get-api-version.js +++ b/src/lib/get-api-version.js @@ -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 }; From 9b56f91f9fac33d0737c20fac3c1546763c53614 Mon Sep 17 00:00:00 2001 From: yrimal Date: Mon, 8 Jan 2024 11:46:44 -0500 Subject: [PATCH 2/3] #596 add uunittest, update function call --- src/fn/upload-app-settings.js | 2 +- test/fn/upload-app-settings.spec.js | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/fn/upload-app-settings.js b/src/fn/upload-app-settings.js index 5758a762b..bea83d244 100644 --- a/src/fn/upload-app-settings.js +++ b/src/fn/upload-app-settings.js @@ -38,7 +38,7 @@ async function augmentDeclarativeWithNoolsBoilerplate(appSettings) { return; } - const actualCoreVersion = await getValidApiVersion(appSettings); + const actualCoreVersion = await getValidApiVersion(); const addNoolsBoilerplate = actualCoreVersion && semver.lt(actualCoreVersion, '4.2.0-dev'); if (addNoolsBoilerplate) { appSettings.tasks.rules = nools.addBoilerplateToCode(appSettings.tasks.rules); diff --git a/test/fn/upload-app-settings.spec.js b/test/fn/upload-app-settings.spec.js index 08b4aa876..e4037b55b 100644 --- a/test/fn/upload-app-settings.spec.js +++ b/test/fn/upload-app-settings.spec.js @@ -20,6 +20,10 @@ 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} ]; for (const scenario of scenarios) { From 7c5df2fcbd328d61c28b886f36f592eee02bfccd Mon Sep 17 00:00:00 2001 From: yrimal Date: Mon, 8 Jan 2024 19:10:37 -0500 Subject: [PATCH 3/3] #596 add more tests --- test/fn/upload-app-settings.spec.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/fn/upload-app-settings.spec.js b/test/fn/upload-app-settings.spec.js index e4037b55b..dfe7055e2 100644 --- a/test/fn/upload-app-settings.spec.js +++ b/test/fn/upload-app-settings.spec.js @@ -23,7 +23,11 @@ describe('upload-app-settings', () => { // 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} + { 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) {