From b39875fb4b6495f816ffa270458f6f3d61f8282d Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Thu, 1 Aug 2024 12:07:01 +0100 Subject: [PATCH] Fix make.spec.ts's reliance on the node-fetch mock. --- .../server/src/automations/tests/make.spec.ts | 44 ++++++++++--------- .../src/automations/tests/zapier.spec.ts | 6 +-- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/packages/server/src/automations/tests/make.spec.ts b/packages/server/src/automations/tests/make.spec.ts index 62474ae2c0..388b197c7f 100644 --- a/packages/server/src/automations/tests/make.spec.ts +++ b/packages/server/src/automations/tests/make.spec.ts @@ -1,4 +1,5 @@ import { getConfig, afterAll, runStep, actions } from "./utilities" +import nock from "nock" describe("test the outgoing webhook action", () => { let config = getConfig() @@ -9,42 +10,45 @@ describe("test the outgoing webhook action", () => { afterAll() + beforeEach(() => { + nock.cleanAll() + }) + it("should be able to run the action", async () => { + nock("http://www.example.com/").post("/").reply(200, { foo: "bar" }) const res = await runStep(actions.integromat.stepId, { - value1: "test", url: "http://www.example.com", }) - expect(res.response.url).toEqual("http://www.example.com") - expect(res.response.method).toEqual("post") + expect(res.response.foo).toEqual("bar") expect(res.success).toEqual(true) }) 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) + .reply(200, { foo: "bar" }) + const res = await runStep(actions.integromat.stepId, { - value1: "ONE", - value2: "TWO", - value3: "THREE", - value4: "FOUR", - value5: "FIVE", - body: { - value: payload, - }, + body: { value: JSON.stringify(payload) }, url: "http://www.example.com", }) - expect(res.response.url).toEqual("http://www.example.com") - expect(res.response.method).toEqual("post") - expect(res.response.body).toEqual(payload) + expect(res.response.foo).toEqual("bar") expect(res.success).toEqual(true) }) it("should return a 400 if the JSON payload string is malformed", async () => { - const payload = `{ value1 1 }` const res = await runStep(actions.integromat.stepId, { - value1: "ONE", - body: { - value: payload, - }, + body: { value: "{ invalid json }" }, url: "http://www.example.com", }) expect(res.httpStatus).toEqual(400) diff --git a/packages/server/src/automations/tests/zapier.spec.ts b/packages/server/src/automations/tests/zapier.spec.ts index a1406e4818..a7dc7d3eae 100644 --- a/packages/server/src/automations/tests/zapier.spec.ts +++ b/packages/server/src/automations/tests/zapier.spec.ts @@ -47,12 +47,8 @@ describe("test the outgoing webhook action", () => { }) it("should return a 400 if the JSON payload string is malformed", async () => { - const payload = `{ value1 1 }` const res = await runStep(actions.zapier.stepId, { - value1: "ONE", - body: { - value: payload, - }, + body: { value: "{ invalid json }" }, url: "http://www.example.com", }) expect(res.httpStatus).toEqual(400)