sync automation webhooks tests
This commit is contained in:
parent
986348f511
commit
8d3a5307ed
|
@ -1,11 +1,13 @@
|
||||||
const setup = require("./utilities")
|
import { Webhook } from "@budibase/types"
|
||||||
const { checkBuilderEndpoint } = require("./utilities/TestFunctions")
|
import * as setup from "./utilities"
|
||||||
const { basicWebhook, basicAutomation } = setup.structures
|
import { checkBuilderEndpoint } from "./utilities/TestFunctions"
|
||||||
|
import { mocks } from "@budibase/backend-core/tests"
|
||||||
|
const { basicWebhook, basicAutomation, collectAutomation } = setup.structures
|
||||||
|
|
||||||
describe("/webhooks", () => {
|
describe("/webhooks", () => {
|
||||||
let request = setup.getRequest()
|
let request = setup.getRequest()
|
||||||
let config = setup.getConfig()
|
let config = setup.getConfig()
|
||||||
let webhook
|
let webhook: Webhook
|
||||||
|
|
||||||
afterAll(setup.afterAll)
|
afterAll(setup.afterAll)
|
||||||
|
|
||||||
|
@ -13,10 +15,11 @@ describe("/webhooks", () => {
|
||||||
config.modeSelf()
|
config.modeSelf()
|
||||||
await config.init()
|
await config.init()
|
||||||
const autoConfig = basicAutomation()
|
const autoConfig = basicAutomation()
|
||||||
autoConfig.definition.trigger = {
|
autoConfig.definition.trigger.schema = {
|
||||||
schema: { outputs: { properties: {} } },
|
outputs: { properties: {} },
|
||||||
inputs: {},
|
inputs: { properties: {} },
|
||||||
}
|
}
|
||||||
|
autoConfig.definition.trigger.inputs = {}
|
||||||
await config.createAutomation(autoConfig)
|
await config.createAutomation(autoConfig)
|
||||||
webhook = await config.createWebhook()
|
webhook = await config.createWebhook()
|
||||||
}
|
}
|
||||||
|
@ -97,7 +100,7 @@ describe("/webhooks", () => {
|
||||||
const res = await request
|
const res = await request
|
||||||
.post(`/api/webhooks/schema/${config.getAppId()}/${webhook._id}`)
|
.post(`/api/webhooks/schema/${config.getAppId()}/${webhook._id}`)
|
||||||
.send({
|
.send({
|
||||||
a: 1
|
a: 1,
|
||||||
})
|
})
|
||||||
.set(config.defaultHeaders())
|
.set(config.defaultHeaders())
|
||||||
.expect("Content-Type", /json/)
|
.expect("Content-Type", /json/)
|
||||||
|
@ -112,7 +115,7 @@ describe("/webhooks", () => {
|
||||||
expect(fetch.body[0]).toBeDefined()
|
expect(fetch.body[0]).toBeDefined()
|
||||||
expect(fetch.body[0].bodySchema).toEqual({
|
expect(fetch.body[0].bodySchema).toEqual({
|
||||||
properties: {
|
properties: {
|
||||||
a: { type: "integer" }
|
a: { type: "integer" },
|
||||||
},
|
},
|
||||||
type: "object",
|
type: "object",
|
||||||
})
|
})
|
||||||
|
@ -131,4 +134,23 @@ describe("/webhooks", () => {
|
||||||
expect(res.body.message).toBeDefined()
|
expect(res.body.message).toBeDefined()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("should trigger a synchronous webhook call ", async () => {
|
||||||
|
mocks.licenses.useSyncAutomations()
|
||||||
|
let automation = collectAutomation()
|
||||||
|
let newAutomation = await config.createAutomation(automation)
|
||||||
|
let syncWebhook = await config.createWebhook(
|
||||||
|
basicWebhook(newAutomation._id)
|
||||||
|
)
|
||||||
|
|
||||||
|
// replicate changes before checking webhook
|
||||||
|
await config.publish()
|
||||||
|
|
||||||
|
const res = await request
|
||||||
|
.post(`/api/webhooks/trigger/${config.prodAppId}/${syncWebhook._id}`)
|
||||||
|
.expect("Content-Type", /json/)
|
||||||
|
.expect(200)
|
||||||
|
expect(res.body.success).toEqual(true)
|
||||||
|
expect(res.body.value).toEqual([1, 2, 3])
|
||||||
|
})
|
||||||
})
|
})
|
Loading…
Reference in New Issue