Fixing automation test cases.
This commit is contained in:
parent
198ada80b3
commit
8119a5f7f7
|
@ -21,7 +21,7 @@ const automation = require("../index")
|
||||||
const usageQuota = require("../../utilities/usageQuota")
|
const usageQuota = require("../../utilities/usageQuota")
|
||||||
const thread = require("../thread")
|
const thread = require("../thread")
|
||||||
const triggers = require("../triggers")
|
const triggers = require("../triggers")
|
||||||
const { basicAutomation, basicTable } = require("../../tests/utilities/structures")
|
const { basicAutomation } = require("../../tests/utilities/structures")
|
||||||
const { wait } = require("../../utilities")
|
const { wait } = require("../../utilities")
|
||||||
const { makePartial } = require("../../tests/utilities")
|
const { makePartial } = require("../../tests/utilities")
|
||||||
const { cleanInputValues } = require("../automationUtils")
|
const { cleanInputValues } = require("../automationUtils")
|
||||||
|
@ -61,44 +61,13 @@ describe("Run through some parts of the automations system", () => {
|
||||||
it("try error scenario", async () => {
|
it("try error scenario", async () => {
|
||||||
await setup.runInProd(async () => {
|
await setup.runInProd(async () => {
|
||||||
// the second call will throw an error
|
// 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)
|
await wait(100)
|
||||||
expect(console.error).toHaveBeenCalled()
|
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 () => {
|
it("should check coercion", async () => {
|
||||||
const table = await config.createTable()
|
const table = await config.createTable()
|
||||||
const automation = basicAutomation()
|
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", () => {
|
it("should be able to clean inputs with the utilities", () => {
|
||||||
|
|
|
@ -5,9 +5,9 @@ const { coerce } = require("../utilities/rowProcessor")
|
||||||
const { definitions } = require("./triggerInfo")
|
const { definitions } = require("./triggerInfo")
|
||||||
const { isDevAppID } = require("../db/utils")
|
const { isDevAppID } = require("../db/utils")
|
||||||
// need this to call directly, so we can get a response
|
// need this to call directly, so we can get a response
|
||||||
const { processEvent } = require("./utils")
|
|
||||||
const { queue } = require("./bullboard")
|
const { queue } = require("./bullboard")
|
||||||
const { checkTestFlag } = require("../utilities/redis")
|
const { checkTestFlag } = require("../utilities/redis")
|
||||||
|
const utils = require("./utils")
|
||||||
|
|
||||||
const TRIGGER_DEFINITIONS = definitions
|
const TRIGGER_DEFINITIONS = definitions
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ exports.externalTrigger = async function (
|
||||||
}
|
}
|
||||||
const data = { automation, event: params }
|
const data = { automation, event: params }
|
||||||
if (getResponses) {
|
if (getResponses) {
|
||||||
return processEvent({ data })
|
return utils.processEvent({ data })
|
||||||
} else {
|
} else {
|
||||||
return queue.add(data)
|
return queue.add(data)
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,16 +52,19 @@ exports.processEvent = async job => {
|
||||||
if (env.USE_QUOTAS) {
|
if (env.USE_QUOTAS) {
|
||||||
job.data.automation.apiKey = await updateQuota(job.data.automation)
|
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()) {
|
if (!env.isProd()) {
|
||||||
return runSingleThread(job)
|
response = await runSingleThread(job)
|
||||||
} else {
|
} else {
|
||||||
return runWorker(job)
|
response = await runWorker(job)
|
||||||
}
|
}
|
||||||
|
return response
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(
|
console.error(
|
||||||
`${job.data.automation.appId} automation ${job.data.automation._id} was unable to run - ${err}`
|
`${job.data.automation.appId} automation ${job.data.automation._id} was unable to run - ${err}`
|
||||||
)
|
)
|
||||||
return err
|
return { err }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue