Skip to content

Commit

Permalink
Add removeConfirmationPageQCodes tests
Browse files Browse the repository at this point in the history
  • Loading branch information
farres1 committed Jan 16, 2025
1 parent 43bd072 commit 80bf882
Showing 1 changed file with 133 additions and 0 deletions.
133 changes: 133 additions & 0 deletions eq-author-api/migrations/removeConfirmationPageQCodes.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
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: "123",
},
},
],
},
],
},
],
};

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: "123",
},
],
confirmation: {
id: "confirmation-page-1",
qCode: "123",
},
},
],
},
],
},
],
};

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("123");
});

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: "123",
},
],
},
],
},
],
},
],
};

const result = removeConfirmationPageQCodes(questionnaire);

expect(result.sections[0].folders[0].pages[0].answers[0].qCode).toBe("123");
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 80bf882

Please sign in to comment.