From 1058e0a196d18c76d365f21e9b67da8195ff0140 Mon Sep 17 00:00:00 2001 From: Peter Clement Date: Wed, 6 Nov 2024 16:58:37 +0000 Subject: [PATCH] Revert "Issue where looping wasn't working due to missing context" This reverts commit 67057b1b586f3ea66f28ff6f25753abae92f5842. --- .../tests/scenarios/looping.spec.ts | 87 ------------------- packages/server/src/threads/automation.ts | 4 +- 2 files changed, 1 insertion(+), 90 deletions(-) diff --git a/packages/server/src/automations/tests/scenarios/looping.spec.ts b/packages/server/src/automations/tests/scenarios/looping.spec.ts index 9c5313e9da..379927342a 100644 --- a/packages/server/src/automations/tests/scenarios/looping.spec.ts +++ b/packages/server/src/automations/tests/scenarios/looping.spec.ts @@ -355,93 +355,6 @@ describe("Loop automations", () => { expect(results.steps[2].outputs.rows).toHaveLength(expectedRows.length) }) - it("should run an automation with a loop and update row step using stepIds", async () => { - const table = await config.createTable({ - name: "TestTable", - type: "table", - schema: { - name: { - name: "name", - type: FieldType.STRING, - constraints: { - presence: true, - }, - }, - value: { - name: "value", - type: FieldType.NUMBER, - constraints: { - presence: true, - }, - }, - }, - }) - - const rows = [ - { name: "Row 1", value: 1, tableId: table._id }, - { name: "Row 2", value: 2, tableId: table._id }, - { name: "Row 3", value: 3, tableId: table._id }, - ] - - await config.api.row.bulkImport(table._id!, { rows }) - - const builder = createAutomationBuilder({ - name: "Test Loop and Update Row", - }) - - const results = await builder - .appAction({ fields: {} }) - .queryRows( - { - tableId: table._id!, - }, - { stepId: "abc123" } - ) - .loop({ - option: LoopStepType.ARRAY, - binding: "{{ steps.abc123.rows }}", - }) - .updateRow({ - rowId: "{{ loop.currentItem._id }}", - row: { - name: "Updated {{ loop.currentItem.name }}", - value: "{{ loop.currentItem.value }}", - tableId: table._id, - }, - meta: {}, - }) - .queryRows({ - tableId: table._id!, - }) - .run() - - const expectedRows = [ - { name: "Updated Row 1", value: 1 }, - { name: "Updated Row 2", value: 2 }, - { name: "Updated Row 3", value: 3 }, - ] - - expect(results.steps[1].outputs.items).toEqual( - expect.arrayContaining( - expectedRows.map(row => - expect.objectContaining({ - success: true, - row: expect.objectContaining(row), - }) - ) - ) - ) - - expect(results.steps[2].outputs.rows).toEqual( - expect.arrayContaining( - expectedRows.map(row => expect.objectContaining(row)) - ) - ) - - expect(results.steps[1].outputs.items).toHaveLength(expectedRows.length) - expect(results.steps[2].outputs.rows).toHaveLength(expectedRows.length) - }) - it("should run an automation with a loop and delete row step", async () => { const table = await config.createTable({ name: "TestTable", diff --git a/packages/server/src/threads/automation.ts b/packages/server/src/threads/automation.ts index 5894e7613e..b37ec8dc73 100644 --- a/packages/server/src/threads/automation.ts +++ b/packages/server/src/threads/automation.ts @@ -49,9 +49,7 @@ const CRON_STEP_ID = triggerDefs.CRON.stepId const STOPPED_STATUS = { success: true, status: AutomationStatus.STOPPED } function getLoopIterations(loopStep: LoopStep) { - console.log(loopStep) const binding = loopStep.inputs.binding - console.log(binding) if (!binding) { return 0 } @@ -387,7 +385,7 @@ class Orchestrator { stepIdx: number, pathIdx?: number ): Promise { - await processObject(loopStep.inputs, this.processContext(this.context)) + await processObject(loopStep.inputs, this.context) const iterations = getLoopIterations(loopStep) let stepToLoopIndex = stepIdx + 1 let pathStepIdx = (pathIdx || stepIdx) + 1