Fix outgoingWebhook.spec.ts's reliance on the node-fetch mock.
This commit is contained in:
parent
661e1f241d
commit
6d70dd1924
|
@ -1,41 +0,0 @@
|
||||||
const setup = require("./utilities")
|
|
||||||
const fetch = require("node-fetch")
|
|
||||||
|
|
||||||
jest.mock("node-fetch")
|
|
||||||
|
|
||||||
describe("test the outgoing webhook action", () => {
|
|
||||||
let inputs
|
|
||||||
let config = setup.getConfig()
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
await config.init()
|
|
||||||
inputs = {
|
|
||||||
requestMethod: "POST",
|
|
||||||
url: "www.example.com",
|
|
||||||
requestBody: JSON.stringify({
|
|
||||||
a: 1,
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(setup.afterAll)
|
|
||||||
|
|
||||||
it("should be able to run the action", async () => {
|
|
||||||
const res = await setup.runStep(
|
|
||||||
setup.actions.OUTGOING_WEBHOOK.stepId,
|
|
||||||
inputs
|
|
||||||
)
|
|
||||||
expect(res.success).toEqual(true)
|
|
||||||
expect(res.response.url).toEqual("http://www.example.com")
|
|
||||||
expect(res.response.method).toEqual("POST")
|
|
||||||
expect(JSON.parse(res.response.body).a).toEqual(1)
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should return an error if something goes wrong in fetch", async () => {
|
|
||||||
const res = await setup.runStep(setup.actions.OUTGOING_WEBHOOK.stepId, {
|
|
||||||
requestMethod: "GET",
|
|
||||||
url: "www.invalid.com",
|
|
||||||
})
|
|
||||||
expect(res.success).toEqual(false)
|
|
||||||
})
|
|
||||||
})
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
import { getConfig, afterAll as _afterAll, runStep, actions } from "./utilities"
|
||||||
|
import nock from "nock"
|
||||||
|
|
||||||
|
describe("test the outgoing webhook action", () => {
|
||||||
|
const config = getConfig()
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
await config.init()
|
||||||
|
})
|
||||||
|
|
||||||
|
afterAll(_afterAll)
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
nock.cleanAll()
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should be able to run the action", async () => {
|
||||||
|
nock("http://www.example.com")
|
||||||
|
.post("/", { a: 1 })
|
||||||
|
.reply(200, { foo: "bar" })
|
||||||
|
const res = await runStep(actions.OUTGOING_WEBHOOK.stepId, {
|
||||||
|
requestMethod: "POST",
|
||||||
|
url: "www.example.com",
|
||||||
|
requestBody: JSON.stringify({ a: 1 }),
|
||||||
|
})
|
||||||
|
expect(res.success).toEqual(true)
|
||||||
|
expect(res.response.foo).toEqual("bar")
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should return an error if something goes wrong in fetch", async () => {
|
||||||
|
const res = await runStep(actions.OUTGOING_WEBHOOK.stepId, {
|
||||||
|
requestMethod: "GET",
|
||||||
|
url: "www.invalid.com",
|
||||||
|
})
|
||||||
|
expect(res.success).toEqual(false)
|
||||||
|
})
|
||||||
|
})
|
Loading…
Reference in New Issue