Skip to content

Commit

Permalink
Merge pull request #3027 from ONSdigital/Migration-Update-Introductio…
Browse files Browse the repository at this point in the history
…n-PreviewingQuestions-Setting

Add migration and tests
  • Loading branch information
kayloshai authored Jul 27, 2023
2 parents 69d85aa + 8ff31a1 commit 0960351
Show file tree
Hide file tree
Showing 3 changed files with 114 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 @@ -47,6 +47,7 @@ const migrations = [
require("./updateIntroductionEnabledWithValidation"),
require("./addRepeatingLabelAndInputFields"),
require("./addCollectionListAnswerRepeatingProperties"),
require("./updateIntroductionPreviewQuestionsSettings"),
];

const currentVersion = migrations.length;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = function updateIntroductionPreviewQuestionsSettings(
questionnaire
) {
if (questionnaire.introduction) {
if (!questionnaire.introduction.previewQuestions) {
questionnaire.introduction.previewQuestions = false;
}
if (!questionnaire.introduction.disallowPreviewQuestions) {
questionnaire.introduction.disallowPreviewQuestions = false;
}
if (
questionnaire.collectionLists &&
questionnaire.collectionLists.lists &&
questionnaire.collectionLists.lists.length > 0
) {
questionnaire.introduction.previewQuestions = false;
questionnaire.introduction.disallowPreviewQuestions = true;
}
return questionnaire;
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
const updateIntroductionPreviewQuestionsSettings = require("./updateIntroductionPreviewQuestionsSettings");

describe("updateIntroductionPreviewQuestionsSettings", () => {
it("should check for introduction", () => {
const questionnaire = {};
expect(
updateIntroductionPreviewQuestionsSettings(questionnaire)
).toBeFalsy();
});

it("should add preview questions equal to false if it doesnt exist", () => {
const questionnaire = { introduction: {} };
const updateIntroductionPreviewQuestion =
updateIntroductionPreviewQuestionsSettings(questionnaire);

expect(
updateIntroductionPreviewQuestion.introduction.previewQuestions
).toBe(false);
});

it("should add disallow preview questions equal to false if it doesnt exist", () => {
const questionnaire = { introduction: {} };
const updateIntroductionPreviewQuestion =
updateIntroductionPreviewQuestionsSettings(questionnaire);

expect(
updateIntroductionPreviewQuestion.introduction.disallowPreviewQuestions
).toBe(false);
});

it("should set previewQuestions to false and disallowPreviewQuestions to true if given a collection list is present", () => {
const questionnaire = {
introduction: {},
collectionLists: {
id: "collection-list-1",
lists: [
{
id: "list-1",
listName: "List 1",
answers: [
{
id: "list-answer-1",
type: "TextField",
label: "List answer 1",
},
],
},
],
},
};
const updateIntroductionPreviewQuestion =
updateIntroductionPreviewQuestionsSettings(questionnaire);

expect(
updateIntroductionPreviewQuestion.introduction.previewQuestions
).toBe(false);
expect(
updateIntroductionPreviewQuestion.introduction.disallowPreviewQuestions
).toBe(true);
});

it("should check if preview questions is true, confirm it changes to false as it passes through migration", () => {
const questionnaire = {
introduction: { previewQuestions: true },
collectionLists: {
id: "collection-list-1",
lists: [
{
id: "list-1",
listName: "List 1",
answers: [
{
id: "list-answer-1",
type: "TextField",
label: "List answer 1",
},
],
},
],
},
};
const updateIntroductionPreviewQuestion =
updateIntroductionPreviewQuestionsSettings(questionnaire);

expect(
updateIntroductionPreviewQuestion.introduction.previewQuestions
).toBe(false);
expect(
updateIntroductionPreviewQuestion.introduction.disallowPreviewQuestions
).toBe(true);
});
});

0 comments on commit 0960351

Please sign in to comment.