diff --git a/packages/server/src/automations/tests/automation.spec.js b/packages/server/src/automations/tests/automation.spec.js index 05ec44d70e..689ee4ab76 100644 --- a/packages/server/src/automations/tests/automation.spec.js +++ b/packages/server/src/automations/tests/automation.spec.js @@ -21,7 +21,7 @@ const automation = require("../index") const usageQuota = require("../../utilities/usageQuota") const thread = require("../thread") const triggers = require("../triggers") -const { basicAutomation, basicTable } = require("../../tests/utilities/structures") +const { basicAutomation } = require("../../tests/utilities/structures") const { wait } = require("../../utilities") const { makePartial } = require("../../tests/utilities") const { cleanInputValues } = require("../automationUtils") @@ -61,44 +61,13 @@ describe("Run through some parts of the automations system", () => { it("try error scenario", async () => { await setup.runInProd(async () => { // the second call will throw an error - await triggers.externalTrigger(basicAutomation(), { a: 1 }) + const response = await triggers.externalTrigger(basicAutomation(), {a: 1}, {getResponses: true}) await wait(100) expect(console.error).toHaveBeenCalled() + expect(response.err).toBeDefined() }) }) - it("should be able to check triggering row filling", async () => { - const automation = basicAutomation() - let table = basicTable() - table.schema.boolean = { - type: "boolean", - constraints: { - type: "boolean", - }, - } - table.schema.number = { - type: "number", - constraints: { - type: "number", - }, - } - table.schema.datetime = { - type: "datetime", - constraints: { - type: "datetime", - }, - } - table = await config.createTable(table) - automation.definition.trigger.inputs.tableId = table._id - const params = await triggers.fillRowOutput(automation, { appId: config.getAppId() }) - expect(params.row).toBeDefined() - const date = new Date(params.row.datetime) - expect(typeof params.row.name).toBe("string") - expect(typeof params.row.boolean).toBe("boolean") - expect(typeof params.row.number).toBe("number") - expect(date.getFullYear()).toBe(1970) - }) - it("should check coercion", async () => { const table = await config.createTable() const automation = basicAutomation() @@ -120,7 +89,7 @@ describe("Run through some parts of the automations system", () => { } } } - })) + }), expect.any(Function)) }) it("should be able to clean inputs with the utilities", () => { diff --git a/packages/server/src/automations/triggers.js b/packages/server/src/automations/triggers.js index db4b8304dd..d90511c7ba 100644 --- a/packages/server/src/automations/triggers.js +++ b/packages/server/src/automations/triggers.js @@ -5,9 +5,9 @@ const { coerce } = require("../utilities/rowProcessor") const { definitions } = require("./triggerInfo") const { isDevAppID } = require("../db/utils") // need this to call directly, so we can get a response -const { processEvent } = require("./utils") const { queue } = require("./bullboard") const { checkTestFlag } = require("../utilities/redis") +const utils = require("./utils") const TRIGGER_DEFINITIONS = definitions @@ -90,7 +90,7 @@ exports.externalTrigger = async function ( } const data = { automation, event: params } if (getResponses) { - return processEvent({ data }) + return utils.processEvent({ data }) } else { return queue.add(data) } diff --git a/packages/server/src/automations/utils.js b/packages/server/src/automations/utils.js index 6815de3e62..29a8e38b18 100644 --- a/packages/server/src/automations/utils.js +++ b/packages/server/src/automations/utils.js @@ -52,16 +52,19 @@ exports.processEvent = async job => { if (env.USE_QUOTAS) { job.data.automation.apiKey = await updateQuota(job.data.automation) } + // need to actually await these so that an error can be captured properly + let response if (!env.isProd()) { - return runSingleThread(job) + response = await runSingleThread(job) } else { - return runWorker(job) + response = await runWorker(job) } + return response } catch (err) { console.error( `${job.data.automation.appId} automation ${job.data.automation._id} was unable to run - ${err}` ) - return err + return { err } } }