Skip to content

Commit

Permalink
Merge pull request #92 from ONSdigital/EAR-1739-fixes
Browse files Browse the repository at this point in the history
EAR-1739 fix radio and "and" routing errors
  • Loading branch information
shelleytruong authored Apr 19, 2022
2 parents 0c28a96 + 6cf2359 commit 7af66fe
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 63 deletions.
2 changes: 1 addition & 1 deletion src/eq_schema/builders/routing2/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const buildRunnerRules = (rules, pageId, ctx, groupId) => {

const { expressions, operator } = rule.expressionGroup;

if (operator === AND || operator === OR) {
if ((operator === AND || operator === OR) && (expressions.length > 1)) {
const when = expressions.map((expression) =>
checkValidRoutingType(expression, ctx)
);
Expand Down
54 changes: 10 additions & 44 deletions src/eq_schema/builders/routing2/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ describe("Routing2", () => {
},
},
},
],
},
destination: {
logical: "NextPage",
},
},
{
expressionGroup: {
operator: AND,
expressions: [
{
left: {
answerId: "2",
Expand All @@ -54,7 +44,7 @@ describe("Routing2", () => {
],
},
destination: {
logical: "EndOfCurrentSection",
logical: "NextPage",
},
},
],
Expand Down Expand Up @@ -85,20 +75,13 @@ describe("Routing2", () => {
5,
],
},
],
},
},
{
section: "End",
when: {
and: [
{
"any-in": [
["red", "white"],
"in": [
{
identifier: "answer2",
source: "answers",
},
["red", "white"],
],
},
],
Expand Down Expand Up @@ -128,16 +111,6 @@ describe("Routing2", () => {
optionIds: ["123", "456"],
},
},
],
},
destination: {
logical: "NextPage",
},
},
{
expressionGroup: {
operator: OR,
expressions: [
{
left: {
answerId: "2",
Expand All @@ -152,7 +125,7 @@ describe("Routing2", () => {
],
},
destination: {
logical: "EndOfCurrentSection",
logical: "NextPage",
},
},
],
Expand All @@ -173,28 +146,21 @@ describe("Routing2", () => {
when: {
or: [
{
"any-in": [
["red", "white"],
"in": [
{
identifier: "answer1",
source: "answers",
},
["red", "white"],
],
},
],
},
},
{
section: "End",
when: {
or: [
{
"any-in": [
["red", "white"],
"in": [
{
identifier: "answer2",
source: "answers",
},
["red", "white"],
],
},
],
Expand Down Expand Up @@ -694,12 +660,12 @@ describe("Testing Skip Condition Logic", () => {
when: {
or: [
{
"any-in": [
["red"],
"in": [
{
identifier: "answer27b51b6f-3ada-4b8c-88db-33e21e13172f",
source: "answers",
},
["red"],
],
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ const buildAnswerObject = (
return SelectedOptions;
}

if (condition === "OneOf") {
const swapOptionValues = [optionValues[0], optionValues[1]] = [optionValues[1], optionValues[0]];
const SelectedOptions = {
[routingConditionConversion(condition)]: swapOptionValues,
};

return SelectedOptions;
}

const SelectedOptions = {
[routingConditionConversion(condition)]: optionValues,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ describe("Should build a runner representation of a binary expression", () => {
});

expect(runnerExpression).toMatchObject({
"any-in": [
["red"],
"in": [
{
identifier: "answer1",
source: "answers",
},
["red"],
],
});
});
Expand Down Expand Up @@ -73,12 +73,12 @@ describe("Should build a runner representation of a binary expression", () => {
questionnaireJson,
});
expect(runnerExpression).toMatchObject({
"any-in": [
["red", "white"],
"in": [
{
identifier: "answer1",
source: "answers",
},
["red", "white"],
],
});
});
Expand Down
20 changes: 8 additions & 12 deletions src/eq_schema/schema/Group/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -405,19 +405,15 @@ describe("Group", () => {
{
group: "groupuu1d-iuhiuwfew-fewfewfewdsf-dsf-4",
when: {
and: [
{
"==": [
{
identifier: "answer1",
source: "answers",
},
"5",
],
},
],
"==": [
{
identifier: "answer1",
source: "answers",
},
"5",
],
},
},
},
{
section: "End",
},
Expand Down
2 changes: 1 addition & 1 deletion src/utils/routingConditionConversion/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const routingConditionConversions = {
AnyOf: "any-in",
NotAnyOf: "not",
Unanswered: "==",
OneOf: "any-in",
OneOf: "in",
};

const routingConditionConversion = (conditionString) => {
Expand Down
2 changes: 1 addition & 1 deletion src/utils/routingConditionConversion/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe("Convert routing conditions", () => {
AnyOf: "any-in",
NotAnyOf: "not",
Unanswered: "==",
OneOf: "any-in",
OneOf: "in",
};
Object.keys(conditionMap).forEach((authorCondition) =>
expect(routingConditionConversion(authorCondition)).toEqual(
Expand Down

0 comments on commit 7af66fe

Please sign in to comment.