-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3027 from ONSdigital/Migration-Update-Introductio…
…n-PreviewingQuestions-Setting Add migration and tests
- Loading branch information
Showing
3 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
eq-author-api/migrations/updateIntroductionPreviewQuestionsSettings.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
}; |
92 changes: 92 additions & 0 deletions
92
eq-author-api/migrations/updateIntroductionPreviewQuestionsSettings.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |