From 6cf2359c62e1fa89a1c997e6029d52dd24f673c6 Mon Sep 17 00:00:00 2001 From: shelleytruong Date: Thu, 14 Apr 2022 12:29:48 +0100 Subject: [PATCH] fix radio and "and" routing errors --- src/eq_schema/builders/routing2/index.js | 2 +- src/eq_schema/builders/routing2/index.test.js | 54 ++++--------------- .../routing2/newRoutingDestination/index.js | 9 ++++ .../newRoutingDestination/index.test.js | 8 +-- src/eq_schema/schema/Group/index.test.js | 20 +++---- src/utils/routingConditionConversion/index.js | 2 +- .../routingConditionConversion/index.test.js | 2 +- 7 files changed, 34 insertions(+), 63 deletions(-) diff --git a/src/eq_schema/builders/routing2/index.js b/src/eq_schema/builders/routing2/index.js index 589ded02..f28ca2d8 100644 --- a/src/eq_schema/builders/routing2/index.js +++ b/src/eq_schema/builders/routing2/index.js @@ -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) ); diff --git a/src/eq_schema/builders/routing2/index.test.js b/src/eq_schema/builders/routing2/index.test.js index b5e7c9aa..c69b0068 100644 --- a/src/eq_schema/builders/routing2/index.test.js +++ b/src/eq_schema/builders/routing2/index.test.js @@ -30,16 +30,6 @@ describe("Routing2", () => { }, }, }, - ], - }, - destination: { - logical: "NextPage", - }, - }, - { - expressionGroup: { - operator: AND, - expressions: [ { left: { answerId: "2", @@ -54,7 +44,7 @@ describe("Routing2", () => { ], }, destination: { - logical: "EndOfCurrentSection", + logical: "NextPage", }, }, ], @@ -85,20 +75,13 @@ describe("Routing2", () => { 5, ], }, - ], - }, - }, - { - section: "End", - when: { - and: [ { - "any-in": [ - ["red", "white"], + "in": [ { identifier: "answer2", source: "answers", }, + ["red", "white"], ], }, ], @@ -128,16 +111,6 @@ describe("Routing2", () => { optionIds: ["123", "456"], }, }, - ], - }, - destination: { - logical: "NextPage", - }, - }, - { - expressionGroup: { - operator: OR, - expressions: [ { left: { answerId: "2", @@ -152,7 +125,7 @@ describe("Routing2", () => { ], }, destination: { - logical: "EndOfCurrentSection", + logical: "NextPage", }, }, ], @@ -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"], ], }, ], @@ -694,12 +660,12 @@ describe("Testing Skip Condition Logic", () => { when: { or: [ { - "any-in": [ - ["red"], + "in": [ { identifier: "answer27b51b6f-3ada-4b8c-88db-33e21e13172f", source: "answers", }, + ["red"], ], }, { diff --git a/src/eq_schema/builders/routing2/newRoutingDestination/index.js b/src/eq_schema/builders/routing2/newRoutingDestination/index.js index 852c55a3..b29c954e 100644 --- a/src/eq_schema/builders/routing2/newRoutingDestination/index.js +++ b/src/eq_schema/builders/routing2/newRoutingDestination/index.js @@ -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, }; diff --git a/src/eq_schema/builders/routing2/newRoutingDestination/index.test.js b/src/eq_schema/builders/routing2/newRoutingDestination/index.test.js index 373a47d7..767a8f67 100644 --- a/src/eq_schema/builders/routing2/newRoutingDestination/index.test.js +++ b/src/eq_schema/builders/routing2/newRoutingDestination/index.test.js @@ -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"], ], }); }); @@ -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"], ], }); }); diff --git a/src/eq_schema/schema/Group/index.test.js b/src/eq_schema/schema/Group/index.test.js index 002046f0..8d6577f9 100644 --- a/src/eq_schema/schema/Group/index.test.js +++ b/src/eq_schema/schema/Group/index.test.js @@ -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", }, diff --git a/src/utils/routingConditionConversion/index.js b/src/utils/routingConditionConversion/index.js index 261159e2..bcc1003d 100644 --- a/src/utils/routingConditionConversion/index.js +++ b/src/utils/routingConditionConversion/index.js @@ -9,7 +9,7 @@ const routingConditionConversions = { AnyOf: "any-in", NotAnyOf: "not", Unanswered: "==", - OneOf: "any-in", + OneOf: "in", }; const routingConditionConversion = (conditionString) => { diff --git a/src/utils/routingConditionConversion/index.test.js b/src/utils/routingConditionConversion/index.test.js index 5f9b7890..9b06971c 100644 --- a/src/utils/routingConditionConversion/index.test.js +++ b/src/utils/routingConditionConversion/index.test.js @@ -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(