From 837778c250d3f0db42ab89c3025e138652f51c23 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 7 Dec 2020 17:55:35 +0000 Subject: [PATCH] Fixing test case and also making sure that external trigger does what its expected to. --- .../server/src/api/routes/tests/automation.spec.js | 12 +++++++----- packages/server/src/automations/triggers.js | 12 +++++------- packages/server/src/events/AutomationEmitter.js | 2 +- 3 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/server/src/api/routes/tests/automation.spec.js b/packages/server/src/api/routes/tests/automation.spec.js index 633926195a..314f5c2d17 100644 --- a/packages/server/src/api/routes/tests/automation.spec.js +++ b/packages/server/src/api/routes/tests/automation.spec.js @@ -127,8 +127,8 @@ describe("/automations", () => { trigger.id = "wadiawdo34" let createAction = ACTION_DEFINITIONS["CREATE_ROW"] createAction.inputs.row = { - name: "{{trigger.name}}", - description: "{{trigger.description}}" + name: "{{trigger.row.name}}", + description: "{{trigger.row.description}}" } createAction.id = "awde444wk" @@ -164,21 +164,23 @@ describe("/automations", () => { describe("trigger", () => { it("trigger the automation successfully", async () => { let table = await createTable(request, appId) + TEST_AUTOMATION.definition.trigger.inputs.tableId = table._id TEST_AUTOMATION.definition.steps[0].inputs.row.tableId = table._id await createAutomation() + await delay(500) + const res = await triggerWorkflow(automation._id) // this looks a bit mad but we don't actually have a way to wait for a response from the automation to // know that it has finished all of its actions - this is currently the best way // also when this runs in CI it is very temper-mental so for now trying to make run stable by repeating until it works // TODO: update when workflow logs are a thing for (let tries = 0; tries < MAX_RETRIES; tries++) { - const res = await triggerWorkflow(automation._id) expect(res.body.message).toEqual(`Automation ${automation._id} has been triggered.`) expect(res.body.automation.name).toEqual(TEST_AUTOMATION.name) await delay(500) let elements = await getAllFromTable(request, appId, table._id) // don't test it unless there are values to test - if (elements.length === 1) { - expect(elements.length).toEqual(1) + if (elements.length > 1) { + expect(elements.length).toEqual(5) expect(elements[0].name).toEqual("Test") expect(elements[0].description).toEqual("TEST") return diff --git a/packages/server/src/automations/triggers.js b/packages/server/src/automations/triggers.js index 5d2121df7b..6fbd8e4c25 100644 --- a/packages/server/src/automations/triggers.js +++ b/packages/server/src/automations/triggers.js @@ -174,22 +174,20 @@ async function fillRowOutput(automation, params) { let table = await db.get(tableId) let row = {} for (let schemaKey of Object.keys(table.schema)) { - if (params[schemaKey] != null) { - continue - } + const paramValue = params[schemaKey] let propSchema = table.schema[schemaKey] switch (propSchema.constraints.type) { case "string": - row[schemaKey] = FAKE_STRING + row[schemaKey] = paramValue || FAKE_STRING break case "boolean": - row[schemaKey] = FAKE_BOOL + row[schemaKey] = paramValue || FAKE_BOOL break case "number": - row[schemaKey] = FAKE_NUMBER + row[schemaKey] = paramValue || FAKE_NUMBER break case "datetime": - row[schemaKey] = FAKE_DATETIME + row[schemaKey] = paramValue || FAKE_DATETIME break } } diff --git a/packages/server/src/events/AutomationEmitter.js b/packages/server/src/events/AutomationEmitter.js index 43cea664a9..fbfc445e2c 100644 --- a/packages/server/src/events/AutomationEmitter.js +++ b/packages/server/src/events/AutomationEmitter.js @@ -20,7 +20,7 @@ class AutomationEmitter { emitRow(eventName, appId, row, table = null) { // don't emit even if we've reached max automation chain - if (this.chainCount > MAX_AUTOMATION_CHAIN) { + if (this.chainCount >= MAX_AUTOMATION_CHAIN) { return } rowEmission({