Fixing test case and also making sure that external trigger does what its expected to.

This commit is contained in:
mike12345567 2020-12-07 17:55:35 +00:00
parent bc9a8ef0e3
commit 8a57f61607
3 changed files with 13 additions and 13 deletions

View File

@ -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

View File

@ -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
}
}

View File

@ -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({