Skip to content

Commit

Permalink
fix: lists passed to GOVnotify work with no list items shown (#1080)
Browse files Browse the repository at this point in the history
* List created for GOVnotify is now appended to an empty string to avoid undefined being passed through to personalisation

* Changed list parsing in notifyModel to wrap the array map in a template instead of appending to an empty string
  • Loading branch information
ziggy-cyb committed Jun 21, 2023
1 parent c5497c9 commit 1c77dea
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ const parseListAsNotifyTemplate = (
model: FormModel,
state: FormSubmissionState
) => {
return list.items
return `${list.items
.filter((item) => checkItemIsValid(model, state, item.condition))
.map((item) => `* ${item.value}\n`)
.join("");
.join("")}`;
};

const checkItemIsValid = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
"type": "string",
"items": [
{ "text": "Item 1", "value": "Item 1", "condition": "KAOicj" },
{ "text": "Item 2", "value": "Item 2", "condition": "vzzqjG" },
{ "text": "Item 3", "value": "Item 3" }
{ "text": "Item 2", "value": "Item 2", "condition": "vzzqjG" }
]
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ suite("NotifyModel", () => {
TZOHRn: "test@test.com",
};
const model = testFormSubmission(state);
expect(model.personalisation["wVUZJW"]).to.equal(
`* Item 1\n* Item 2\n* Item 3\n`
);
expect(model.personalisation["wVUZJW"]).to.equal(`* Item 1\n* Item 2\n`);
});
test("returns correct personalisation when a list is passed in and the second condition is satisfied", () => {
const state: FormSubmissionState = {
Expand All @@ -42,9 +40,9 @@ suite("NotifyModel", () => {

const model = testFormSubmission(state);

expect(model.personalisation["wVUZJW"]).to.equal(`* Item 1\n* Item 3\n`);
expect(model.personalisation["wVUZJW"]).to.equal(`* Item 1\n`);
});
test("returns correct personalisation when a list is passed in and no conditions are satisfied", () => {
test("returns an empty string when a list is passed in and no conditions are satisfied", () => {
const state: FormSubmissionState = {
SWJtVi: false,
dxWjPr: false,
Expand All @@ -53,6 +51,6 @@ suite("NotifyModel", () => {

const model = testFormSubmission(state);

expect(model.personalisation["wVUZJW"]).to.equal(`* Item 3\n`);
expect(model.personalisation["wVUZJW"]).to.equal("");
});
});

0 comments on commit 1c77dea

Please sign in to comment.