From 924f4009921572753f17c31660584abd7fadc0f3 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Thu, 6 Feb 2025 15:58:15 +0000 Subject: [PATCH] Rename run to test to better reflect the API being hit. --- .../src/api/routes/tests/automation.spec.ts | 2 +- .../src/automations/tests/branching.spec.ts | 14 ++-- .../src/automations/tests/scenarios.spec.ts | 22 +++---- .../src/automations/tests/steps/bash.spec.ts | 6 +- .../automations/tests/steps/createRow.spec.ts | 12 ++-- .../tests/steps/executeScript.spec.ts | 10 +-- .../src/automations/tests/steps/loop.spec.ts | 6 +- .../automations/tests/steps/openai.spec.ts | 8 +-- .../automations/tests/steps/queryRows.spec.ts | 12 ++-- .../tests/utilities/AutomationTestBuilder.ts | 64 +++++++++---------- 10 files changed, 78 insertions(+), 78 deletions(-) diff --git a/packages/server/src/api/routes/tests/automation.spec.ts b/packages/server/src/api/routes/tests/automation.spec.ts index a27c21ded4..1d7b9cd6ed 100644 --- a/packages/server/src/api/routes/tests/automation.spec.ts +++ b/packages/server/src/api/routes/tests/automation.spec.ts @@ -251,7 +251,7 @@ describe("/automations", () => { .serverLog({ text: "{{ settings.company }}", }) - .run({ fields: {} }) + .test({ fields: {} }) expect(result.steps[0].outputs.message).toEndWith("https://example.com") expect(result.steps[1].outputs.message).toEndWith( diff --git a/packages/server/src/automations/tests/branching.spec.ts b/packages/server/src/automations/tests/branching.spec.ts index feac5f80f5..bf9b9ce3f8 100644 --- a/packages/server/src/automations/tests/branching.spec.ts +++ b/packages/server/src/automations/tests/branching.spec.ts @@ -76,7 +76,7 @@ describe("Branching automations", () => { }, }, }) - .run({ fields: {} }) + .test({ fields: {} }) expect(results.steps[3].outputs.status).toContain("branch1 branch taken") expect(results.steps[4].outputs.message).toContain("Branch 1.1") @@ -100,7 +100,7 @@ describe("Branching automations", () => { }, }, }) - .run({ fields: { status: "active" } }) + .test({ fields: { status: "active" } }) expect(results.steps[0].outputs.status).toContain( "activeBranch branch taken" ) @@ -130,7 +130,7 @@ describe("Branching automations", () => { }, }, }) - .run({ fields: { status: "active", role: "admin" } }) + .test({ fields: { status: "active", role: "admin" } }) expect(results.steps[1].outputs.message).toContain("Active admin user") }) @@ -162,7 +162,7 @@ describe("Branching automations", () => { }, }, }) - .run({ fields: { status: "test", role: "user" } }) + .test({ fields: { status: "test", role: "user" } }) expect(results.steps[1].outputs.message).toContain("Special user") }) @@ -195,7 +195,7 @@ describe("Branching automations", () => { }, }, }) - .run({ fields: { status: "test", role: "user" } }) + .test({ fields: { status: "test", role: "user" } }) expect(results.steps[1].outputs.status).toEqual( AutomationStatus.NO_CONDITION_MET @@ -239,7 +239,7 @@ describe("Branching automations", () => { }, }, }) - .run({ fields: { test_trigger: true } }) + .test({ fields: { test_trigger: true } }) expect(results.steps[2].outputs.message).toContain("Special user") }) @@ -276,7 +276,7 @@ describe("Branching automations", () => { }, }, }) - .run({ fields: { test_trigger: true } }) + .test({ fields: { test_trigger: true } }) expect(results.steps[2].outputs.message).toContain("Special user") }) diff --git a/packages/server/src/automations/tests/scenarios.spec.ts b/packages/server/src/automations/tests/scenarios.spec.ts index e37aea838e..3015e75018 100644 --- a/packages/server/src/automations/tests/scenarios.spec.ts +++ b/packages/server/src/automations/tests/scenarios.spec.ts @@ -38,7 +38,7 @@ describe("Automation Scenarios", () => { tableId: table._id, }, }) - .run({ + .test({ row: { name: "Test", description: "TEST" }, id: "1234", }) @@ -67,7 +67,7 @@ describe("Automation Scenarios", () => { .queryRows({ tableId: table._id!, }) - .run({ fields: {} }) + .test({ fields: {} }) expect(results.steps).toHaveLength(1) expect(results.steps[0].outputs.rows).toHaveLength(2) @@ -93,7 +93,7 @@ describe("Automation Scenarios", () => { .queryRows({ tableId: table._id!, }) - .run({ fields: {} }) + .test({ fields: {} }) expect(results.steps).toHaveLength(3) expect(results.steps[1].outputs.success).toBeTruthy() @@ -153,7 +153,7 @@ describe("Automation Scenarios", () => { }, { stepName: "QueryRowsStep" } ) - .run({ fields: {} }) + .test({ fields: {} }) expect(results.steps).toHaveLength(3) @@ -207,7 +207,7 @@ describe("Automation Scenarios", () => { .queryRows({ tableId: table._id!, }) - .run({ fields: {} }) + .test({ fields: {} }) expect(results.steps).toHaveLength(3) expect(results.steps[1].outputs.success).toBeTruthy() @@ -260,7 +260,7 @@ describe("Automation Scenarios", () => { value: 20, }) .serverLog({ text: "Equal condition met" }) - .run({ fields: {} }) + .test({ fields: {} }) expect(results.steps[2].outputs.success).toBeTrue() expect(results.steps[2].outputs.result).toBeFalse() @@ -286,7 +286,7 @@ describe("Automation Scenarios", () => { value: 20, }) .serverLog({ text: "Not Equal condition met" }) - .run({ fields: {} }) + .test({ fields: {} }) expect(results.steps[2].outputs.success).toBeTrue() expect(results.steps[2].outputs.result).toBeTrue() @@ -355,7 +355,7 @@ describe("Automation Scenarios", () => { .serverLog({ text: `${condition} condition ${expectPass ? "passed" : "failed"}`, }) - .run({ fields: {} }) + .test({ fields: {} }) expect(results.steps[2].outputs.result).toBe(expectPass) if (expectPass) { @@ -373,7 +373,7 @@ describe("Automation Scenarios", () => { const results = await createAutomationBuilder(config) .onRowUpdated({ tableId: table._id! }) .serverLog({ text: "{{ [user].[email] }}" }) - .run({ + .test({ row: { name: "Test", description: "TEST" }, id: "1234", }) @@ -385,7 +385,7 @@ describe("Automation Scenarios", () => { const results = await createAutomationBuilder(config) .onAppAction() .serverLog({ text: "{{ [user].[email] }}" }) - .run({ fields: {} }) + .test({ fields: {} }) expect(results.steps[0].outputs.message).toContain("example.com") }) @@ -475,7 +475,7 @@ if (descriptions.length) { .queryRows({ tableId: newTable._id!, }) - .run({ fields: {} }) + .test({ fields: {} }) expect(results.steps).toHaveLength(3) diff --git a/packages/server/src/automations/tests/steps/bash.spec.ts b/packages/server/src/automations/tests/steps/bash.spec.ts index 2174a6db42..48174ceb04 100644 --- a/packages/server/src/automations/tests/steps/bash.spec.ts +++ b/packages/server/src/automations/tests/steps/bash.spec.ts @@ -34,7 +34,7 @@ describe("Execute Bash Automations", () => { { text: "Bash output was: {{ steps.[Echo Command].stdout }}" }, { stepName: "Log Output" } ) - .run() + .test() expect(result.steps[0].outputs.stdout).toEqual("hello world\n") expect(result.steps[1].outputs.message).toContain( @@ -57,7 +57,7 @@ describe("Execute Bash Automations", () => { { code: "rm {{ trigger.fields.filename }}" }, { stepName: "Cleanup" } ) - .run() + .test() expect(result.steps[1].outputs.stdout).toEqual("INITIAL CONTENT\n") expect(result.steps[1].outputs.success).toEqual(true) @@ -112,7 +112,7 @@ describe("Execute Bash Automations", () => { { text: "Value was {{ steps.[Check Value].value }}" }, { stepName: "Log Result" } ) - .run() + .test() expect(result.steps[0].outputs.stdout).toEqual("10\n") expect(result.steps[1].outputs.value).toEqual("high") diff --git a/packages/server/src/automations/tests/steps/createRow.spec.ts b/packages/server/src/automations/tests/steps/createRow.spec.ts index 9d2fb5374f..a4523e15ef 100644 --- a/packages/server/src/automations/tests/steps/createRow.spec.ts +++ b/packages/server/src/automations/tests/steps/createRow.spec.ts @@ -48,7 +48,7 @@ describe("test the create row action", () => { { text: "Row created with ID: {{ stepsByName.CreateRow.row._id }}" }, { stepName: "CreationLog" } ) - .run() + .test() expect(result.steps[1].outputs.success).toBeDefined() expect(result.steps[1].outputs.id).toBeDefined() @@ -78,7 +78,7 @@ describe("test the create row action", () => { }, { stepName: "CreateRow" } ) - .run() + .test() expect(result.steps[1].outputs.success).toEqual(false) }) @@ -97,7 +97,7 @@ describe("test the create row action", () => { { text: "This log should not appear" }, { stepName: "SkippedLog" } ) - .run() + .test() expect(result.steps[1].outputs.success).toEqual(false) expect(result.steps.length).toBeLessThan(4) @@ -140,7 +140,7 @@ describe("test the create row action", () => { }, { stepName: "UploadLog" } ) - .run() + .test() expect(result.steps[1].outputs.success).toEqual(true) expect(result.steps[1].outputs.row.file_attachment[0]).toHaveProperty("key") @@ -209,7 +209,7 @@ describe("test the create row action", () => { }, }, }) - .run() + .test() expect(result.steps[1].outputs.success).toEqual(true) expect(result.steps[1].outputs.row.single_file_attachment).toHaveProperty( @@ -278,7 +278,7 @@ describe("test the create row action", () => { }, }, }) - .run() + .test() expect(result.steps[1].outputs.success).toEqual(false) expect(result.steps[1].outputs.response).toEqual( diff --git a/packages/server/src/automations/tests/steps/executeScript.spec.ts b/packages/server/src/automations/tests/steps/executeScript.spec.ts index 351af09a4a..117c2341ba 100644 --- a/packages/server/src/automations/tests/steps/executeScript.spec.ts +++ b/packages/server/src/automations/tests/steps/executeScript.spec.ts @@ -23,7 +23,7 @@ describe("Execute Script Automations", () => { const results = await createAutomationBuilder(config) .onAppAction() .executeScript({ code: "return 2 + 2" }) - .run({ fields: {} }) + .test({ fields: {} }) expect(results.steps[0].outputs.value).toEqual(4) }) @@ -37,7 +37,7 @@ describe("Execute Script Automations", () => { }, { stepId: "binding-script-step" } ) - .run({ fields: { data: [1, 2, 3] } }) + .test({ fields: { data: [1, 2, 3] } }) expect(results.steps[0].outputs.value).toEqual([2, 4, 6]) }) @@ -46,7 +46,7 @@ describe("Execute Script Automations", () => { const results = await createAutomationBuilder(config) .onAppAction() .executeScript({ code: "return nonexistentVariable.map(x => x)" }) - .run({ fields: {} }) + .test({ fields: {} }) expect(results.steps[0].outputs.response).toContain( "ReferenceError: nonexistentVariable is not defined" @@ -66,7 +66,7 @@ describe("Execute Script Automations", () => { } `, }) - .run({ fields: { value: 10 } }) + .test({ fields: { value: 10 } }) expect(results.steps[0].outputs.value).toEqual("Value is greater than 5") }) @@ -94,7 +94,7 @@ describe("Execute Script Automations", () => { .serverLog({ text: `Final result is {{ steps.ScriptingStep1.value }}`, }) - .run({ fields: {} }) + .test({ fields: {} }) expect(results.steps[0].outputs.message).toContain( "Starting multi-step automation" diff --git a/packages/server/src/automations/tests/steps/loop.spec.ts b/packages/server/src/automations/tests/steps/loop.spec.ts index 3d53b3aa01..5e4f3e8126 100644 --- a/packages/server/src/automations/tests/steps/loop.spec.ts +++ b/packages/server/src/automations/tests/steps/loop.spec.ts @@ -95,7 +95,7 @@ describe("Attempt to run a basic loop automation", () => { tableId: table._id, }, }) - .run() + .test() expect(results.trigger).toBeDefined() expect(results.steps).toHaveLength(1) @@ -136,7 +136,7 @@ describe("Attempt to run a basic loop automation", () => { }) .serverLog({ text: "Message {{loop.currentItem}}" }) .serverLog({ text: "{{steps.1.rows.0._id}}" }) - .run() + .test() results.steps[1].outputs.items.forEach( (output: ServerLogStepOutputs, index: number) => { @@ -240,7 +240,7 @@ describe("Attempt to run a basic loop automation", () => { binding: "Message 1,Message 2,Message 3", }) .serverLog({ text: "{{loop.currentItem}}" }) - .run() + .test() expect(results.trigger).toBeDefined() expect(results.steps).toHaveLength(2) diff --git a/packages/server/src/automations/tests/steps/openai.spec.ts b/packages/server/src/automations/tests/steps/openai.spec.ts index fb3382cff7..d5f002571d 100644 --- a/packages/server/src/automations/tests/steps/openai.spec.ts +++ b/packages/server/src/automations/tests/steps/openai.spec.ts @@ -60,7 +60,7 @@ describe("test the openai action", () => { createAutomationBuilder(config) .onAppAction() .openai({ prompt: "Hello, world", model: Model.GPT_4O_MINI }) - .run({ fields: {} }) + .test({ fields: {} }) ) expect(result.steps[0].outputs.response).toEqual("This is a test") @@ -72,7 +72,7 @@ describe("test the openai action", () => { createAutomationBuilder(config) .onAppAction() .openai({ prompt: "", model: Model.GPT_4O_MINI }) - .run({ fields: {} }) + .test({ fields: {} }) ) expect(result.steps[0].outputs.response).toEqual( @@ -88,7 +88,7 @@ describe("test the openai action", () => { createAutomationBuilder(config) .onAppAction() .openai({ prompt: "Hello, world", model: Model.GPT_4O_MINI }) - .run({ fields: {} }) + .test({ fields: {} }) ) expect(result.steps[0].outputs.response).toEqual( @@ -111,7 +111,7 @@ describe("test the openai action", () => { createAutomationBuilder(config) .onAppAction() .openai({ model: Model.GPT_4O_MINI, prompt: "Hello, world" }) - .run({ fields: {} }) + .test({ fields: {} }) ) expect(result.steps[0].outputs.response).toEqual("This is a test") diff --git a/packages/server/src/automations/tests/steps/queryRows.spec.ts b/packages/server/src/automations/tests/steps/queryRows.spec.ts index b377d05e73..f6d756e770 100644 --- a/packages/server/src/automations/tests/steps/queryRows.spec.ts +++ b/packages/server/src/automations/tests/steps/queryRows.spec.ts @@ -44,7 +44,7 @@ describe("Test a query step automation", () => { }, { stepName: "Query All Rows" } ) - .run({ fields: {} }) + .test({ fields: {} }) expect(result.steps[0].outputs.success).toBe(true) expect(result.steps[0].outputs.rows).toBeDefined() @@ -65,7 +65,7 @@ describe("Test a query step automation", () => { }, { stepName: "Query With Empty Filter" } ) - .run({ fields: {} }) + .test({ fields: {} }) expect(result.steps[0].outputs.success).toBe(true) expect(result.steps[0].outputs.rows).toBeDefined() @@ -88,7 +88,7 @@ describe("Test a query step automation", () => { }, { stepName: "Query With Return None" } ) - .run({ fields: {} }) + .test({ fields: {} }) expect(result.steps[0].outputs.success).toBe(true) expect(result.steps[0].outputs.rows).toBeDefined() @@ -114,7 +114,7 @@ describe("Test a query step automation", () => { }, { stepName: "Query With Null Filter" } ) - .run({ fields: {} }) + .test({ fields: {} }) expect(result.steps[0].outputs.success).toBe(true) expect(result.steps[0].outputs.rows).toBeDefined() @@ -135,7 +135,7 @@ describe("Test a query step automation", () => { }, { stepName: "Query With Return All" } ) - .run({ fields: {} }) + .test({ fields: {} }) expect(result.steps[0].outputs.success).toBe(true) expect(result.steps[0].outputs.rows).toBeDefined() @@ -160,7 +160,7 @@ describe("Test a query step automation", () => { }, { stepName: "Query table with spaces" } ) - .run({ fields: {} }) + .test({ fields: {} }) expect(result.steps[0].outputs.success).toBe(true) expect(result.steps[0].outputs.rows).toBeDefined() expect(result.steps[0].outputs.rows.length).toBe(1) diff --git a/packages/server/src/automations/tests/utilities/AutomationTestBuilder.ts b/packages/server/src/automations/tests/utilities/AutomationTestBuilder.ts index 00f87d3616..835a177ea8 100644 --- a/packages/server/src/automations/tests/utilities/AutomationTestBuilder.ts +++ b/packages/server/src/automations/tests/utilities/AutomationTestBuilder.ts @@ -31,7 +31,7 @@ type BranchConfig = { } class TriggerBuilder { - private config: TestConfiguration + private readonly config: TestConfiguration constructor(config: TestConfiguration) { this.config = config @@ -64,10 +64,10 @@ class TriggerBuilder { } class BranchStepBuilder { - protected steps: AutomationStep[] = [] - protected stepNames: { [key: string]: string } = {} + protected readonly steps: AutomationStep[] = [] + protected readonly stepNames: { [key: string]: string } = {} - protected createStepFn(stepId: TStep) { + protected step(stepId: TStep) { return ( inputs: AutomationStepInputs, opts?: { stepName?: string; stepId?: string } @@ -88,28 +88,28 @@ class BranchStepBuilder { } } - createRow = this.createStepFn(AutomationActionStepId.CREATE_ROW) - updateRow = this.createStepFn(AutomationActionStepId.UPDATE_ROW) - deleteRow = this.createStepFn(AutomationActionStepId.DELETE_ROW) - sendSmtpEmail = this.createStepFn(AutomationActionStepId.SEND_EMAIL_SMTP) - executeQuery = this.createStepFn(AutomationActionStepId.EXECUTE_QUERY) - queryRows = this.createStepFn(AutomationActionStepId.QUERY_ROWS) - loop = this.createStepFn(AutomationActionStepId.LOOP) - serverLog = this.createStepFn(AutomationActionStepId.SERVER_LOG) - executeScript = this.createStepFn(AutomationActionStepId.EXECUTE_SCRIPT) - filter = this.createStepFn(AutomationActionStepId.FILTER) - bash = this.createStepFn(AutomationActionStepId.EXECUTE_BASH) - openai = this.createStepFn(AutomationActionStepId.OPENAI) - collect = this.createStepFn(AutomationActionStepId.COLLECT) - zapier = this.createStepFn(AutomationActionStepId.zapier) - triggerAutomationRun = this.createStepFn( + createRow = this.step(AutomationActionStepId.CREATE_ROW) + updateRow = this.step(AutomationActionStepId.UPDATE_ROW) + deleteRow = this.step(AutomationActionStepId.DELETE_ROW) + sendSmtpEmail = this.step(AutomationActionStepId.SEND_EMAIL_SMTP) + executeQuery = this.step(AutomationActionStepId.EXECUTE_QUERY) + queryRows = this.step(AutomationActionStepId.QUERY_ROWS) + loop = this.step(AutomationActionStepId.LOOP) + serverLog = this.step(AutomationActionStepId.SERVER_LOG) + executeScript = this.step(AutomationActionStepId.EXECUTE_SCRIPT) + filter = this.step(AutomationActionStepId.FILTER) + bash = this.step(AutomationActionStepId.EXECUTE_BASH) + openai = this.step(AutomationActionStepId.OPENAI) + collect = this.step(AutomationActionStepId.COLLECT) + zapier = this.step(AutomationActionStepId.zapier) + triggerAutomationRun = this.step( AutomationActionStepId.TRIGGER_AUTOMATION_RUN ) - outgoingWebhook = this.createStepFn(AutomationActionStepId.OUTGOING_WEBHOOK) - n8n = this.createStepFn(AutomationActionStepId.n8n) - make = this.createStepFn(AutomationActionStepId.integromat) - discord = this.createStepFn(AutomationActionStepId.discord) - delay = this.createStepFn(AutomationActionStepId.DELAY) + outgoingWebhook = this.step(AutomationActionStepId.OUTGOING_WEBHOOK) + n8n = this.step(AutomationActionStepId.n8n) + make = this.step(AutomationActionStepId.integromat) + discord = this.step(AutomationActionStepId.discord) + delay = this.step(AutomationActionStepId.DELAY) protected addBranchStep(branchConfig: BranchConfig): void { const inputs: BranchStepInputs = { @@ -142,8 +142,8 @@ class BranchStepBuilder { class StepBuilder< TStep extends AutomationTriggerStepId > extends BranchStepBuilder { - private config: TestConfiguration - private trigger: AutomationTrigger + private readonly config: TestConfiguration + private readonly trigger: AutomationTrigger private _name: string | undefined = undefined constructor(config: TestConfiguration, trigger: AutomationTrigger) { @@ -176,26 +176,26 @@ class StepBuilder< return new AutomationRunner(this.config, automation) } - async run(outputs: AutomationTriggerOutputs) { + async test(triggerOutput: AutomationTriggerOutputs) { const runner = await this.save() - return await runner.run(outputs) + return await runner.test(triggerOutput) } } class AutomationRunner { - private config: TestConfiguration - automation: Automation + private readonly config: TestConfiguration + readonly automation: Automation constructor(config: TestConfiguration, automation: Automation) { this.config = config this.automation = automation } - async run(outputs: AutomationTriggerOutputs) { + async test(triggerOutput: AutomationTriggerOutputs) { const response = await this.config.api.automation.test( this.automation._id!, // TODO: figure out why this cast is needed. - outputs as TestAutomationRequest + triggerOutput as TestAutomationRequest ) if (isDidNotTriggerResponse(response)) {