-
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 #308 from ONSdigital/1026-metadata-example-values-…
…missing-after-data-migration Added migration to bring new metadata values into new resolver format
- Loading branch information
Showing
9 changed files
with
154 additions
and
45 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
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 @@ | ||
//This is an auto-generated file. Do NOT modify the method signature. | ||
const { defaultTypeValueNames } = require("../utils/defaultMetadata"); | ||
|
||
module.exports = function updateMetadataValue(questionnaire) { | ||
questionnaire.metadata.map(metadata => { | ||
if (!metadata.value) { | ||
return; | ||
} | ||
metadata[defaultTypeValueNames[metadata.type]] = metadata.value; | ||
delete metadata.value; | ||
}); | ||
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,86 @@ | ||
const updateMetadataValue = require("./updateMetadataValue.js"); | ||
|
||
describe("updateMetadataValue", () => { | ||
it("should update metadata to correct new format", () => { | ||
const metadata = [ | ||
{ | ||
alias: "text", | ||
dateValue: null, | ||
id: "296", | ||
key: "ru_ref", | ||
languageValue: null, | ||
regionValue: null, | ||
textValue: "old Value", | ||
type: "Text", | ||
value: "new Value", | ||
}, | ||
{ | ||
alias: "date", | ||
dateValue: "2019-07-01", | ||
id: "294", | ||
key: "date", | ||
languageValue: null, | ||
regionValue: null, | ||
textValue: null, | ||
type: "Date", | ||
value: "2019-04-09", | ||
}, | ||
{ | ||
alias: "region", | ||
dateValue: null, | ||
id: "297", | ||
key: "region", | ||
languageValue: null, | ||
regionValue: "GB_GBN", | ||
textValue: null, | ||
type: "Region", | ||
value: "GB_ENG", | ||
}, | ||
{ | ||
alias: "language", | ||
dateValue: null, | ||
id: "297", | ||
key: "language", | ||
languageValue: "cy", | ||
regionValue: null, | ||
textValue: null, | ||
type: "Language", | ||
value: "en", | ||
}, | ||
{ | ||
alias: "language", | ||
dateValue: null, | ||
id: "297", | ||
key: "language", | ||
languageValue: "cy", | ||
regionValue: null, | ||
textValue: null, | ||
type: "Language", | ||
}, | ||
]; | ||
const updatedQuestionnaire = updateMetadataValue({ metadata }); | ||
updatedQuestionnaire.metadata.forEach(metadata => { | ||
expect(metadata).not.toHaveProperty("value"); | ||
}); | ||
expect(updatedQuestionnaire.metadata[0].textValue).toEqual("new Value"); | ||
expect(updatedQuestionnaire.metadata[1].dateValue).toEqual("2019-04-09"); | ||
expect(updatedQuestionnaire.metadata[2].regionValue).toEqual("GB_ENG"); | ||
expect(updatedQuestionnaire.metadata[3].languageValue).toEqual("en"); | ||
}); | ||
it("should not update if metadata is already in correct format", () => { | ||
const metadata = [ | ||
{ | ||
alias: "language", | ||
dateValue: null, | ||
id: "297", | ||
key: "language", | ||
languageValue: "cy", | ||
regionValue: null, | ||
textValue: null, | ||
type: "Language", | ||
}, | ||
]; | ||
const updatedQuestionnaire = updateMetadataValue({ metadata }); | ||
expect(updatedQuestionnaire.metadata[0]).toMatchObject(metadata[0]); | ||
}); | ||
}); |
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