-
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 #314 from ONSdigital/149-survey-introduction
Survey Introduction
- Loading branch information
Showing
134 changed files
with
4,823 additions
and
667 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,3 @@ | ||
module.exports.NOTICE_1 = "NOTICE_1"; | ||
module.exports.NOTICE_2 = "NOTICE_2"; | ||
module.exports.VOLUNTARY = "VOLUNTARY"; |
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
32 changes: 32 additions & 0 deletions
32
eq-author-api/migrations/addBusinessQuestionnaireIntroduction.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,32 @@ | ||
//This is an auto-generated file. Do NOT modify the method signature. | ||
|
||
const { find } = require("lodash"); | ||
const { BUSINESS } = require("../constants/questionnaireTypes"); | ||
const { | ||
createDefaultBusinessSurveyMetadata, | ||
} = require("../utils/defaultMetadata"); | ||
const { | ||
createQuestionnaireIntroduction, | ||
} = require("../schema/resolvers/questionnaireIntroduction"); | ||
|
||
module.exports = function addBusinessQuestionnaireIntroduction(questionnaire) { | ||
if (questionnaire.type !== BUSINESS) { | ||
return questionnaire; | ||
} | ||
|
||
const defaultMetadata = createDefaultBusinessSurveyMetadata(); | ||
const metadataToAdd = defaultMetadata | ||
.filter(({ key }) => !find(questionnaire.metadata, { key })) | ||
.map((md, index) => ({ | ||
...md, | ||
id: `migrated-md-${index}`, | ||
})); | ||
questionnaire.metadata = [...questionnaire.metadata, ...metadataToAdd]; | ||
|
||
questionnaire.introduction = createQuestionnaireIntroduction( | ||
questionnaire.metadata | ||
); | ||
questionnaire.introduction.id = "questionnaire-introduction"; | ||
|
||
return questionnaire; | ||
}; |
57 changes: 57 additions & 0 deletions
57
eq-author-api/migrations/addBusinessQuestionnaireIntroduction.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,57 @@ | ||
const { cloneDeep } = require("lodash"); | ||
|
||
const { SOCIAL, BUSINESS } = require("../constants/questionnaireTypes"); | ||
|
||
const addBusinessQuestionnaireIntroduction = require("./addBusinessQuestionnaireIntroduction.js"); | ||
|
||
describe("addBusinessQuestionnaireIntroduction", () => { | ||
it("should be deterministic", () => { | ||
const questionnaire = { | ||
type: BUSINESS, | ||
metadata: [], | ||
}; | ||
|
||
expect( | ||
addBusinessQuestionnaireIntroduction(cloneDeep(questionnaire)) | ||
).toMatchObject( | ||
addBusinessQuestionnaireIntroduction(cloneDeep(questionnaire)) | ||
); | ||
}); | ||
|
||
it("should not touch social", () => { | ||
const questionnaire = { | ||
type: SOCIAL, | ||
}; | ||
|
||
expect(addBusinessQuestionnaireIntroduction(questionnaire)).toEqual( | ||
questionnaire | ||
); | ||
}); | ||
|
||
it("should add missing default metadata", () => { | ||
const questionnaire = { | ||
type: BUSINESS, | ||
metadata: [ | ||
{ | ||
key: "ru_name", | ||
alias: "Ru Name", | ||
type: "Text", | ||
value: "ESSENTIAL ENTERPRISE LTD.", | ||
}, | ||
], | ||
}; | ||
|
||
expect( | ||
addBusinessQuestionnaireIntroduction(questionnaire).metadata.map( | ||
md => md.key | ||
) | ||
).toEqual([ | ||
"ru_name", | ||
"trad_as", | ||
"period_id", | ||
"ref_p_start_date", | ||
"ref_p_end_date", | ||
"employmentDate", | ||
]); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
const base = require("./base"); | ||
const routing2 = require("./routing2"); | ||
const page = require("./pages"); | ||
const questionnaireIntroduction = require("./questionnaireIntroduction"); | ||
|
||
module.exports = [base, ...routing2, ...page]; | ||
module.exports = [base, ...routing2, ...page, ...questionnaireIntroduction]; |
83 changes: 83 additions & 0 deletions
83
eq-author-api/schema/resolvers/questionnaireIntroduction.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,83 @@ | ||
const { find, omit, first, remove } = require("lodash"); | ||
const uuid = require("uuid").v4; | ||
|
||
const { saveQuestionnaire } = require("../../utils/datastore"); | ||
const { NOTICE_1 } = require("../../constants/legalBases"); | ||
|
||
const createCollapsible = options => ({ | ||
id: uuid(), | ||
title: "", | ||
description: "", | ||
...options, | ||
}); | ||
|
||
const Resolvers = {}; | ||
Resolvers.Query = { | ||
questionnaireIntroduction: (root, args, ctx) => | ||
ctx.questionnaire.introduction, | ||
}; | ||
Resolvers.Mutation = { | ||
updateQuestionnaireIntroduction: async (_, { input }, ctx) => { | ||
const introduction = ctx.questionnaire.introduction; | ||
Object.assign(introduction, omit(input, "id")); | ||
await saveQuestionnaire(ctx.questionnaire); | ||
return introduction; | ||
}, | ||
createCollapsible: async (_, { input }, ctx) => { | ||
const collapsible = createCollapsible(omit(input, "introductionId")); | ||
ctx.questionnaire.introduction.collapsibles.push(collapsible); | ||
await saveQuestionnaire(ctx.questionnaire); | ||
return collapsible; | ||
}, | ||
updateCollapsible: async (_, { input: { id, ...rest } }, ctx) => { | ||
const collapsible = ctx.questionnaire.introduction.collapsibles.find( | ||
c => c.id === id | ||
); | ||
Object.assign(collapsible, rest); | ||
await saveQuestionnaire(ctx.questionnaire); | ||
return collapsible; | ||
}, | ||
moveCollapsible: async (_, { input: { id, position } }, ctx) => { | ||
const introduction = ctx.questionnaire.introduction; | ||
const collapsibleMoving = first(remove(introduction.collapsibles, { id })); | ||
introduction.collapsibles.splice(position, 0, collapsibleMoving); | ||
await saveQuestionnaire(ctx.questionnaire); | ||
return collapsibleMoving; | ||
}, | ||
deleteCollapsible: async (_, { input: { id } }, ctx) => { | ||
const introduction = ctx.questionnaire.introduction; | ||
remove(introduction.collapsibles, { id }); | ||
await saveQuestionnaire(ctx.questionnaire); | ||
return introduction; | ||
}, | ||
}; | ||
Resolvers.QuestionnaireIntroduction = { | ||
availablePipingMetadata: (root, args, ctx) => ctx.questionnaire.metadata, | ||
availablePipingAnswers: () => [], | ||
}; | ||
|
||
Resolvers.Collapsible = { | ||
introduction: (root, args, ctx) => ctx.questionnaire.introduction, | ||
}; | ||
|
||
module.exports = [Resolvers]; | ||
module.exports.createQuestionnaireIntroduction = metadata => { | ||
return { | ||
id: uuid.v4(), | ||
title: `<p>You are completing this for <span data-piped="metadata" data-id="${ | ||
find(metadata, { key: "trad_as" }).id | ||
}">trad_as</span> (<span data-piped="metadata" data-id="${ | ||
find(metadata, { key: "ru_name" }).id | ||
}">ru_name</span>)</p>`, | ||
description: | ||
"<ul><li>Data should relate to all sites in England, Scotland, Wales and Northern Ireland unless otherwise stated. </li><li>You can provide info estimates if actual figures aren’t available.</li><li>We will treat your data securely and confidentially.</li></ul>", | ||
legalBasis: NOTICE_1, | ||
secondaryTitle: "<p>Information you need</p>", | ||
secondaryDescription: | ||
"<p>You can select the dates of the period you are reporting for, if the given dates are not appropriate.</p>", | ||
collapsibles: [], | ||
tertiaryTitle: "<p>How we use your data</p>", | ||
tertiaryDescription: | ||
"<ul><li>You cannot appeal your selection. Your business was selected to give us a comprehensive view of the UK economy.</li><li>The information you provide contributes to Gross Domestic Product (GDP).</li></ul>", | ||
}; | ||
}; |
Oops, something went wrong.