diff --git a/packages/server/src/api/routes/tests/automation.spec.ts b/packages/server/src/api/routes/tests/automation.spec.ts index 94517db67a..eeceabdb2f 100644 --- a/packages/server/src/api/routes/tests/automation.spec.ts +++ b/packages/server/src/api/routes/tests/automation.spec.ts @@ -257,7 +257,6 @@ describe("/automations", () => { appId: config.getAppId(), config, }) - .appAction({ fields: {} }) .serverLog({ text: "{{ settings.url }}", }) diff --git a/packages/server/src/automations/tests/branching.spec.ts b/packages/server/src/automations/tests/branching.spec.ts index 1a514e0537..e6a250577d 100644 --- a/packages/server/src/automations/tests/branching.spec.ts +++ b/packages/server/src/automations/tests/branching.spec.ts @@ -25,7 +25,6 @@ describe("Branching automations", () => { const branch2Id = "44444444-4444-4444-4444-444444444444" const results = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .serverLog( { text: "Starting automation" }, { stepName: "FirstLog", stepId: firstLogId } diff --git a/packages/server/src/automations/tests/scenarios.spec.ts b/packages/server/src/automations/tests/scenarios.spec.ts index 8d6e051ce2..6c40b793dd 100644 --- a/packages/server/src/automations/tests/scenarios.spec.ts +++ b/packages/server/src/automations/tests/scenarios.spec.ts @@ -66,7 +66,6 @@ describe("Automation Scenarios", () => { await config.api.row.save(table._id!, row) await config.api.row.save(table._id!, row) const results = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .queryRows({ tableId: table._id!, }) @@ -85,7 +84,6 @@ describe("Automation Scenarios", () => { await config.api.row.save(table._id!, row) await config.api.row.save(table._id!, row) const results = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .queryRows({ tableId: table._id!, }) @@ -127,7 +125,6 @@ describe("Automation Scenarios", () => { }) const results = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .createRow( { row: { @@ -196,7 +193,6 @@ describe("Automation Scenarios", () => { await config.api.row.save(table._id!, row) await config.api.row.save(table._id!, row) const results = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .queryRows( { tableId: table._id!, @@ -246,7 +242,6 @@ describe("Automation Scenarios", () => { it("should stop an automation if the condition is not met", async () => { const results = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .createRow({ row: { name: "Equal Test", @@ -272,7 +267,6 @@ describe("Automation Scenarios", () => { it("should continue the automation if the condition is met", async () => { const results = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .createRow({ row: { name: "Not Equal Test", @@ -339,7 +333,6 @@ describe("Automation Scenarios", () => { "should pass the filter when condition is $condition", async ({ condition, value, rowValue, expectPass }) => { const results = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .createRow({ row: { name: `${condition} Test`, @@ -389,7 +382,6 @@ describe("Automation Scenarios", () => { it("Check user is passed through from app trigger", async () => { const results = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .serverLog({ text: "{{ [user].[email] }}" }) .run() diff --git a/packages/server/src/automations/tests/steps/bash.spec.ts b/packages/server/src/automations/tests/steps/bash.spec.ts index ef10f9b568..edf01bb3e2 100644 --- a/packages/server/src/automations/tests/steps/bash.spec.ts +++ b/packages/server/src/automations/tests/steps/bash.spec.ts @@ -65,7 +65,6 @@ describe("Execute Bash Automations", () => { it("should integrate bash output with row operations", async () => { const result = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .queryRows( { tableId: table._id!, @@ -122,7 +121,6 @@ describe("Execute Bash Automations", () => { it("should handle null values gracefully", async () => { const result = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .bash( // @ts-expect-error - testing null input { code: null }, diff --git a/packages/server/src/automations/tests/steps/delay.spec.ts b/packages/server/src/automations/tests/steps/delay.spec.ts index a9e97b502f..89b85530e1 100644 --- a/packages/server/src/automations/tests/steps/delay.spec.ts +++ b/packages/server/src/automations/tests/steps/delay.spec.ts @@ -16,10 +16,7 @@ describe("test the delay logic", () => { const time = 100 const before = performance.now() - await createAutomationBuilder({ config }) - .appAction({ fields: {} }) - .delay({ time }) - .run() + await createAutomationBuilder({ config }).delay({ time }).run() const now = performance.now() diff --git a/packages/server/src/automations/tests/steps/deleteRow.spec.ts b/packages/server/src/automations/tests/steps/deleteRow.spec.ts index 1815edb4d3..52a5dacdd7 100644 --- a/packages/server/src/automations/tests/steps/deleteRow.spec.ts +++ b/packages/server/src/automations/tests/steps/deleteRow.spec.ts @@ -21,7 +21,6 @@ describe("test the delete row action", () => { it("should be able to run the delete row action", async () => { await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .deleteRow({ tableId: table._id!, id: row._id!, @@ -36,7 +35,6 @@ describe("test the delete row action", () => { it("should check invalid inputs return an error", async () => { const results = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .deleteRow({ tableId: "", id: "", revision: "" }) .run() @@ -45,7 +43,6 @@ describe("test the delete row action", () => { it("should return an error when table doesn't exist", async () => { const results = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .deleteRow({ tableId: "invalid", id: "invalid", diff --git a/packages/server/src/automations/tests/steps/discord.spec.ts b/packages/server/src/automations/tests/steps/discord.spec.ts index 5dc9c1088a..9d4d3f6033 100644 --- a/packages/server/src/automations/tests/steps/discord.spec.ts +++ b/packages/server/src/automations/tests/steps/discord.spec.ts @@ -20,7 +20,6 @@ describe("test the outgoing webhook action", () => { it("should be able to run the action", async () => { nock("http://www.example.com/").post("/").reply(200, { foo: "bar" }) const result = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .discord({ url: "http://www.example.com", username: "joe_bloggs", diff --git a/packages/server/src/automations/tests/steps/executeScript.spec.ts b/packages/server/src/automations/tests/steps/executeScript.spec.ts index 4470b8e760..2d510e86e0 100644 --- a/packages/server/src/automations/tests/steps/executeScript.spec.ts +++ b/packages/server/src/automations/tests/steps/executeScript.spec.ts @@ -21,7 +21,6 @@ describe("Execute Script Automations", () => { it("should execute a basic script and return the result", async () => { const results = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .executeScript({ code: "return 2 + 2" }) .run() @@ -44,7 +43,6 @@ describe("Execute Script Automations", () => { it("should handle script execution errors gracefully", async () => { const results = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .executeScript({ code: "return nonexistentVariable.map(x => x)" }) .run() @@ -73,7 +71,6 @@ describe("Execute Script Automations", () => { it("should use multiple steps and validate script execution", async () => { const results = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .serverLog( { text: "Starting multi-step automation" }, { stepId: "start-log-step" } diff --git a/packages/server/src/automations/tests/steps/filter.spec.ts b/packages/server/src/automations/tests/steps/filter.spec.ts index b0943f3fa8..0d4ac0f01a 100644 --- a/packages/server/src/automations/tests/steps/filter.spec.ts +++ b/packages/server/src/automations/tests/steps/filter.spec.ts @@ -43,7 +43,6 @@ describe("test the filter logic", () => { ] it.each(pass)("should pass %p %p %p", async (field, condition, value) => { const result = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .filter({ field, condition: stringToFilterCondition(condition), value }) .run() @@ -61,7 +60,6 @@ describe("test the filter logic", () => { ] it.each(fail)("should fail %p %p %p", async (field, condition, value) => { const result = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .filter({ field, condition: stringToFilterCondition(condition), value }) .run() diff --git a/packages/server/src/automations/tests/steps/loop.spec.ts b/packages/server/src/automations/tests/steps/loop.spec.ts index af174c33ca..764f55d9ad 100644 --- a/packages/server/src/automations/tests/steps/loop.spec.ts +++ b/packages/server/src/automations/tests/steps/loop.spec.ts @@ -152,7 +152,6 @@ describe("Attempt to run a basic loop automation", () => { it("if an incorrect type is passed to the loop it should return an error", async () => { const results = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .loop({ option: LoopStepType.ARRAY, binding: "1, 2, 3", @@ -168,7 +167,6 @@ describe("Attempt to run a basic loop automation", () => { it("ensure the loop stops if the failure condition is reached", async () => { const results = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .loop({ option: LoopStepType.ARRAY, binding: ["test", "test2", "test3"], @@ -187,7 +185,6 @@ describe("Attempt to run a basic loop automation", () => { it("ensure the loop stops if the max iterations are reached", async () => { const results = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .loop({ option: LoopStepType.ARRAY, binding: ["test", "test2", "test3"], @@ -202,7 +199,6 @@ describe("Attempt to run a basic loop automation", () => { it("should run an automation with loop and max iterations to ensure context correctness further down the tree", async () => { const results = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .loop({ option: LoopStepType.ARRAY, binding: ["test", "test2", "test3"], @@ -279,7 +275,6 @@ describe("Attempt to run a basic loop automation", () => { it("should run an automation where a loop is used twice to ensure context correctness further down the tree", async () => { const results = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .loop({ option: LoopStepType.ARRAY, binding: [1, 2, 3], @@ -301,7 +296,6 @@ describe("Attempt to run a basic loop automation", () => { it("should use automation names to loop with", async () => { const results = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .loop( { option: LoopStepType.ARRAY, @@ -353,7 +347,6 @@ describe("Attempt to run a basic loop automation", () => { await config.api.row.bulkImport(table._id!, { rows }) const results = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .queryRows({ tableId: table._id!, }) @@ -433,7 +426,6 @@ describe("Attempt to run a basic loop automation", () => { await config.api.row.bulkImport(table._id!, { rows }) const results = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .queryRows( { tableId: table._id!, @@ -516,7 +508,6 @@ describe("Attempt to run a basic loop automation", () => { await config.api.row.bulkImport(table._id!, { rows }) const results = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .queryRows({ tableId: table._id!, }) diff --git a/packages/server/src/automations/tests/steps/make.spec.ts b/packages/server/src/automations/tests/steps/make.spec.ts index 8ba5d3f8b7..a26f9f73ae 100644 --- a/packages/server/src/automations/tests/steps/make.spec.ts +++ b/packages/server/src/automations/tests/steps/make.spec.ts @@ -20,7 +20,6 @@ describe("test the outgoing webhook action", () => { it("should be able to run the action", async () => { nock("http://www.example.com/").post("/").reply(200, { foo: "bar" }) const result = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .make({ url: "http://www.example.com", body: null, @@ -47,7 +46,6 @@ describe("test the outgoing webhook action", () => { .reply(200, { foo: "bar" }) const result = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .make({ body: { value: JSON.stringify(payload) }, url: "http://www.example.com", @@ -60,7 +58,6 @@ describe("test the outgoing webhook action", () => { it("should return a 400 if the JSON payload string is malformed", async () => { const result = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .make({ body: { value: "{ invalid json }" }, url: "http://www.example.com", diff --git a/packages/server/src/automations/tests/steps/n8n.spec.ts b/packages/server/src/automations/tests/steps/n8n.spec.ts index 4427ea33e0..04d82fcd77 100644 --- a/packages/server/src/automations/tests/steps/n8n.spec.ts +++ b/packages/server/src/automations/tests/steps/n8n.spec.ts @@ -21,7 +21,6 @@ describe("test the outgoing webhook action", () => { it("should be able to run the action and default to 'get'", async () => { nock("http://www.example.com/").get("/").reply(200, { foo: "bar" }) const result = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .n8n({ url: "http://www.example.com", body: { test: "IGNORE_ME" }, @@ -40,7 +39,6 @@ describe("test the outgoing webhook action", () => { .reply(200) const result = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .n8n({ url: "http://www.example.com", body: { value: JSON.stringify({ name: "Adam", age: 9 }) }, @@ -54,7 +52,6 @@ describe("test the outgoing webhook action", () => { it("should return a 400 if the JSON payload string is malformed", async () => { const result = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .n8n({ url: "http://www.example.com", body: { value: "{ value1 1 }" }, @@ -74,7 +71,6 @@ describe("test the outgoing webhook action", () => { .reply(200) const result = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .n8n({ url: "http://www.example.com", method: HttpMethod.HEAD, diff --git a/packages/server/src/automations/tests/steps/openai.spec.ts b/packages/server/src/automations/tests/steps/openai.spec.ts index 3030b3db39..7e9fa1f933 100644 --- a/packages/server/src/automations/tests/steps/openai.spec.ts +++ b/packages/server/src/automations/tests/steps/openai.spec.ts @@ -58,7 +58,6 @@ describe("test the openai action", () => { // own API key. We don't count this against your quota. const result = await expectAIUsage(0, () => createAutomationBuilder({ config }) - .appAction({ fields: {} }) .openai({ prompt: "Hello, world", model: Model.GPT_4O_MINI }) .run() ) @@ -70,7 +69,6 @@ describe("test the openai action", () => { it("should present the correct error message when a prompt is not provided", async () => { const result = await expectAIUsage(0, () => createAutomationBuilder({ config }) - .appAction({ fields: {} }) .openai({ prompt: "", model: Model.GPT_4O_MINI }) .run() ) @@ -86,7 +84,6 @@ describe("test the openai action", () => { const result = await expectAIUsage(0, () => createAutomationBuilder({ config }) - .appAction({ fields: {} }) .openai({ prompt: "Hello, world", model: Model.GPT_4O_MINI }) .run() ) @@ -109,7 +106,6 @@ describe("test the openai action", () => { // key, so we charge users for it. const result = await expectAIUsage(14, () => createAutomationBuilder({ config }) - .appAction({ fields: {} }) .openai({ model: Model.GPT_4O_MINI, prompt: "Hello, world" }) .run() ) diff --git a/packages/server/src/automations/tests/steps/outgoingWebhook.spec.ts b/packages/server/src/automations/tests/steps/outgoingWebhook.spec.ts index b1ff5aa264..9ef3cf1e57 100644 --- a/packages/server/src/automations/tests/steps/outgoingWebhook.spec.ts +++ b/packages/server/src/automations/tests/steps/outgoingWebhook.spec.ts @@ -24,7 +24,6 @@ describe("test the outgoing webhook action", () => { .reply(200, { foo: "bar" }) const result = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .outgoingWebhook({ requestMethod: RequestType.POST, url: "http://www.example.com", @@ -40,7 +39,6 @@ describe("test the outgoing webhook action", () => { it("should return an error if something goes wrong in fetch", async () => { const result = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .outgoingWebhook({ requestMethod: RequestType.GET, url: "www.invalid.com", diff --git a/packages/server/src/automations/tests/steps/queryRows.spec.ts b/packages/server/src/automations/tests/steps/queryRows.spec.ts index 0030e7fc61..1d79d8e046 100644 --- a/packages/server/src/automations/tests/steps/queryRows.spec.ts +++ b/packages/server/src/automations/tests/steps/queryRows.spec.ts @@ -32,7 +32,6 @@ describe("Test a query step automation", () => { name: "Basic Query Test", config, }) - .appAction({ fields: {} }) .queryRows( { tableId: table._id!, @@ -60,7 +59,6 @@ describe("Test a query step automation", () => { name: "Empty Filter Test", config, }) - .appAction({ fields: {} }) .queryRows( { tableId: table._id!, @@ -84,7 +82,6 @@ describe("Test a query step automation", () => { name: "Return None Test", config, }) - .appAction({ fields: {} }) .queryRows( { tableId: table._id!, @@ -109,7 +106,6 @@ describe("Test a query step automation", () => { name: "Null Filter Test", config, }) - .appAction({ fields: {} }) .queryRows( { tableId: table._id!, @@ -138,7 +134,6 @@ describe("Test a query step automation", () => { name: "Return All Test", config, }) - .appAction({ fields: {} }) .queryRows( { tableId: table._id!, @@ -169,7 +164,6 @@ describe("Test a query step automation", () => { name: "Return All Test", config, }) - .appAction({ fields: {} }) .queryRows( { tableId: tableWithSpaces._id!, diff --git a/packages/server/src/automations/tests/steps/serverLog.spec.ts b/packages/server/src/automations/tests/steps/serverLog.spec.ts index 556f7b174c..73d72b9a99 100644 --- a/packages/server/src/automations/tests/steps/serverLog.spec.ts +++ b/packages/server/src/automations/tests/steps/serverLog.spec.ts @@ -14,7 +14,6 @@ describe("test the server log action", () => { it("should be able to log the text", async () => { const result = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .serverLog({ text: "Hello World" }) .run() expect(result.steps[0].outputs.message).toEqual( diff --git a/packages/server/src/automations/tests/steps/triggerAutomationRun.spec.ts b/packages/server/src/automations/tests/steps/triggerAutomationRun.spec.ts index 674f2386c1..4047c23566 100644 --- a/packages/server/src/automations/tests/steps/triggerAutomationRun.spec.ts +++ b/packages/server/src/automations/tests/steps/triggerAutomationRun.spec.ts @@ -18,12 +18,10 @@ describe("Test triggering an automation from another automation", () => { it("should trigger an other server log automation", async () => { const automation = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .serverLog({ text: "Hello World" }) .save() const result = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .triggerAutomationRun({ automation: { automationId: automation._id!, @@ -37,7 +35,6 @@ describe("Test triggering an automation from another automation", () => { it("should fail gracefully if the automation id is incorrect", async () => { const result = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .triggerAutomationRun({ automation: { // @ts-expect-error - incorrect on purpose diff --git a/packages/server/src/automations/tests/steps/updateRow.spec.ts b/packages/server/src/automations/tests/steps/updateRow.spec.ts index 79fed5f613..ca3854f745 100644 --- a/packages/server/src/automations/tests/steps/updateRow.spec.ts +++ b/packages/server/src/automations/tests/steps/updateRow.spec.ts @@ -31,7 +31,6 @@ describe("test the update row action", () => { it("should be able to run the update row action", async () => { const results = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .updateRow({ rowId: row._id!, row: { @@ -54,7 +53,6 @@ describe("test the update row action", () => { it("should check invalid inputs return an error", async () => { const results = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .updateRow({ meta: {}, row: {}, rowId: "" }) .run() @@ -63,7 +61,6 @@ describe("test the update row action", () => { it("should return an error when table doesn't exist", async () => { const results = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .updateRow({ row: { _id: "invalid" }, rowId: "invalid", @@ -107,7 +104,6 @@ describe("test the update row action", () => { }) const results = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .updateRow({ rowId: row._id!, row: { @@ -161,7 +157,6 @@ describe("test the update row action", () => { }) const results = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .updateRow({ rowId: row._id!, row: { diff --git a/packages/server/src/automations/tests/steps/zapier.spec.ts b/packages/server/src/automations/tests/steps/zapier.spec.ts index 17a0a7c7bf..331acb68f3 100644 --- a/packages/server/src/automations/tests/steps/zapier.spec.ts +++ b/packages/server/src/automations/tests/steps/zapier.spec.ts @@ -21,7 +21,6 @@ describe("test the outgoing webhook action", () => { nock("http://www.example.com/").post("/").reply(200, { foo: "bar" }) const result = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .zapier({ url: "http://www.example.com", body: null }) .run() @@ -45,7 +44,6 @@ describe("test the outgoing webhook action", () => { .reply(200, { foo: "bar" }) const result = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .zapier({ url: "http://www.example.com", body: { value: JSON.stringify(payload) }, @@ -58,7 +56,6 @@ describe("test the outgoing webhook action", () => { it("should return a 400 if the JSON payload string is malformed", async () => { const result = await createAutomationBuilder({ config }) - .appAction({ fields: {} }) .zapier({ url: "http://www.example.com", body: { value: "{ invalid json }" }, diff --git a/packages/server/src/automations/tests/triggers/createRow.spec.ts b/packages/server/src/automations/tests/triggers/createRow.spec.ts deleted file mode 100644 index 84f136c8a6..0000000000 --- a/packages/server/src/automations/tests/triggers/createRow.spec.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { createAutomationBuilder } from "../utilities/AutomationTestBuilder" -import TestConfiguration from "../../../tests/utilities/TestConfiguration" -import { getQueue } from "../.." -import { Job } from "bull" -import { basicTable } from "../../../tests/utilities/structures" -import { Table } from "@budibase/types" - -describe("cron trigger", () => { - const config = new TestConfiguration() - let table: Table - - beforeAll(async () => { - await config.init() - table = await config.api.table.save(basicTable()) - }) - - afterAll(() => { - config.end() - }) - - it("should successfully fire", async () => { - const queue = getQueue() - expect(await queue.getCompletedCount()).toEqual(0) - - const jobPromise = new Promise(resolve => { - queue.on("completed", async job => { - resolve(job) - }) - }) - - await createAutomationBuilder({ config }) - .rowSaved({ tableId: table._id! }) - .cron({ cron: "* * * * *" }) - .serverLog({ - text: "Hello, world!", - }) - .save() - - await config.api.application.publish(config.getAppId()) - - expect(await queue.getCompletedCount()).toEqual(1) - - const job = await jobPromise - const repeat = job.opts?.repeat - if (!repeat || !("cron" in repeat)) { - throw new Error("Expected cron repeat") - } - expect(repeat.cron).toEqual("* * * * *") - }) - - it("should fail if the cron expression is invalid", async () => { - await createAutomationBuilder({ config }) - .cron({ cron: "* * * * * *" }) - .serverLog({ - text: "Hello, world!", - }) - .save() - - await config.api.application.publish(config.getAppId(), { - status: 500, - body: { - message: - 'Deployment Failed: Invalid automation CRON "* * * * * *" - Expected 5 values, but got 6.', - }, - }) - }) -}) diff --git a/packages/server/src/automations/tests/utilities/AutomationTestBuilder.ts b/packages/server/src/automations/tests/utilities/AutomationTestBuilder.ts index 9484f5cf21..e059bd1c04 100644 --- a/packages/server/src/automations/tests/utilities/AutomationTestBuilder.ts +++ b/packages/server/src/automations/tests/utilities/AutomationTestBuilder.ts @@ -158,7 +158,7 @@ class AutomationBuilder extends BaseStepBuilder { } } - protected createTriggerFn< + protected triggerInputOutput< TStep extends AutomationTriggerStepId, TInput = AutomationTriggerInputs, TOutput = AutomationTriggerOutputs @@ -179,12 +179,28 @@ class AutomationBuilder extends BaseStepBuilder { } } - rowSaved = this.createTriggerFn(AutomationTriggerStepId.ROW_SAVED) - rowUpdated = this.createTriggerFn(AutomationTriggerStepId.ROW_UPDATED) - rowDeleted = this.createTriggerFn(AutomationTriggerStepId.ROW_DELETED) - appAction = this.createTriggerFn(AutomationTriggerStepId.APP) - webhook = this.createTriggerFn(AutomationTriggerStepId.WEBHOOK) - cron = this.createTriggerFn(AutomationTriggerStepId.CRON) + protected triggerOutputOnly< + TStep extends AutomationTriggerStepId, + TOutput = AutomationTriggerOutputs + >(stepId: TStep) { + return (outputs: TOutput) => { + this.triggerOutputs = outputs as TriggerOutputs + this.automationConfig.definition.trigger = { + ...TRIGGER_DEFINITIONS[stepId], + stepId, + id: uuidv4(), + } as AutomationTrigger + this.triggerSet = true + return this + } + } + + rowSaved = this.triggerInputOutput(AutomationTriggerStepId.ROW_SAVED) + rowUpdated = this.triggerInputOutput(AutomationTriggerStepId.ROW_UPDATED) + rowDeleted = this.triggerInputOutput(AutomationTriggerStepId.ROW_DELETED) + appAction = this.triggerOutputOnly(AutomationTriggerStepId.APP) + webhook = this.triggerInputOutput(AutomationTriggerStepId.WEBHOOK) + cron = this.triggerInputOutput(AutomationTriggerStepId.CRON) branch(branchConfig: BranchConfig): this { this.addBranchStep(branchConfig)