Fixing test case and also making sure that external trigger does what its expected to.
This commit is contained in:
parent
bc9a8ef0e3
commit
8a57f61607
|
@ -127,8 +127,8 @@ describe("/automations", () => {
|
||||||
trigger.id = "wadiawdo34"
|
trigger.id = "wadiawdo34"
|
||||||
let createAction = ACTION_DEFINITIONS["CREATE_ROW"]
|
let createAction = ACTION_DEFINITIONS["CREATE_ROW"]
|
||||||
createAction.inputs.row = {
|
createAction.inputs.row = {
|
||||||
name: "{{trigger.name}}",
|
name: "{{trigger.row.name}}",
|
||||||
description: "{{trigger.description}}"
|
description: "{{trigger.row.description}}"
|
||||||
}
|
}
|
||||||
createAction.id = "awde444wk"
|
createAction.id = "awde444wk"
|
||||||
|
|
||||||
|
@ -164,21 +164,23 @@ describe("/automations", () => {
|
||||||
describe("trigger", () => {
|
describe("trigger", () => {
|
||||||
it("trigger the automation successfully", async () => {
|
it("trigger the automation successfully", async () => {
|
||||||
let table = await createTable(request, appId)
|
let table = await createTable(request, appId)
|
||||||
|
TEST_AUTOMATION.definition.trigger.inputs.tableId = table._id
|
||||||
TEST_AUTOMATION.definition.steps[0].inputs.row.tableId = table._id
|
TEST_AUTOMATION.definition.steps[0].inputs.row.tableId = table._id
|
||||||
await createAutomation()
|
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
|
// 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
|
// 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
|
// 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
|
// TODO: update when workflow logs are a thing
|
||||||
for (let tries = 0; tries < MAX_RETRIES; tries++) {
|
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.message).toEqual(`Automation ${automation._id} has been triggered.`)
|
||||||
expect(res.body.automation.name).toEqual(TEST_AUTOMATION.name)
|
expect(res.body.automation.name).toEqual(TEST_AUTOMATION.name)
|
||||||
await delay(500)
|
await delay(500)
|
||||||
let elements = await getAllFromTable(request, appId, table._id)
|
let elements = await getAllFromTable(request, appId, table._id)
|
||||||
// don't test it unless there are values to test
|
// don't test it unless there are values to test
|
||||||
if (elements.length === 1) {
|
if (elements.length > 1) {
|
||||||
expect(elements.length).toEqual(1)
|
expect(elements.length).toEqual(5)
|
||||||
expect(elements[0].name).toEqual("Test")
|
expect(elements[0].name).toEqual("Test")
|
||||||
expect(elements[0].description).toEqual("TEST")
|
expect(elements[0].description).toEqual("TEST")
|
||||||
return
|
return
|
||||||
|
|
|
@ -174,22 +174,20 @@ async function fillRowOutput(automation, params) {
|
||||||
let table = await db.get(tableId)
|
let table = await db.get(tableId)
|
||||||
let row = {}
|
let row = {}
|
||||||
for (let schemaKey of Object.keys(table.schema)) {
|
for (let schemaKey of Object.keys(table.schema)) {
|
||||||
if (params[schemaKey] != null) {
|
const paramValue = params[schemaKey]
|
||||||
continue
|
|
||||||
}
|
|
||||||
let propSchema = table.schema[schemaKey]
|
let propSchema = table.schema[schemaKey]
|
||||||
switch (propSchema.constraints.type) {
|
switch (propSchema.constraints.type) {
|
||||||
case "string":
|
case "string":
|
||||||
row[schemaKey] = FAKE_STRING
|
row[schemaKey] = paramValue || FAKE_STRING
|
||||||
break
|
break
|
||||||
case "boolean":
|
case "boolean":
|
||||||
row[schemaKey] = FAKE_BOOL
|
row[schemaKey] = paramValue || FAKE_BOOL
|
||||||
break
|
break
|
||||||
case "number":
|
case "number":
|
||||||
row[schemaKey] = FAKE_NUMBER
|
row[schemaKey] = paramValue || FAKE_NUMBER
|
||||||
break
|
break
|
||||||
case "datetime":
|
case "datetime":
|
||||||
row[schemaKey] = FAKE_DATETIME
|
row[schemaKey] = paramValue || FAKE_DATETIME
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ class AutomationEmitter {
|
||||||
|
|
||||||
emitRow(eventName, appId, row, table = null) {
|
emitRow(eventName, appId, row, table = null) {
|
||||||
// don't emit even if we've reached max automation chain
|
// don't emit even if we've reached max automation chain
|
||||||
if (this.chainCount > MAX_AUTOMATION_CHAIN) {
|
if (this.chainCount >= MAX_AUTOMATION_CHAIN) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rowEmission({
|
rowEmission({
|
||||||
|
|
Loading…
Reference in New Issue