|
|
@ -1,11 +1,10 @@ |
|
|
const TestConfig = require("./utilities/TestConfiguration") |
|
|
|
|
|
const { |
|
|
const { |
|
|
checkBuilderEndpoint, |
|
|
checkBuilderEndpoint, |
|
|
getAllTableRows, |
|
|
getAllTableRows, |
|
|
clearAllAutomations, |
|
|
clearAllAutomations, |
|
|
} = require("./utilities/TestFunctions") |
|
|
} = require("./utilities/TestFunctions") |
|
|
const { basicAutomation } = require("./utilities/structures") |
|
|
const { basicAutomation } = require("./utilities/structures") |
|
|
const { delay } = require("./utilities") |
|
|
const setup = require("./utilities") |
|
|
|
|
|
|
|
|
const MAX_RETRIES = 4 |
|
|
const MAX_RETRIES = 4 |
|
|
|
|
|
|
|
|
@ -14,23 +13,16 @@ let TRIGGER_DEFINITIONS = {} |
|
|
let LOGIC_DEFINITIONS = {} |
|
|
let LOGIC_DEFINITIONS = {} |
|
|
|
|
|
|
|
|
describe("/automations", () => { |
|
|
describe("/automations", () => { |
|
|
let request |
|
|
let request = setup.getRequest() |
|
|
let config |
|
|
let config = setup.getConfig() |
|
|
let automation |
|
|
let automation |
|
|
|
|
|
|
|
|
beforeAll(async () => { |
|
|
afterAll(setup.afterAll) |
|
|
config = new TestConfig() |
|
|
|
|
|
request = config.request |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
beforeEach(async () => { |
|
|
beforeEach(async () => { |
|
|
await config.init() |
|
|
await config.init() |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
afterAll(() => { |
|
|
|
|
|
config.end() |
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
const triggerWorkflow = async automation => { |
|
|
const triggerWorkflow = async automation => { |
|
|
return await request |
|
|
return await request |
|
|
.post(`/api/automations/${automation._id}/trigger`) |
|
|
.post(`/api/automations/${automation._id}/trigger`) |
|
|
@ -133,7 +125,7 @@ describe("/automations", () => { |
|
|
automation.definition.trigger.inputs.tableId = table._id |
|
|
automation.definition.trigger.inputs.tableId = table._id |
|
|
automation.definition.steps[0].inputs.row.tableId = table._id |
|
|
automation.definition.steps[0].inputs.row.tableId = table._id |
|
|
automation = await config.createAutomation(automation) |
|
|
automation = await config.createAutomation(automation) |
|
|
await delay(500) |
|
|
await setup.delay(500) |
|
|
const res = await triggerWorkflow(automation) |
|
|
const res = await triggerWorkflow(automation) |
|
|
// 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
|
|
|
@ -142,7 +134,7 @@ describe("/automations", () => { |
|
|
for (let tries = 0; tries < MAX_RETRIES; tries++) { |
|
|
for (let tries = 0; tries < MAX_RETRIES; tries++) { |
|
|
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(automation.name) |
|
|
expect(res.body.automation.name).toEqual(automation.name) |
|
|
await delay(500) |
|
|
await setup.delay(500) |
|
|
let elements = await getAllTableRows(config) |
|
|
let elements = await getAllTableRows(config) |
|
|
// 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) { |
|
|
|