Skip to content

Commit

Permalink
Merge pull request #3137 from ONSdigital/migration-remove-confirmatio…
Browse files Browse the repository at this point in the history
…n-qcodes

Migration to remove confirmation qcodes
  • Loading branch information
farres1 authored Jan 16, 2025
2 parents 45c0e0e + a1a3afb commit 104320e
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 0 deletions.
1 change: 1 addition & 0 deletions eq-author-api/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const migrations = [
require("./updateHealthThemeToPandemicMonitoring"),
require("./addAllowableDataVersions"),
require("./convertEmTagsToStrongTags"),
require("./removeConfirmationPageQCodes"),
];

const currentVersion = migrations.length;
Expand Down
13 changes: 13 additions & 0 deletions eq-author-api/migrations/removeConfirmationPageQCodes.js
Original file line number Diff line number Diff line change
@@ -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;
};
137 changes: 137 additions & 0 deletions eq-author-api/migrations/removeConfirmationPageQCodes.test.js
Original file line number Diff line number Diff line change
@@ -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);
});
});

0 comments on commit 104320e

Please sign in to comment.