-
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 #3137 from ONSdigital/migration-remove-confirmatio…
…n-qcodes Migration to remove confirmation qcodes
- Loading branch information
Showing
3 changed files
with
151 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
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,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
137
eq-author-api/migrations/removeConfirmationPageQCodes.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,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); | ||
}); | ||
}); |