Fix n8n.spec.ts's reliance on the node-fetch mock.
This commit is contained in:
parent
3657067337
commit
e530400f46
|
@ -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,31 +10,33 @@ describe("test the outgoing webhook action", () => {
|
||||||
|
|
||||||
afterAll()
|
afterAll()
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
nock.cleanAll()
|
||||||
|
})
|
||||||
|
|
||||||
it("should be able to run the action and default to 'get'", async () => {
|
it("should be able to run the action and default to 'get'", async () => {
|
||||||
|
nock("http://www.example.com/").get("/").reply(200, { foo: "bar" })
|
||||||
const res = await runStep(actions.n8n.stepId, {
|
const res = await runStep(actions.n8n.stepId, {
|
||||||
url: "http://www.example.com",
|
url: "http://www.example.com",
|
||||||
body: {
|
body: {
|
||||||
test: "IGNORE_ME",
|
test: "IGNORE_ME",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
expect(res.response.url).toEqual("http://www.example.com")
|
expect(res.response.foo).toEqual("bar")
|
||||||
expect(res.response.method).toEqual("GET")
|
|
||||||
expect(res.response.body).toBeUndefined()
|
|
||||||
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 = `{ "name": "Adam", "age": 9 }`
|
nock("http://www.example.com/")
|
||||||
|
.post("/", { name: "Adam", age: 9 })
|
||||||
|
.reply(200)
|
||||||
const res = await runStep(actions.n8n.stepId, {
|
const res = await runStep(actions.n8n.stepId, {
|
||||||
body: {
|
body: {
|
||||||
value: payload,
|
value: JSON.stringify({ name: "Adam", age: 9 }),
|
||||||
},
|
},
|
||||||
method: "POST",
|
method: "POST",
|
||||||
url: "http://www.example.com",
|
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(`{"name":"Adam","age":9}`)
|
|
||||||
expect(res.success).toEqual(true)
|
expect(res.success).toEqual(true)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -53,6 +56,9 @@ describe("test the outgoing webhook action", () => {
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should not append the body if the method is HEAD", async () => {
|
it("should not append the body if the method is HEAD", async () => {
|
||||||
|
nock("http://www.example.com/")
|
||||||
|
.head("/", body => body === "")
|
||||||
|
.reply(200)
|
||||||
const res = await runStep(actions.n8n.stepId, {
|
const res = await runStep(actions.n8n.stepId, {
|
||||||
url: "http://www.example.com",
|
url: "http://www.example.com",
|
||||||
method: "HEAD",
|
method: "HEAD",
|
||||||
|
@ -60,9 +66,6 @@ describe("test the outgoing webhook action", () => {
|
||||||
test: "IGNORE_ME",
|
test: "IGNORE_ME",
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
expect(res.response.url).toEqual("http://www.example.com")
|
|
||||||
expect(res.response.method).toEqual("HEAD")
|
|
||||||
expect(res.response.body).toBeUndefined()
|
|
||||||
expect(res.success).toEqual(true)
|
expect(res.success).toEqual(true)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import env from "../environment"
|
import env from "../environment"
|
||||||
import { env as coreEnv, timers } from "@budibase/backend-core"
|
import { env as coreEnv, timers } from "@budibase/backend-core"
|
||||||
import { testContainerUtils } from "@budibase/backend-core/tests"
|
import { testContainerUtils } from "@budibase/backend-core/tests"
|
||||||
|
import nock from "nock"
|
||||||
|
|
||||||
if (!process.env.CI) {
|
if (!process.env.CI) {
|
||||||
// set a longer timeout in dev for debugging 100 seconds
|
// set a longer timeout in dev for debugging 100 seconds
|
||||||
|
@ -9,6 +10,15 @@ if (!process.env.CI) {
|
||||||
jest.setTimeout(30 * 1000)
|
jest.setTimeout(30 * 1000)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nock.disableNetConnect()
|
||||||
|
nock.enableNetConnect(host => {
|
||||||
|
return (
|
||||||
|
host.includes("localhost") ||
|
||||||
|
host.includes("127.0.0.1") ||
|
||||||
|
host.includes("::1")
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
testContainerUtils.setupEnv(env, coreEnv)
|
testContainerUtils.setupEnv(env, coreEnv)
|
||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
|
|
Loading…
Reference in New Issue