diff --git a/eq-author-api/migrations/index.js b/eq-author-api/migrations/index.js index cc793812be..c60c0b33f6 100644 --- a/eq-author-api/migrations/index.js +++ b/eq-author-api/migrations/index.js @@ -55,6 +55,7 @@ const migrations = [ require("./updateHealthThemeToPandemicMonitoring"), require("./addAllowableDataVersions"), require("./convertEmTagsToStrongTags"), + require("./removeConfirmationPageQCodes"), ]; const currentVersion = migrations.length; diff --git a/eq-author-api/migrations/removeConfirmationPageQCodes.js b/eq-author-api/migrations/removeConfirmationPageQCodes.js new file mode 100644 index 0000000000..d86973f21b --- /dev/null +++ b/eq-author-api/migrations/removeConfirmationPageQCodes.js @@ -0,0 +1,13 @@ +module.exports = (questionnaire) => { + questionnaire.sections.forEach((section) => { + section.folders.forEach((folder) => { + folder.pages.forEach((page) => { + if (page.confirmation && page.confirmation.qCode) { + delete page.confirmation.qCode; + } + }); + }); + }); + + return questionnaire; +}; diff --git a/eq-author-api/migrations/removeConfirmationPageQCodes.test.js b/eq-author-api/migrations/removeConfirmationPageQCodes.test.js new file mode 100644 index 0000000000..f731fab5a5 --- /dev/null +++ b/eq-author-api/migrations/removeConfirmationPageQCodes.test.js @@ -0,0 +1,137 @@ +const removeConfirmationPageQCodes = require("./removeConfirmationPageQCodes"); + +describe("removeConfirmationPageQCodes", () => { + it("should remove qCode from confirmation pages", () => { + const questionnaire = { + sections: [ + { + id: "section-1", + folders: [ + { + id: "folder-1", + pages: [ + { + id: "page-1", + confirmation: { + id: "confirmation-page-1", + qCode: "confirmation-page-1-qcode", + }, + }, + ], + }, + ], + }, + ], + }; + + const result = removeConfirmationPageQCodes(questionnaire); + + expect( + result.sections[0].folders[0].pages[0].confirmation.qCode + ).toBeUndefined(); + }); + + it("should not remove qCode from answers", () => { + const questionnaire = { + sections: [ + { + id: "section-1", + folders: [ + { + id: "folder-1", + pages: [ + { + id: "page-1", + answers: [ + { + id: "answer-1", + qCode: "answer-1-qCode", + }, + ], + confirmation: { + id: "confirmation-page-1", + qCode: "confirmation-page-1-qCode", + }, + }, + ], + }, + ], + }, + ], + }; + + const result = removeConfirmationPageQCodes(questionnaire); + + expect( + result.sections[0].folders[0].pages[0].confirmation.qCode + ).toBeUndefined(); + expect(result.sections[0].folders[0].pages[0].answers[0].qCode).toBe( + "answer-1-qCode" + ); + }); + + it("should not amend questionnaire data if the questionnaire does not contain any confirmation pages", () => { + const questionnaire = { + sections: [ + { + id: "section-1", + folders: [ + { + id: "folder-1", + pages: [ + { + id: "page-1", + answers: [ + { + id: "answer-1", + qCode: "answer-1-qCode", + }, + ], + }, + ], + }, + ], + }, + ], + }; + + const result = removeConfirmationPageQCodes(questionnaire); + + expect(result.sections[0].folders[0].pages[0].answers[0].qCode).toBe( + "answer-1-qCode" + ); + expect(result).toEqual(questionnaire); + }); + + it("should not amend questionnaire data if the questionnaire does not contain any qCodes", () => { + const questionnaire = { + sections: [ + { + id: "section-1", + folders: [ + { + id: "folder-1", + pages: [ + { + id: "page-1", + answers: [ + { + id: "answer-1", + }, + ], + confirmation: { + id: "confirmation-page-1", + }, + }, + ], + }, + ], + }, + ], + }; + + const result = removeConfirmationPageQCodes(questionnaire); + + expect(result).toEqual(questionnaire); + }); +});