diff --git a/packages/server/src/automations/tests/outgoingWebhook.spec.js b/packages/server/src/automations/tests/outgoingWebhook.spec.js deleted file mode 100644 index 06fe2e0a38..0000000000 --- a/packages/server/src/automations/tests/outgoingWebhook.spec.js +++ /dev/null @@ -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) - }) -}) diff --git a/packages/server/src/automations/tests/outgoingWebhook.spec.ts b/packages/server/src/automations/tests/outgoingWebhook.spec.ts new file mode 100644 index 0000000000..0e26927c55 --- /dev/null +++ b/packages/server/src/automations/tests/outgoingWebhook.spec.ts @@ -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) + }) +})