Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Commit

Permalink
Merge pull request #72 from ONSdigital/adding-set-condition
Browse files Browse the repository at this point in the history
Added a set condition to all not equals
  • Loading branch information
SamGodwin2 committed Jul 11, 2018
2 parents 8c0f625 + 15ba3ce commit b15f054
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
17 changes: 11 additions & 6 deletions src/eq_schema/RoutingConditions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@ class RoutingConditions {

return flatMap(condition => {
const optionIds = map("id", condition.answer.options);
const notIds = xor(condition.routingValue.value, optionIds);
const unselectedIds = xor(condition.routingValue.value, optionIds);

return notIds.map(id => ({
id: `answer${condition.answer.id}`,
condition: "not equals",
value: optionById[id].label
}));
return unselectedIds
.map(id => ({
id: `answer${condition.answer.id}`,
condition: "not equals",
value: optionById[id].label
}))
.concat({
id: `answer${condition.answer.id}`,
condition: "set"
});
}, conditions);
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/eq_schema/RoutingRule.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ describe("Rule", () => {
block: "block2",
when: [
{ id: "answer2", condition: "not equals", value: "no" },
{ id: "answer2", condition: "not equals", value: "maybe" }
{ id: "answer2", condition: "not equals", value: "maybe" },
{ id: "answer2", condition: "set" }
]
}
},
Expand Down Expand Up @@ -160,7 +161,8 @@ describe("Rule", () => {
group: "summary-group",
when: [
{ id: "answer2", condition: "not equals", value: "no" },
{ id: "answer2", condition: "not equals", value: "maybe" }
{ id: "answer2", condition: "not equals", value: "maybe" },
{ id: "answer2", condition: "set" }
]
}
},
Expand Down Expand Up @@ -189,8 +191,10 @@ describe("Rule", () => {
when: [
{ id: "answer2", condition: "not equals", value: "no" },
{ id: "answer2", condition: "not equals", value: "maybe" },
{ id: "answer2", condition: "set" },
{ id: "answer3", condition: "not equals", value: "pepperoni" },
{ id: "answer3", condition: "not equals", value: "chorizo" }
{ id: "answer3", condition: "not equals", value: "chorizo" },
{ id: "answer3", condition: "set" }
]
}
},
Expand Down

0 comments on commit b15f054

Please sign in to comment.