From 6817d6cf462dba0e6bef3a781d80a0c91645e993 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 12 Jan 2022 11:50:14 +0000 Subject: [PATCH] Fixing test mocking. --- .../src/middleware/tests/currentapp.spec.js | 72 +++++++++---------- 1 file changed, 33 insertions(+), 39 deletions(-) diff --git a/packages/server/src/middleware/tests/currentapp.spec.js b/packages/server/src/middleware/tests/currentapp.spec.js index 893a508620..27c88f3b48 100644 --- a/packages/server/src/middleware/tests/currentapp.spec.js +++ b/packages/server/src/middleware/tests/currentapp.spec.js @@ -32,34 +32,30 @@ function mockAuthWithNoCookie() { }, }, })) - jest.mock("@budibase/backend-core", () => ({ - utils: { - getAppId: jest.fn(), - setCookie: jest.fn(), - getCookie: jest.fn(), - }, - constants: { - Cookies: {}, - }, + jest.mock("@budibase/backend-core/utils", () => ({ + getAppId: jest.fn(), + setCookie: jest.fn(), + getCookie: jest.fn(), + })) + jest.mock("@budibase/backend-core/constants", () => ({ + Cookies: {}, })) } function mockAuthWithCookie() { jest.resetModules() mockWorker() - jest.mock("@budibase/backend-core", () => ({ - utils: { - getAppId: () => { - return "app_test" - }, - setCookie: jest.fn(), - getCookie: () => ({appId: "app_different", roleId: "PUBLIC"}), + jest.mock("@budibase/backend-core/utils", () => ({ + getAppId: () => { + return "app_test" }, - constants: { - Cookies: { - Auth: "auth", - CurrentApp: "currentapp", - }, + setCookie: jest.fn(), + getCookie: () => ({appId: "app_different", roleId: "PUBLIC"}), + })) + jest.mock("@budibase/backend-core/constants", () => ({ + Cookies: { + Auth: "auth", + CurrentApp: "currentapp", }, })) } @@ -140,32 +136,30 @@ describe("Current app middleware", () => { it("should perform correct when no cookie exists", async () => { mockReset() - jest.mock("@budibase/backend-core", () => ({ - utils: { - getAppId: () => { - return "app_test" - }, - setCookie: jest.fn(), - getCookie: jest.fn(), - }, - constants: { - Cookies: {}, + jest.mock("@budibase/backend-core/utils", () => ({ + getAppId: () => { + return "app_test" }, + setCookie: jest.fn(), + getCookie: jest.fn(), + })) + jest.mock("@budibase/backend-core/constants", () => ({ + Cookies: {}, })) await checkExpected(true) }) it("lastly check what occurs when cookie doesn't need updated", async () => { mockReset() - jest.mock("@budibase/backend-core", () => ({ - utils: { - getAppId: () => { - return "app_test" - }, - setCookie: jest.fn(), - getCookie: () => ({appId: "app_test", roleId: "PUBLIC"}), + jest.mock("@budibase/backend-core/utils", () => ({ + getAppId: () => { + return "app_test" }, - constants: { Cookies: {} }, + setCookie: jest.fn(), + getCookie: () => ({appId: "app_test", roleId: "PUBLIC"}), + })) + jest.mock("@budibase/backend-core/constants", () => ({ + Cookies: {}, })) await checkExpected(false) })