From acdcd02fcdf85427d5c42aa4bc5dd5219f979c24 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Fri, 27 Sep 2024 09:12:50 +0100 Subject: [PATCH 1/3] Fix small issue with conditions in branches --- .../tests/scenarios/branching.spec.ts | 34 +++++++++---------- packages/server/src/threads/automation.ts | 6 ++-- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/packages/server/src/automations/tests/scenarios/branching.spec.ts b/packages/server/src/automations/tests/scenarios/branching.spec.ts index df513e98c6..ae89fc18b5 100644 --- a/packages/server/src/automations/tests/scenarios/branching.spec.ts +++ b/packages/server/src/automations/tests/scenarios/branching.spec.ts @@ -32,25 +32,25 @@ describe("Branching automations", () => { steps: stepBuilder => stepBuilder.serverLog({ text: "Branch 1.1" }), condition: { - equal: { "steps.1.success": true }, + equal: { "{{steps.1.success}}": true }, }, }, branch2: { steps: stepBuilder => stepBuilder.serverLog({ text: "Branch 1.2" }), condition: { - equal: { "steps.1.success": false }, + equal: { "{{steps.1.success}}": false }, }, }, }), condition: { - equal: { "steps.1.success": true }, + equal: { "{{steps.1.success}}": true }, }, }, topLevelBranch2: { steps: stepBuilder => stepBuilder.serverLog({ text: "Branch 2" }), condition: { - equal: { "steps.1.success": false }, + equal: { "{{steps.1.success}}": false }, }, }, }) @@ -70,14 +70,14 @@ describe("Branching automations", () => { activeBranch: { steps: stepBuilder => stepBuilder.serverLog({ text: "Active user" }), condition: { - equal: { "trigger.fields.status": "active" }, + equal: { "{{trigger.fields.status}}": "active" }, }, }, inactiveBranch: { steps: stepBuilder => stepBuilder.serverLog({ text: "Inactive user" }), condition: { - equal: { "trigger.fields.status": "inactive" }, + equal: { "{{trigger.fields.status}}": "inactive" }, }, }, }) @@ -102,8 +102,8 @@ describe("Branching automations", () => { condition: { $and: { conditions: [ - { equal: { "trigger.fields.status": "active" } }, - { equal: { "trigger.fields.role": "admin" } }, + { equal: { "{{trigger.fields.status}}": "active" } }, + { equal: { "{{trigger.fields.role}}": "admin" } }, ], }, }, @@ -111,7 +111,7 @@ describe("Branching automations", () => { otherBranch: { steps: stepBuilder => stepBuilder.serverLog({ text: "Other user" }), condition: { - notEqual: { "trigger.fields.status": "active" }, + notEqual: { "{{trigger.fields.status}}": "active" }, }, }, }) @@ -133,8 +133,8 @@ describe("Branching automations", () => { condition: { $or: { conditions: [ - { equal: { "trigger.fields.status": "test" } }, - { equal: { "trigger.fields.role": "admin" } }, + { equal: { "{{trigger.fields.status}}": "test" } }, + { equal: { "{{trigger.fields.role}}": "admin" } }, ], }, }, @@ -144,8 +144,8 @@ describe("Branching automations", () => { condition: { $and: { conditions: [ - { notEqual: { "trigger.fields.status": "active" } }, - { notEqual: { "trigger.fields.role": "admin" } }, + { notEqual: { "{{trigger.fields.status}}": "active" } }, + { notEqual: { "{{trigger.fields.role}}": "admin" } }, ], }, }, @@ -170,8 +170,8 @@ describe("Branching automations", () => { condition: { $or: { conditions: [ - { equal: { "trigger.fields.status": "new" } }, - { equal: { "trigger.fields.role": "admin" } }, + { equal: { "{{trigger.fields.status}}": "new" } }, + { equal: { "{{trigger.fields.role}}": "admin" } }, ], }, }, @@ -181,8 +181,8 @@ describe("Branching automations", () => { condition: { $and: { conditions: [ - { equal: { "trigger.fields.status": "active" } }, - { equal: { "trigger.fields.role": "admin" } }, + { equal: { "{{trigger.fields.status}}": "active" } }, + { equal: { "{{trigger.fields.role}}": "admin" } }, ], }, }, diff --git a/packages/server/src/threads/automation.ts b/packages/server/src/threads/automation.ts index a59935c6aa..e2a5a1c192 100644 --- a/packages/server/src/threads/automation.ts +++ b/packages/server/src/threads/automation.ts @@ -516,10 +516,8 @@ class Orchestrator { filter => { Object.entries(filter).forEach(([_, value]) => { Object.entries(value).forEach(([field, _]) => { - const fromContext = processStringSync( - `{{ literal ${field} }}`, - this.context - ) + const updatedField = field.replace("{{", "{{ literal ") + const fromContext = processStringSync(updatedField, this.context) toFilter[field] = fromContext }) }) From f03ed037945075b3c3a4858de3554852dc8087ba Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Fri, 27 Sep 2024 10:05:05 +0100 Subject: [PATCH 2/3] remove space Co-authored-by: Sam Rose --- packages/server/src/threads/automation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/threads/automation.ts b/packages/server/src/threads/automation.ts index e2a5a1c192..120a323f20 100644 --- a/packages/server/src/threads/automation.ts +++ b/packages/server/src/threads/automation.ts @@ -516,7 +516,7 @@ class Orchestrator { filter => { Object.entries(filter).forEach(([_, value]) => { Object.entries(value).forEach(([field, _]) => { - const updatedField = field.replace("{{", "{{ literal ") + const updatedField = field.replace("{{", "{{ literal") const fromContext = processStringSync(updatedField, this.context) toFilter[field] = fromContext }) From 5ef0e48ee0b35423c93402265f452f2b22a3d4f0 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Fri, 27 Sep 2024 10:21:52 +0100 Subject: [PATCH 3/3] add back space --- packages/server/src/threads/automation.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/threads/automation.ts b/packages/server/src/threads/automation.ts index 120a323f20..e2a5a1c192 100644 --- a/packages/server/src/threads/automation.ts +++ b/packages/server/src/threads/automation.ts @@ -516,7 +516,7 @@ class Orchestrator { filter => { Object.entries(filter).forEach(([_, value]) => { Object.entries(value).forEach(([field, _]) => { - const updatedField = field.replace("{{", "{{ literal") + const updatedField = field.replace("{{", "{{ literal ") const fromContext = processStringSync(updatedField, this.context) toFilter[field] = fromContext })