sync automation webhooks tests

This commit is contained in:
Peter Clement 2023-05-23 15:55:52 +01:00
parent 986348f511
commit 8d3a5307ed
1 changed files with 33 additions and 11 deletions

View File

@ -1,11 +1,13 @@
const setup = require("./utilities")
const { checkBuilderEndpoint } = require("./utilities/TestFunctions")
const { basicWebhook, basicAutomation } = setup.structures
import { Webhook } from "@budibase/types"
import * as setup from "./utilities"
import { checkBuilderEndpoint } from "./utilities/TestFunctions"
import { mocks } from "@budibase/backend-core/tests"
const { basicWebhook, basicAutomation, collectAutomation } = setup.structures
describe("/webhooks", () => {
let request = setup.getRequest()
let config = setup.getConfig()
let webhook
let webhook: Webhook
afterAll(setup.afterAll)
@ -13,10 +15,11 @@ describe("/webhooks", () => {
config.modeSelf()
await config.init()
const autoConfig = basicAutomation()
autoConfig.definition.trigger = {
schema: { outputs: { properties: {} } },
inputs: {},
autoConfig.definition.trigger.schema = {
outputs: { properties: {} },
inputs: { properties: {} },
}
autoConfig.definition.trigger.inputs = {}
await config.createAutomation(autoConfig)
webhook = await config.createWebhook()
}
@ -97,7 +100,7 @@ describe("/webhooks", () => {
const res = await request
.post(`/api/webhooks/schema/${config.getAppId()}/${webhook._id}`)
.send({
a: 1
a: 1,
})
.set(config.defaultHeaders())
.expect("Content-Type", /json/)
@ -112,7 +115,7 @@ describe("/webhooks", () => {
expect(fetch.body[0]).toBeDefined()
expect(fetch.body[0].bodySchema).toEqual({
properties: {
a: { type: "integer" }
a: { type: "integer" },
},
type: "object",
})
@ -131,4 +134,23 @@ describe("/webhooks", () => {
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])
})
})