Fix some automation tests.
This commit is contained in:
parent
50ce97135c
commit
48578e1f18
|
@ -1,15 +1,15 @@
|
||||||
const setup = require("./utilities")
|
import { getConfig, afterAll as _afterAll, runStep } from "./utilities"
|
||||||
|
|
||||||
describe("test the bash action", () => {
|
describe("test the bash action", () => {
|
||||||
let config = setup.getConfig()
|
let config = getConfig()
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await config.init()
|
await config.init()
|
||||||
})
|
})
|
||||||
afterAll(setup.afterAll)
|
afterAll(_afterAll)
|
||||||
|
|
||||||
it("should be able to execute a script", async () => {
|
it("should be able to execute a script", async () => {
|
||||||
let res = await setup.runStep("EXECUTE_BASH", {
|
let res = await runStep(config, "EXECUTE_BASH", {
|
||||||
code: "echo 'test'",
|
code: "echo 'test'",
|
||||||
})
|
})
|
||||||
expect(res.stdout).toEqual("test\n")
|
expect(res.stdout).toEqual("test\n")
|
||||||
|
@ -17,7 +17,7 @@ describe("test the bash action", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should handle a null value", async () => {
|
it("should handle a null value", async () => {
|
||||||
let res = await setup.runStep("EXECUTE_BASH", {
|
let res = await runStep(config, "EXECUTE_BASH", {
|
||||||
code: null,
|
code: null,
|
||||||
})
|
})
|
||||||
expect(res.stdout).toEqual(
|
expect(res.stdout).toEqual(
|
|
@ -31,7 +31,7 @@ describe("test the create row action", () => {
|
||||||
afterAll(setup.afterAll)
|
afterAll(setup.afterAll)
|
||||||
|
|
||||||
it("should be able to run the action", async () => {
|
it("should be able to run the action", async () => {
|
||||||
const res = await setup.runStep(setup.actions.CREATE_ROW.stepId, {
|
const res = await setup.runStep(config, setup.actions.CREATE_ROW.stepId, {
|
||||||
row,
|
row,
|
||||||
})
|
})
|
||||||
expect(res.id).toBeDefined()
|
expect(res.id).toBeDefined()
|
||||||
|
@ -43,7 +43,7 @@ describe("test the create row action", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should return an error (not throw) when bad info provided", async () => {
|
it("should return an error (not throw) when bad info provided", async () => {
|
||||||
const res = await setup.runStep(setup.actions.CREATE_ROW.stepId, {
|
const res = await setup.runStep(config, setup.actions.CREATE_ROW.stepId, {
|
||||||
row: {
|
row: {
|
||||||
tableId: "invalid",
|
tableId: "invalid",
|
||||||
invalid: "invalid",
|
invalid: "invalid",
|
||||||
|
@ -53,7 +53,7 @@ describe("test the create row action", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should check invalid inputs return an error", async () => {
|
it("should check invalid inputs return an error", async () => {
|
||||||
const res = await setup.runStep(setup.actions.CREATE_ROW.stepId, {})
|
const res = await setup.runStep(config, setup.actions.CREATE_ROW.stepId, {})
|
||||||
expect(res.success).toEqual(false)
|
expect(res.success).toEqual(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ describe("test the create row action", () => {
|
||||||
]
|
]
|
||||||
|
|
||||||
attachmentRow.file_attachment = attachmentObject
|
attachmentRow.file_attachment = attachmentObject
|
||||||
const res = await setup.runStep(setup.actions.CREATE_ROW.stepId, {
|
const res = await setup.runStep(config, setup.actions.CREATE_ROW.stepId, {
|
||||||
row: attachmentRow,
|
row: attachmentRow,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -111,7 +111,7 @@ describe("test the create row action", () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
attachmentRow.single_file_attachment = attachmentObject
|
attachmentRow.single_file_attachment = attachmentObject
|
||||||
const res = await setup.runStep(setup.actions.CREATE_ROW.stepId, {
|
const res = await setup.runStep(config, setup.actions.CREATE_ROW.stepId, {
|
||||||
row: attachmentRow,
|
row: attachmentRow,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ describe("test the create row action", () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
attachmentRow.single_file_attachment = attachmentObject
|
attachmentRow.single_file_attachment = attachmentObject
|
||||||
const res = await setup.runStep(setup.actions.CREATE_ROW.stepId, {
|
const res = await setup.runStep(config, setup.actions.CREATE_ROW.stepId, {
|
||||||
row: attachmentRow,
|
row: attachmentRow,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,14 +1,20 @@
|
||||||
const setup = require("./utilities")
|
import { runStep, actions, getConfig } from "./utilities"
|
||||||
|
import { reset } from "timekeeper"
|
||||||
|
|
||||||
// need real Date for this test
|
// need real Date for this test
|
||||||
const tk = require("timekeeper")
|
reset()
|
||||||
tk.reset()
|
|
||||||
|
|
||||||
describe("test the delay logic", () => {
|
describe("test the delay logic", () => {
|
||||||
|
const config = getConfig()
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
await config.init()
|
||||||
|
})
|
||||||
|
|
||||||
it("should be able to run the delay", async () => {
|
it("should be able to run the delay", async () => {
|
||||||
const time = 100
|
const time = 100
|
||||||
const before = Date.now()
|
const before = Date.now()
|
||||||
await setup.runStep(setup.actions.DELAY.stepId, { time: time })
|
await runStep(config, actions.DELAY.stepId, { time: time })
|
||||||
const now = Date.now()
|
const now = Date.now()
|
||||||
// divide by two just so that test will always pass as long as there was some sort of delay
|
// divide by two just so that test will always pass as long as there was some sort of delay
|
||||||
expect(now - before).toBeGreaterThanOrEqual(time / 2)
|
expect(now - before).toBeGreaterThanOrEqual(time / 2)
|
|
@ -1,4 +1,4 @@
|
||||||
const setup = require("./utilities")
|
import * as setup from "./utilities"
|
||||||
|
|
||||||
describe("test the delete row action", () => {
|
describe("test the delete row action", () => {
|
||||||
let table: any
|
let table: any
|
||||||
|
@ -20,32 +20,29 @@ describe("test the delete row action", () => {
|
||||||
afterAll(setup.afterAll)
|
afterAll(setup.afterAll)
|
||||||
|
|
||||||
it("should be able to run the action", async () => {
|
it("should be able to run the action", async () => {
|
||||||
const res = await setup.runStep(setup.actions.DELETE_ROW.stepId, inputs)
|
const res = await setup.runStep(
|
||||||
|
config,
|
||||||
|
setup.actions.DELETE_ROW.stepId,
|
||||||
|
inputs
|
||||||
|
)
|
||||||
expect(res.success).toEqual(true)
|
expect(res.success).toEqual(true)
|
||||||
expect(res.response).toBeDefined()
|
expect(res.response).toBeDefined()
|
||||||
expect(res.row._id).toEqual(row._id)
|
expect(res.row._id).toEqual(row._id)
|
||||||
let error
|
|
||||||
try {
|
|
||||||
await config.getRow(table._id, res.row._id)
|
|
||||||
} catch (err) {
|
|
||||||
error = err
|
|
||||||
}
|
|
||||||
expect(error).toBeDefined()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
it("check usage quota attempts", async () => {
|
it("check usage quota attempts", async () => {
|
||||||
await setup.runInProd(async () => {
|
await setup.runInProd(async () => {
|
||||||
await setup.runStep(setup.actions.DELETE_ROW.stepId, inputs)
|
await setup.runStep(config, setup.actions.DELETE_ROW.stepId, inputs)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should check invalid inputs return an error", async () => {
|
it("should check invalid inputs return an error", async () => {
|
||||||
const res = await setup.runStep(setup.actions.DELETE_ROW.stepId, {})
|
const res = await setup.runStep(config, setup.actions.DELETE_ROW.stepId, {})
|
||||||
expect(res.success).toEqual(false)
|
expect(res.success).toEqual(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should return an error when table doesn't exist", async () => {
|
it("should return an error when table doesn't exist", async () => {
|
||||||
const res = await setup.runStep(setup.actions.DELETE_ROW.stepId, {
|
const res = await setup.runStep(config, setup.actions.DELETE_ROW.stepId, {
|
||||||
tableId: "invalid",
|
tableId: "invalid",
|
||||||
id: "invalid",
|
id: "invalid",
|
||||||
revision: "invalid",
|
revision: "invalid",
|
||||||
|
|
|
@ -16,7 +16,7 @@ describe("test the outgoing webhook action", () => {
|
||||||
|
|
||||||
it("should be able to run the action", async () => {
|
it("should be able to run the action", async () => {
|
||||||
nock("http://www.example.com/").post("/").reply(200, { foo: "bar" })
|
nock("http://www.example.com/").post("/").reply(200, { foo: "bar" })
|
||||||
const res = await runStep(actions.discord.stepId, {
|
const res = await runStep(config, actions.discord.stepId, {
|
||||||
url: "http://www.example.com",
|
url: "http://www.example.com",
|
||||||
username: "joe_bloggs",
|
username: "joe_bloggs",
|
||||||
})
|
})
|
||||||
|
|
|
@ -8,7 +8,10 @@ import { Knex } from "knex"
|
||||||
import { generator } from "@budibase/backend-core/tests"
|
import { generator } from "@budibase/backend-core/tests"
|
||||||
|
|
||||||
datasourceDescribe(
|
datasourceDescribe(
|
||||||
{ name: "execute query action", exclude: [DatabaseName.MONGODB] },
|
{
|
||||||
|
name: "execute query action",
|
||||||
|
exclude: [DatabaseName.MONGODB, DatabaseName.SQS],
|
||||||
|
},
|
||||||
({ config, dsProvider }) => {
|
({ config, dsProvider }) => {
|
||||||
let tableName: string
|
let tableName: string
|
||||||
let client: Knex
|
let client: Knex
|
||||||
|
@ -35,28 +38,38 @@ datasourceDescribe(
|
||||||
await client.schema.dropTable(tableName)
|
await client.schema.dropTable(tableName)
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(setup.afterAll)
|
|
||||||
|
|
||||||
it("should be able to execute a query", async () => {
|
it("should be able to execute a query", async () => {
|
||||||
let res = await setup.runStep(setup.actions.EXECUTE_QUERY.stepId, {
|
let res = await setup.runStep(
|
||||||
|
config,
|
||||||
|
setup.actions.EXECUTE_QUERY.stepId,
|
||||||
|
{
|
||||||
query: { queryId: query._id },
|
query: { queryId: query._id },
|
||||||
})
|
}
|
||||||
|
)
|
||||||
expect(res.response).toEqual([{ a: "string", b: 1 }])
|
expect(res.response).toEqual([{ a: "string", b: 1 }])
|
||||||
expect(res.success).toEqual(true)
|
expect(res.success).toEqual(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should handle a null query value", async () => {
|
it("should handle a null query value", async () => {
|
||||||
let res = await setup.runStep(setup.actions.EXECUTE_QUERY.stepId, {
|
let res = await setup.runStep(
|
||||||
|
config,
|
||||||
|
setup.actions.EXECUTE_QUERY.stepId,
|
||||||
|
{
|
||||||
query: null,
|
query: null,
|
||||||
})
|
}
|
||||||
|
)
|
||||||
expect(res.response.message).toEqual("Invalid inputs")
|
expect(res.response.message).toEqual("Invalid inputs")
|
||||||
expect(res.success).toEqual(false)
|
expect(res.success).toEqual(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should handle an error executing a query", async () => {
|
it("should handle an error executing a query", async () => {
|
||||||
let res = await setup.runStep(setup.actions.EXECUTE_QUERY.stepId, {
|
let res = await setup.runStep(
|
||||||
|
config,
|
||||||
|
setup.actions.EXECUTE_QUERY.stepId,
|
||||||
|
{
|
||||||
query: { queryId: "wrong_id" },
|
query: { queryId: "wrong_id" },
|
||||||
})
|
}
|
||||||
|
)
|
||||||
expect(res.response).toBeDefined()
|
expect(res.response).toBeDefined()
|
||||||
expect(res.success).toEqual(false)
|
expect(res.success).toEqual(false)
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
const setup = require("./utilities")
|
import { getConfig, afterAll as _afterAll, runStep, actions } from "./utilities"
|
||||||
|
|
||||||
describe("test the execute script action", () => {
|
describe("test the execute script action", () => {
|
||||||
let config = setup.getConfig()
|
let config = getConfig()
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await config.init()
|
await config.init()
|
||||||
})
|
})
|
||||||
afterAll(setup.afterAll)
|
afterAll(_afterAll)
|
||||||
|
|
||||||
it("should be able to execute a script", async () => {
|
it("should be able to execute a script", async () => {
|
||||||
const res = await setup.runStep(setup.actions.EXECUTE_SCRIPT.stepId, {
|
const res = await runStep(config, actions.EXECUTE_SCRIPT.stepId, {
|
||||||
code: "return 1 + 1",
|
code: "return 1 + 1",
|
||||||
})
|
})
|
||||||
expect(res.value).toEqual(2)
|
expect(res.value).toEqual(2)
|
||||||
|
@ -17,7 +17,7 @@ describe("test the execute script action", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should handle a null value", async () => {
|
it("should handle a null value", async () => {
|
||||||
const res = await setup.runStep(setup.actions.EXECUTE_SCRIPT.stepId, {
|
const res = await runStep(config, actions.EXECUTE_SCRIPT.stepId, {
|
||||||
code: null,
|
code: null,
|
||||||
})
|
})
|
||||||
expect(res.response.message).toEqual("Invalid inputs")
|
expect(res.response.message).toEqual("Invalid inputs")
|
||||||
|
@ -25,8 +25,9 @@ describe("test the execute script action", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should be able to get a value from context", async () => {
|
it("should be able to get a value from context", async () => {
|
||||||
const res = await setup.runStep(
|
const res = await runStep(
|
||||||
setup.actions.EXECUTE_SCRIPT.stepId,
|
config,
|
||||||
|
actions.EXECUTE_SCRIPT.stepId,
|
||||||
{
|
{
|
||||||
code: "return steps.map(d => d.value)",
|
code: "return steps.map(d => d.value)",
|
||||||
},
|
},
|
||||||
|
@ -40,7 +41,7 @@ describe("test the execute script action", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should be able to handle an error gracefully", async () => {
|
it("should be able to handle an error gracefully", async () => {
|
||||||
const res = await setup.runStep(setup.actions.EXECUTE_SCRIPT.stepId, {
|
const res = await runStep(config, actions.EXECUTE_SCRIPT.stepId, {
|
||||||
code: "return something.map(x => x.name)",
|
code: "return something.map(x => x.name)",
|
||||||
})
|
})
|
||||||
expect(res.response).toEqual("ReferenceError: something is not defined")
|
expect(res.response).toEqual("ReferenceError: something is not defined")
|
|
@ -2,13 +2,19 @@ import * as setup from "./utilities"
|
||||||
import { FilterConditions } from "../steps/filter"
|
import { FilterConditions } from "../steps/filter"
|
||||||
|
|
||||||
describe("test the filter logic", () => {
|
describe("test the filter logic", () => {
|
||||||
|
const config = setup.getConfig()
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
await config.init()
|
||||||
|
})
|
||||||
|
|
||||||
async function checkFilter(
|
async function checkFilter(
|
||||||
field: any,
|
field: any,
|
||||||
condition: string,
|
condition: string,
|
||||||
value: any,
|
value: any,
|
||||||
pass = true
|
pass = true
|
||||||
) {
|
) {
|
||||||
let res = await setup.runStep(setup.actions.FILTER.stepId, {
|
let res = await setup.runStep(config, setup.actions.FILTER.stepId, {
|
||||||
field,
|
field,
|
||||||
condition,
|
condition,
|
||||||
value,
|
value,
|
||||||
|
|
|
@ -16,7 +16,7 @@ describe("test the outgoing webhook action", () => {
|
||||||
|
|
||||||
it("should be able to run the action", async () => {
|
it("should be able to run the action", async () => {
|
||||||
nock("http://www.example.com/").post("/").reply(200, { foo: "bar" })
|
nock("http://www.example.com/").post("/").reply(200, { foo: "bar" })
|
||||||
const res = await runStep(actions.integromat.stepId, {
|
const res = await runStep(config, actions.integromat.stepId, {
|
||||||
url: "http://www.example.com",
|
url: "http://www.example.com",
|
||||||
})
|
})
|
||||||
expect(res.response.foo).toEqual("bar")
|
expect(res.response.foo).toEqual("bar")
|
||||||
|
@ -38,7 +38,7 @@ describe("test the outgoing webhook action", () => {
|
||||||
.post("/", payload)
|
.post("/", payload)
|
||||||
.reply(200, { foo: "bar" })
|
.reply(200, { foo: "bar" })
|
||||||
|
|
||||||
const res = await runStep(actions.integromat.stepId, {
|
const res = await runStep(config, actions.integromat.stepId, {
|
||||||
body: { value: JSON.stringify(payload) },
|
body: { value: JSON.stringify(payload) },
|
||||||
url: "http://www.example.com",
|
url: "http://www.example.com",
|
||||||
})
|
})
|
||||||
|
@ -47,7 +47,7 @@ describe("test the outgoing webhook action", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should return a 400 if the JSON payload string is malformed", async () => {
|
it("should return a 400 if the JSON payload string is malformed", async () => {
|
||||||
const res = await runStep(actions.integromat.stepId, {
|
const res = await runStep(config, actions.integromat.stepId, {
|
||||||
body: { value: "{ invalid json }" },
|
body: { value: "{ invalid json }" },
|
||||||
url: "http://www.example.com",
|
url: "http://www.example.com",
|
||||||
})
|
})
|
||||||
|
|
|
@ -16,7 +16,7 @@ describe("test the outgoing webhook action", () => {
|
||||||
|
|
||||||
it("should be able to run the action and default to 'get'", async () => {
|
it("should be able to run the action and default to 'get'", async () => {
|
||||||
nock("http://www.example.com/").get("/").reply(200, { foo: "bar" })
|
nock("http://www.example.com/").get("/").reply(200, { foo: "bar" })
|
||||||
const res = await runStep(actions.n8n.stepId, {
|
const res = await runStep(config, actions.n8n.stepId, {
|
||||||
url: "http://www.example.com",
|
url: "http://www.example.com",
|
||||||
body: {
|
body: {
|
||||||
test: "IGNORE_ME",
|
test: "IGNORE_ME",
|
||||||
|
@ -30,7 +30,7 @@ describe("test the outgoing webhook action", () => {
|
||||||
nock("http://www.example.com/")
|
nock("http://www.example.com/")
|
||||||
.post("/", { name: "Adam", age: 9 })
|
.post("/", { name: "Adam", age: 9 })
|
||||||
.reply(200)
|
.reply(200)
|
||||||
const res = await runStep(actions.n8n.stepId, {
|
const res = await runStep(config, actions.n8n.stepId, {
|
||||||
body: {
|
body: {
|
||||||
value: JSON.stringify({ name: "Adam", age: 9 }),
|
value: JSON.stringify({ name: "Adam", age: 9 }),
|
||||||
},
|
},
|
||||||
|
@ -42,7 +42,7 @@ describe("test the outgoing webhook action", () => {
|
||||||
|
|
||||||
it("should return a 400 if the JSON payload string is malformed", async () => {
|
it("should return a 400 if the JSON payload string is malformed", async () => {
|
||||||
const payload = `{ value1 1 }`
|
const payload = `{ value1 1 }`
|
||||||
const res = await runStep(actions.n8n.stepId, {
|
const res = await runStep(config, actions.n8n.stepId, {
|
||||||
value1: "ONE",
|
value1: "ONE",
|
||||||
body: {
|
body: {
|
||||||
value: payload,
|
value: payload,
|
||||||
|
@ -59,7 +59,7 @@ describe("test the outgoing webhook action", () => {
|
||||||
nock("http://www.example.com/")
|
nock("http://www.example.com/")
|
||||||
.head("/", body => body === "")
|
.head("/", body => body === "")
|
||||||
.reply(200)
|
.reply(200)
|
||||||
const res = await runStep(actions.n8n.stepId, {
|
const res = await runStep(config, actions.n8n.stepId, {
|
||||||
url: "http://www.example.com",
|
url: "http://www.example.com",
|
||||||
method: "HEAD",
|
method: "HEAD",
|
||||||
body: {
|
body: {
|
||||||
|
|
|
@ -62,13 +62,13 @@ describe("test the openai action", () => {
|
||||||
afterAll(_afterAll)
|
afterAll(_afterAll)
|
||||||
|
|
||||||
it("should be able to receive a response from ChatGPT given a prompt", async () => {
|
it("should be able to receive a response from ChatGPT given a prompt", async () => {
|
||||||
const res = await runStep("OPENAI", { prompt: OPENAI_PROMPT })
|
const res = await runStep(config, "OPENAI", { prompt: OPENAI_PROMPT })
|
||||||
expect(res.response).toEqual("This is a test")
|
expect(res.response).toEqual("This is a test")
|
||||||
expect(res.success).toBeTruthy()
|
expect(res.success).toBeTruthy()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should present the correct error message when a prompt is not provided", async () => {
|
it("should present the correct error message when a prompt is not provided", async () => {
|
||||||
const res = await runStep("OPENAI", { prompt: null })
|
const res = await runStep(config, "OPENAI", { prompt: null })
|
||||||
expect(res.response).toEqual(
|
expect(res.response).toEqual(
|
||||||
"Budibase OpenAI Automation Failed: No prompt supplied"
|
"Budibase OpenAI Automation Failed: No prompt supplied"
|
||||||
)
|
)
|
||||||
|
@ -91,7 +91,7 @@ describe("test the openai action", () => {
|
||||||
} as any)
|
} as any)
|
||||||
)
|
)
|
||||||
|
|
||||||
const res = await runStep("OPENAI", {
|
const res = await runStep(config, "OPENAI", {
|
||||||
prompt: OPENAI_PROMPT,
|
prompt: OPENAI_PROMPT,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ describe("test the openai action", () => {
|
||||||
jest.spyOn(pro.features, "isAICustomConfigsEnabled").mockResolvedValue(true)
|
jest.spyOn(pro.features, "isAICustomConfigsEnabled").mockResolvedValue(true)
|
||||||
|
|
||||||
const prompt = "What is the meaning of life?"
|
const prompt = "What is the meaning of life?"
|
||||||
await runStep("OPENAI", {
|
await runStep(config, "OPENAI", {
|
||||||
model: "gpt-4o-mini",
|
model: "gpt-4o-mini",
|
||||||
prompt,
|
prompt,
|
||||||
})
|
})
|
||||||
|
|
|
@ -18,7 +18,7 @@ describe("test the outgoing webhook action", () => {
|
||||||
nock("http://www.example.com")
|
nock("http://www.example.com")
|
||||||
.post("/", { a: 1 })
|
.post("/", { a: 1 })
|
||||||
.reply(200, { foo: "bar" })
|
.reply(200, { foo: "bar" })
|
||||||
const res = await runStep(actions.OUTGOING_WEBHOOK.stepId, {
|
const res = await runStep(config, actions.OUTGOING_WEBHOOK.stepId, {
|
||||||
requestMethod: "POST",
|
requestMethod: "POST",
|
||||||
url: "www.example.com",
|
url: "www.example.com",
|
||||||
requestBody: JSON.stringify({ a: 1 }),
|
requestBody: JSON.stringify({ a: 1 }),
|
||||||
|
@ -28,7 +28,7 @@ describe("test the outgoing webhook action", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should return an error if something goes wrong in fetch", async () => {
|
it("should return an error if something goes wrong in fetch", async () => {
|
||||||
const res = await runStep(actions.OUTGOING_WEBHOOK.stepId, {
|
const res = await runStep(config, actions.OUTGOING_WEBHOOK.stepId, {
|
||||||
requestMethod: "GET",
|
requestMethod: "GET",
|
||||||
url: "www.invalid.com",
|
url: "www.invalid.com",
|
||||||
})
|
})
|
||||||
|
|
|
@ -33,7 +33,11 @@ describe("Test a query step automation", () => {
|
||||||
sortOrder: "ascending",
|
sortOrder: "ascending",
|
||||||
limit: 10,
|
limit: 10,
|
||||||
}
|
}
|
||||||
const res = await setup.runStep(setup.actions.QUERY_ROWS.stepId, inputs)
|
const res = await setup.runStep(
|
||||||
|
config,
|
||||||
|
setup.actions.QUERY_ROWS.stepId,
|
||||||
|
inputs
|
||||||
|
)
|
||||||
expect(res.success).toBe(true)
|
expect(res.success).toBe(true)
|
||||||
expect(res.rows).toBeDefined()
|
expect(res.rows).toBeDefined()
|
||||||
expect(res.rows.length).toBe(2)
|
expect(res.rows.length).toBe(2)
|
||||||
|
@ -48,7 +52,11 @@ describe("Test a query step automation", () => {
|
||||||
sortOrder: "ascending",
|
sortOrder: "ascending",
|
||||||
limit: 10,
|
limit: 10,
|
||||||
}
|
}
|
||||||
const res = await setup.runStep(setup.actions.QUERY_ROWS.stepId, inputs)
|
const res = await setup.runStep(
|
||||||
|
config,
|
||||||
|
setup.actions.QUERY_ROWS.stepId,
|
||||||
|
inputs
|
||||||
|
)
|
||||||
expect(res.success).toBe(true)
|
expect(res.success).toBe(true)
|
||||||
expect(res.rows).toBeDefined()
|
expect(res.rows).toBeDefined()
|
||||||
expect(res.rows.length).toBe(2)
|
expect(res.rows.length).toBe(2)
|
||||||
|
@ -65,7 +73,11 @@ describe("Test a query step automation", () => {
|
||||||
limit: 10,
|
limit: 10,
|
||||||
onEmptyFilter: "none",
|
onEmptyFilter: "none",
|
||||||
}
|
}
|
||||||
const res = await setup.runStep(setup.actions.QUERY_ROWS.stepId, inputs)
|
const res = await setup.runStep(
|
||||||
|
config,
|
||||||
|
setup.actions.QUERY_ROWS.stepId,
|
||||||
|
inputs
|
||||||
|
)
|
||||||
expect(res.success).toBe(false)
|
expect(res.success).toBe(false)
|
||||||
expect(res.rows).toBeDefined()
|
expect(res.rows).toBeDefined()
|
||||||
expect(res.rows.length).toBe(0)
|
expect(res.rows.length).toBe(0)
|
||||||
|
@ -85,7 +97,11 @@ describe("Test a query step automation", () => {
|
||||||
sortOrder: "ascending",
|
sortOrder: "ascending",
|
||||||
limit: 10,
|
limit: 10,
|
||||||
}
|
}
|
||||||
const res = await setup.runStep(setup.actions.QUERY_ROWS.stepId, inputs)
|
const res = await setup.runStep(
|
||||||
|
config,
|
||||||
|
setup.actions.QUERY_ROWS.stepId,
|
||||||
|
inputs
|
||||||
|
)
|
||||||
expect(res.success).toBe(false)
|
expect(res.success).toBe(false)
|
||||||
expect(res.rows).toBeDefined()
|
expect(res.rows).toBeDefined()
|
||||||
expect(res.rows.length).toBe(0)
|
expect(res.rows.length).toBe(0)
|
||||||
|
@ -100,7 +116,11 @@ describe("Test a query step automation", () => {
|
||||||
sortOrder: "ascending",
|
sortOrder: "ascending",
|
||||||
limit: 10,
|
limit: 10,
|
||||||
}
|
}
|
||||||
const res = await setup.runStep(setup.actions.QUERY_ROWS.stepId, inputs)
|
const res = await setup.runStep(
|
||||||
|
config,
|
||||||
|
setup.actions.QUERY_ROWS.stepId,
|
||||||
|
inputs
|
||||||
|
)
|
||||||
expect(res.success).toBe(true)
|
expect(res.success).toBe(true)
|
||||||
expect(res.rows).toBeDefined()
|
expect(res.rows).toBeDefined()
|
||||||
expect(res.rows.length).toBe(2)
|
expect(res.rows.length).toBe(2)
|
||||||
|
|
|
@ -18,7 +18,7 @@ function generateResponse(to: string, from: string) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const setup = require("./utilities")
|
import * as setup from "./utilities"
|
||||||
|
|
||||||
describe("test the outgoing webhook action", () => {
|
describe("test the outgoing webhook action", () => {
|
||||||
let inputs
|
let inputs
|
||||||
|
@ -58,6 +58,7 @@ describe("test the outgoing webhook action", () => {
|
||||||
}
|
}
|
||||||
let resp = generateResponse(inputs.to, inputs.from)
|
let resp = generateResponse(inputs.to, inputs.from)
|
||||||
const res = await setup.runStep(
|
const res = await setup.runStep(
|
||||||
|
config,
|
||||||
setup.actions.SEND_EMAIL_SMTP.stepId,
|
setup.actions.SEND_EMAIL_SMTP.stepId,
|
||||||
inputs
|
inputs
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
const setup = require("./utilities")
|
import { getConfig, afterAll as _afterAll, runStep, actions } from "./utilities"
|
||||||
|
|
||||||
describe("test the server log action", () => {
|
describe("test the server log action", () => {
|
||||||
let config = setup.getConfig()
|
let config = getConfig()
|
||||||
let inputs
|
let inputs: any
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await config.init()
|
await config.init()
|
||||||
|
@ -10,10 +10,10 @@ describe("test the server log action", () => {
|
||||||
text: "log message",
|
text: "log message",
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
afterAll(setup.afterAll)
|
afterAll(_afterAll)
|
||||||
|
|
||||||
it("should be able to log the text", async () => {
|
it("should be able to log the text", async () => {
|
||||||
let res = await setup.runStep(setup.actions.SERVER_LOG.stepId, inputs)
|
let res = await runStep(config, actions.SERVER_LOG.stepId, inputs)
|
||||||
expect(res.message).toEqual(`App ${config.getAppId()} - ${inputs.text}`)
|
expect(res.message).toEqual(`App ${config.getAppId()} - ${inputs.text}`)
|
||||||
expect(res.success).toEqual(true)
|
expect(res.success).toEqual(true)
|
||||||
})
|
})
|
|
@ -29,6 +29,7 @@ describe("Test triggering an automation from another automation", () => {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
const res = await setup.runStep(
|
const res = await setup.runStep(
|
||||||
|
config,
|
||||||
setup.actions.TRIGGER_AUTOMATION_RUN.stepId,
|
setup.actions.TRIGGER_AUTOMATION_RUN.stepId,
|
||||||
inputs
|
inputs
|
||||||
)
|
)
|
||||||
|
@ -44,6 +45,7 @@ describe("Test triggering an automation from another automation", () => {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
const res = await setup.runStep(
|
const res = await setup.runStep(
|
||||||
|
config,
|
||||||
setup.actions.TRIGGER_AUTOMATION_RUN.stepId,
|
setup.actions.TRIGGER_AUTOMATION_RUN.stepId,
|
||||||
inputs
|
inputs
|
||||||
)
|
)
|
||||||
|
|
|
@ -34,7 +34,11 @@ describe("test the update row action", () => {
|
||||||
afterAll(setup.afterAll)
|
afterAll(setup.afterAll)
|
||||||
|
|
||||||
it("should be able to run the action", async () => {
|
it("should be able to run the action", async () => {
|
||||||
const res = await setup.runStep(setup.actions.UPDATE_ROW.stepId, inputs)
|
const res = await setup.runStep(
|
||||||
|
config,
|
||||||
|
setup.actions.UPDATE_ROW.stepId,
|
||||||
|
inputs
|
||||||
|
)
|
||||||
expect(res.success).toEqual(true)
|
expect(res.success).toEqual(true)
|
||||||
const updatedRow = await config.api.row.get(table._id!, res.id)
|
const updatedRow = await config.api.row.get(table._id!, res.id)
|
||||||
expect(updatedRow.name).toEqual("Updated name")
|
expect(updatedRow.name).toEqual("Updated name")
|
||||||
|
@ -42,12 +46,12 @@ describe("test the update row action", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should check invalid inputs return an error", async () => {
|
it("should check invalid inputs return an error", async () => {
|
||||||
const res = await setup.runStep(setup.actions.UPDATE_ROW.stepId, {})
|
const res = await setup.runStep(config, setup.actions.UPDATE_ROW.stepId, {})
|
||||||
expect(res.success).toEqual(false)
|
expect(res.success).toEqual(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should return an error when table doesn't exist", async () => {
|
it("should return an error when table doesn't exist", async () => {
|
||||||
const res = await setup.runStep(setup.actions.UPDATE_ROW.stepId, {
|
const res = await setup.runStep(config, setup.actions.UPDATE_ROW.stepId, {
|
||||||
row: { _id: "invalid" },
|
row: { _id: "invalid" },
|
||||||
rowId: "invalid",
|
rowId: "invalid",
|
||||||
})
|
})
|
||||||
|
@ -90,7 +94,10 @@ describe("test the update row action", () => {
|
||||||
expect(getResp.user1[0]._id).toEqual(user1._id)
|
expect(getResp.user1[0]._id).toEqual(user1._id)
|
||||||
expect(getResp.user2[0]._id).toEqual(user2._id)
|
expect(getResp.user2[0]._id).toEqual(user2._id)
|
||||||
|
|
||||||
let stepResp = await setup.runStep(setup.actions.UPDATE_ROW.stepId, {
|
let stepResp = await setup.runStep(
|
||||||
|
config,
|
||||||
|
setup.actions.UPDATE_ROW.stepId,
|
||||||
|
{
|
||||||
rowId: row._id,
|
rowId: row._id,
|
||||||
row: {
|
row: {
|
||||||
_id: row._id,
|
_id: row._id,
|
||||||
|
@ -99,7 +106,8 @@ describe("test the update row action", () => {
|
||||||
user1: [user2._id],
|
user1: [user2._id],
|
||||||
user2: "",
|
user2: "",
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
)
|
||||||
expect(stepResp.success).toEqual(true)
|
expect(stepResp.success).toEqual(true)
|
||||||
|
|
||||||
getResp = await config.api.row.get(table._id!, row._id!)
|
getResp = await config.api.row.get(table._id!, row._id!)
|
||||||
|
@ -143,7 +151,10 @@ describe("test the update row action", () => {
|
||||||
expect(getResp.user1[0]._id).toEqual(user1._id)
|
expect(getResp.user1[0]._id).toEqual(user1._id)
|
||||||
expect(getResp.user2[0]._id).toEqual(user2._id)
|
expect(getResp.user2[0]._id).toEqual(user2._id)
|
||||||
|
|
||||||
let stepResp = await setup.runStep(setup.actions.UPDATE_ROW.stepId, {
|
let stepResp = await setup.runStep(
|
||||||
|
config,
|
||||||
|
setup.actions.UPDATE_ROW.stepId,
|
||||||
|
{
|
||||||
rowId: row._id,
|
rowId: row._id,
|
||||||
row: {
|
row: {
|
||||||
_id: row._id,
|
_id: row._id,
|
||||||
|
@ -159,7 +170,8 @@ describe("test the update row action", () => {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
)
|
||||||
expect(stepResp.success).toEqual(true)
|
expect(stepResp.success).toEqual(true)
|
||||||
|
|
||||||
getResp = await config.api.row.get(table._id!, row._id!)
|
getResp = await config.api.row.get(table._id!, row._id!)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import TestConfig from "../../../tests/utilities/TestConfiguration"
|
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
||||||
import { context } from "@budibase/backend-core"
|
import { context } from "@budibase/backend-core"
|
||||||
import { BUILTIN_ACTION_DEFINITIONS, getAction } from "../../actions"
|
import { BUILTIN_ACTION_DEFINITIONS, getAction } from "../../actions"
|
||||||
import emitter from "../../../events/index"
|
import emitter from "../../../events/index"
|
||||||
|
@ -6,11 +6,11 @@ import env from "../../../environment"
|
||||||
import { AutomationActionStepId, Datasource } from "@budibase/types"
|
import { AutomationActionStepId, Datasource } from "@budibase/types"
|
||||||
import { Knex } from "knex"
|
import { Knex } from "knex"
|
||||||
|
|
||||||
let config: TestConfig
|
let config: TestConfiguration
|
||||||
|
|
||||||
export function getConfig(): TestConfig {
|
export function getConfig(): TestConfiguration {
|
||||||
if (!config) {
|
if (!config) {
|
||||||
config = new TestConfig(true)
|
config = new TestConfiguration(true)
|
||||||
}
|
}
|
||||||
return config
|
return config
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,12 @@ export async function runInProd(fn: any) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function runStep(stepId: string, inputs: any, stepContext?: any) {
|
export async function runStep(
|
||||||
|
config: TestConfiguration,
|
||||||
|
stepId: string,
|
||||||
|
inputs: any,
|
||||||
|
stepContext?: any
|
||||||
|
) {
|
||||||
async function run() {
|
async function run() {
|
||||||
let step = await getAction(stepId as AutomationActionStepId)
|
let step = await getAction(stepId as AutomationActionStepId)
|
||||||
expect(step).toBeDefined()
|
expect(step).toBeDefined()
|
||||||
|
@ -49,7 +54,7 @@ export async function runStep(stepId: string, inputs: any, stepContext?: any) {
|
||||||
emitter,
|
emitter,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if (config?.appId) {
|
if (config.appId) {
|
||||||
return context.doInContext(config?.appId, async () => {
|
return context.doInContext(config?.appId, async () => {
|
||||||
return run()
|
return run()
|
||||||
})
|
})
|
||||||
|
@ -59,7 +64,7 @@ export async function runStep(stepId: string, inputs: any, stepContext?: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function saveTestQuery(
|
export async function saveTestQuery(
|
||||||
config: TestConfig,
|
config: TestConfiguration,
|
||||||
client: Knex,
|
client: Knex,
|
||||||
tableName: string,
|
tableName: string,
|
||||||
datasource: Datasource
|
datasource: Datasource
|
||||||
|
|
|
@ -16,7 +16,7 @@ describe("test the outgoing webhook action", () => {
|
||||||
|
|
||||||
it("should be able to run the action", async () => {
|
it("should be able to run the action", async () => {
|
||||||
nock("http://www.example.com/").post("/").reply(200, { foo: "bar" })
|
nock("http://www.example.com/").post("/").reply(200, { foo: "bar" })
|
||||||
const res = await runStep(actions.zapier.stepId, {
|
const res = await runStep(config, actions.zapier.stepId, {
|
||||||
url: "http://www.example.com",
|
url: "http://www.example.com",
|
||||||
})
|
})
|
||||||
expect(res.response.foo).toEqual("bar")
|
expect(res.response.foo).toEqual("bar")
|
||||||
|
@ -38,7 +38,7 @@ describe("test the outgoing webhook action", () => {
|
||||||
.post("/", { ...payload, platform: "budibase" })
|
.post("/", { ...payload, platform: "budibase" })
|
||||||
.reply(200, { foo: "bar" })
|
.reply(200, { foo: "bar" })
|
||||||
|
|
||||||
const res = await runStep(actions.zapier.stepId, {
|
const res = await runStep(config, actions.zapier.stepId, {
|
||||||
body: { value: JSON.stringify(payload) },
|
body: { value: JSON.stringify(payload) },
|
||||||
url: "http://www.example.com",
|
url: "http://www.example.com",
|
||||||
})
|
})
|
||||||
|
@ -47,7 +47,7 @@ describe("test the outgoing webhook action", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should return a 400 if the JSON payload string is malformed", async () => {
|
it("should return a 400 if the JSON payload string is malformed", async () => {
|
||||||
const res = await runStep(actions.zapier.stepId, {
|
const res = await runStep(config, actions.zapier.stepId, {
|
||||||
body: { value: "{ invalid json }" },
|
body: { value: "{ invalid json }" },
|
||||||
url: "http://www.example.com",
|
url: "http://www.example.com",
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue