diff --git a/lib/data/schema.js b/lib/data/schema.js index c26fa01dc..6a8c4ad2c 100644 --- a/lib/data/schema.js +++ b/lib/data/schema.js @@ -610,11 +610,11 @@ const _addBranchIdAndTrunkVersion = (xml) => new Promise((pass, fail) => { parser.end(); }); -const _updateEntityVersion = (xml, newVersion) => new Promise((pass, fail) => { +const _updateEntityVersion = (xml, oldVersion, newVersion) => new Promise((pass, fail) => { const stack = []; const parser = new hparser.Parser({ onattribute: (name, value) => { - if ((stripNamespacesFromPath(name) === 'entities-version') && (value === '2023.1.0') + if ((stripNamespacesFromPath(name) === 'entities-version') && (value === oldVersion) && (stack.length) === 2 && (stack[0] === 'html') && (stack[1] === 'head')) { const idx = parser._tokenizer._index; parser.reset(); @@ -636,10 +636,11 @@ const _updateEntityVersion = (xml, newVersion) => new Promise((pass, fail) => { parser.end(); }); -const updateEntityForm = (xml, newVersion, suffix) => - _updateEntityVersion(xml, newVersion) +const updateEntityForm = (xml, oldVersion, newVersion, suffix) => + _updateEntityVersion(xml, oldVersion, newVersion) .then(_addBranchIdAndTrunkVersion) - .then(x => addVersionSuffix(x, suffix)); + .then(x => addVersionSuffix(x, suffix)) + .catch(() => xml); module.exports = { getFormFields, diff --git a/test/unit/data/schema.js b/test/unit/data/schema.js index 725e4abd0..2037bc09b 100644 --- a/test/unit/data/schema.js +++ b/test/unit/data/schema.js @@ -2089,7 +2089,7 @@ describe('form schema', () => { describe('updateEntityForm', () => { it('should change version 2023->2024, add trunkVersion, and add branchId', () => - updateEntityForm(testData.forms.updateEntity, '2024.1.0', '_upgrade').then((result) => result.should.equal(` + updateEntityForm(testData.forms.updateEntity, '2023.1.0', '2024.1.0', '_upgrade').then((result) => result.should.equal(` @@ -2110,6 +2110,12 @@ describe('form schema', () => { `))); + + it('should not alter a version 2022.1.0 form when the old version to replace is 2023.1.0', () => + updateEntityForm(testData.forms.simpleEntity, '2023.1.0', '2024.1.0', '_upgrade').then((result) => result.should.equal(testData.forms.simpleEntity))); + + it('should not alter a version 2024.1.0 form when the old version to replace is 2023.1.0', () => + updateEntityForm(testData.forms.offlineEntity, '2023.1.0', '2024.1.0', '_upgrade').then((result) => result.should.equal(testData.forms.offlineEntity))); }); });