-
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 #3099 from ONSdigital/EAR-2305-data-version-selection
EAR 2305 data version selection
- Loading branch information
Showing
21 changed files
with
449 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = ["1", "3"]; |
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,18 @@ | ||
const { getOptions } = require("../schema/resolvers/utils"); | ||
|
||
module.exports = (questionnaire) => { | ||
const allQuestionnaireOptions = getOptions({ questionnaire }); | ||
|
||
if ( | ||
questionnaire.collectionLists?.lists?.length > 0 || | ||
questionnaire.supplementaryData || | ||
allQuestionnaireOptions?.some((option) => option.dynamicAnswer) | ||
) { | ||
questionnaire.dataVersion = "3"; | ||
questionnaire.allowableDataVersions = ["3"]; | ||
} else { | ||
questionnaire.allowableDataVersions = ["1", "3"]; | ||
} | ||
|
||
return questionnaire; | ||
}; |
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,82 @@ | ||
const addAllowableDataVersions = require("./addAllowableDataVersions"); | ||
|
||
describe("addAllowableDataVersions", () => { | ||
it("should set dataVersion to 3 and add allowableDataVersions with data version 3 when questionnaire has collection list", () => { | ||
const questionnaire = { | ||
id: "questionnaire-1", | ||
title: "Questionnaire 1", | ||
collectionLists: { | ||
lists: [{ id: "list-1" }], | ||
}, | ||
}; | ||
|
||
const updatedQuestionnaire = addAllowableDataVersions(questionnaire); | ||
|
||
expect(updatedQuestionnaire.dataVersion).toEqual("3"); | ||
expect(updatedQuestionnaire.allowableDataVersions).toEqual(["3"]); | ||
}); | ||
|
||
it("should set dataVersion to 3 and add allowableDataVersions with data version 3 when questionnaire has supplementary data", () => { | ||
const questionnaire = { | ||
id: "questionnaire-1", | ||
title: "Questionnaire 1", | ||
supplementaryData: { id: "supplementary-data-1" }, | ||
}; | ||
|
||
const updatedQuestionnaire = addAllowableDataVersions(questionnaire); | ||
|
||
expect(updatedQuestionnaire.dataVersion).toEqual("3"); | ||
expect(updatedQuestionnaire.allowableDataVersions).toEqual(["3"]); | ||
}); | ||
|
||
it("should set dataVersion to 3 and add allowableDataVersions with data version 3 when questionnaire has dynamic answer", () => { | ||
const questionnaire = { | ||
id: "questionnaire-1", | ||
title: "Questionnaire 1", | ||
sections: [ | ||
{ | ||
id: "section-1", | ||
folders: [ | ||
{ | ||
id: "folder-1", | ||
pages: [ | ||
{ | ||
id: "page-1", | ||
answers: [ | ||
{ | ||
id: "answer-1", | ||
options: [ | ||
{ | ||
id: "option-1", | ||
dynamicAnswer: true, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
], | ||
}; | ||
|
||
const updatedQuestionnaire = addAllowableDataVersions(questionnaire); | ||
|
||
expect(updatedQuestionnaire.dataVersion).toEqual("3"); | ||
expect(updatedQuestionnaire.allowableDataVersions).toEqual(["3"]); | ||
}); | ||
|
||
it("should add allowableDataVersions with data versions 1 and 3 without updating dataVersion when questionnaire has no collection lists, supplementary data or dynamic answers", () => { | ||
const questionnaire = { | ||
id: "questionnaire-1", | ||
title: "Questionnaire 1", | ||
dataVersion: "1", | ||
}; | ||
|
||
const updatedQuestionnaire = addAllowableDataVersions(questionnaire); | ||
|
||
expect(updatedQuestionnaire.dataVersion).toEqual("1"); | ||
expect(updatedQuestionnaire.allowableDataVersions).toEqual(["1", "3"]); | ||
}); | ||
}); |
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
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
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
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
Oops, something went wrong.