Fix zapier.spec.ts's reliance on the node-fetch mock.
This commit is contained in:
parent
e530400f46
commit
f16f1fb7ba
|
@ -1,4 +1,5 @@
|
||||||
import { getConfig, afterAll, runStep, actions } from "./utilities"
|
import { getConfig, afterAll, runStep, actions } from "./utilities"
|
||||||
|
import nock from "nock"
|
||||||
|
|
||||||
describe("test the outgoing webhook action", () => {
|
describe("test the outgoing webhook action", () => {
|
||||||
let config = getConfig()
|
let config = getConfig()
|
||||||
|
@ -9,34 +10,39 @@ describe("test the outgoing webhook action", () => {
|
||||||
|
|
||||||
afterAll()
|
afterAll()
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
nock.cleanAll()
|
||||||
|
})
|
||||||
|
|
||||||
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" })
|
||||||
const res = await runStep(actions.zapier.stepId, {
|
const res = await runStep(actions.zapier.stepId, {
|
||||||
value1: "test",
|
|
||||||
url: "http://www.example.com",
|
url: "http://www.example.com",
|
||||||
})
|
})
|
||||||
expect(res.response.url).toEqual("http://www.example.com")
|
expect(res.response.foo).toEqual("bar")
|
||||||
expect(res.response.method).toEqual("post")
|
|
||||||
expect(res.success).toEqual(true)
|
expect(res.success).toEqual(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should add the payload props when a JSON string is provided", async () => {
|
it("should add the payload props when a JSON string is provided", async () => {
|
||||||
const payload = `{ "value1": 1, "value2": 2, "value3": 3, "value4": 4, "value5": 5, "name": "Adam", "age": 9 }`
|
const payload = {
|
||||||
|
value1: 1,
|
||||||
|
value2: 2,
|
||||||
|
value3: 3,
|
||||||
|
value4: 4,
|
||||||
|
value5: 5,
|
||||||
|
name: "Adam",
|
||||||
|
age: 9,
|
||||||
|
}
|
||||||
|
|
||||||
|
nock("http://www.example.com/")
|
||||||
|
.post("/", { ...payload, platform: "budibase" })
|
||||||
|
.reply(200, { foo: "bar" })
|
||||||
|
|
||||||
const res = await runStep(actions.zapier.stepId, {
|
const res = await runStep(actions.zapier.stepId, {
|
||||||
value1: "ONE",
|
body: { value: JSON.stringify(payload) },
|
||||||
value2: "TWO",
|
|
||||||
value3: "THREE",
|
|
||||||
value4: "FOUR",
|
|
||||||
value5: "FIVE",
|
|
||||||
body: {
|
|
||||||
value: payload,
|
|
||||||
},
|
|
||||||
url: "http://www.example.com",
|
url: "http://www.example.com",
|
||||||
})
|
})
|
||||||
expect(res.response.url).toEqual("http://www.example.com")
|
expect(res.response.foo).toEqual("bar")
|
||||||
expect(res.response.method).toEqual("post")
|
|
||||||
expect(res.response.body).toEqual(
|
|
||||||
`{"platform":"budibase","value1":1,"value2":2,"value3":3,"value4":4,"value5":5,"name":"Adam","age":9}`
|
|
||||||
)
|
|
||||||
expect(res.success).toEqual(true)
|
expect(res.success).toEqual(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue