From dc7002270874327719384e05684a554c2d2e918f Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Wed, 16 Nov 2022 13:06:30 +0000 Subject: [PATCH] Test fixes --- packages/backend-core/tests/jestSetup.ts | 3 +++ packages/backend-core/tests/utilities/mocks/fetch.ts | 10 ++++++++-- .../backend-core/tests/utilities/structures/koa.ts | 3 ++- packages/worker/src/api/index.ts | 4 ++-- packages/worker/src/tests/jestSetup.ts | 3 +++ 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/packages/backend-core/tests/jestSetup.ts b/packages/backend-core/tests/jestSetup.ts index 30b645d0e5..7870a721aa 100644 --- a/packages/backend-core/tests/jestSetup.ts +++ b/packages/backend-core/tests/jestSetup.ts @@ -1,6 +1,9 @@ import env from "../src/environment" import { mocks } from "./utilities" +// must explicitly enable fetch mock +mocks.fetch.enable() + // mock all dates to 2020-01-01T00:00:00.000Z // use tk.reset() to use real dates in individual tests import tk from "timekeeper" diff --git a/packages/backend-core/tests/utilities/mocks/fetch.ts b/packages/backend-core/tests/utilities/mocks/fetch.ts index 573b47db9f..eeb0ccda45 100644 --- a/packages/backend-core/tests/utilities/mocks/fetch.ts +++ b/packages/backend-core/tests/utilities/mocks/fetch.ts @@ -1,4 +1,10 @@ const mockFetch = jest.fn() -jest.mock("node-fetch", () => mockFetch) -export default mockFetch +const enable = () => { + jest.mock("node-fetch", () => mockFetch) +} + +export default { + ...mockFetch, + enable, +} diff --git a/packages/backend-core/tests/utilities/structures/koa.ts b/packages/backend-core/tests/utilities/structures/koa.ts index 7084c90360..a33dca1546 100644 --- a/packages/backend-core/tests/utilities/structures/koa.ts +++ b/packages/backend-core/tests/utilities/structures/koa.ts @@ -1,10 +1,11 @@ -import { createMockContext } from "@shopify/jest-koa-mocks" +import { createMockContext, createMockCookies } from "@shopify/jest-koa-mocks" import { BBContext } from "@budibase/types" export const newContext = (): BBContext => { const ctx = createMockContext() return { ...ctx, + cookies: createMockCookies(), request: { ...ctx.request, body: {}, diff --git a/packages/worker/src/api/index.ts b/packages/worker/src/api/index.ts index 28fbbdb4b5..9a32792691 100644 --- a/packages/worker/src/api/index.ts +++ b/packages/worker/src/api/index.ts @@ -45,11 +45,11 @@ const PUBLIC_ENDPOINTS = [ method: "POST", }, { - route: "api/system/environment", + route: "/api/system/environment", method: "GET", }, { - route: "api/system/status", + route: "/api/system/status", method: "GET", }, // TODO: This should be an internal api diff --git a/packages/worker/src/tests/jestSetup.ts b/packages/worker/src/tests/jestSetup.ts index 4cbc91eaf8..fee704ae45 100644 --- a/packages/worker/src/tests/jestSetup.ts +++ b/packages/worker/src/tests/jestSetup.ts @@ -14,6 +14,9 @@ env._set("DISABLE_ACCOUNT_PORTAL", false) import { mocks } from "@budibase/backend-core/tests" +// must explicitly enable fetch mock +mocks.fetch.enable() + // mock all dates to 2020-01-01T00:00:00.000Z // use tk.reset() to use real dates in individual tests const tk = require("timekeeper")