diff --git a/backend/__tests__/__integration__/setup-integration-tests.ts b/backend/__tests__/__integration__/setup-integration-tests.ts index 48b3677f2b86..3ac6e9792b15 100644 --- a/backend/__tests__/__integration__/setup-integration-tests.ts +++ b/backend/__tests__/__integration__/setup-integration-tests.ts @@ -1,6 +1,5 @@ import { afterAll, beforeAll, afterEach, vi } from "vitest"; import { Collection, Db, MongoClient, WithId } from "mongodb"; -import { setupCommonMocks } from "../setup-common-mocks"; import { getConnection } from "../../src/init/redis"; process.env["MODE"] = "dev"; @@ -8,23 +7,21 @@ process.env["MODE"] = "dev"; let db: Db | undefined; let client: MongoClient | undefined; +vi.mock("../../src/init/db", () => ({ + __esModule: true, + getDb: (): Db => db as Db, + collection: (name: string): Collection> => + (db as Db).collection>(name), + close: () => { + // + }, +})); + beforeAll(async () => { client = new MongoClient(process.env["TEST_DB_URL"] as string); await client.connect(); db = client.db(); - vi.mock("../../src/init/db", () => ({ - __esModule: true, - getDb: (): Db => db as Db, - collection: (name: string): Collection> => - (db as Db).collection>(name), - close: () => { - // - }, - })); - - setupCommonMocks(); - //we compare the time in mongodb to calculate premium status, so we have to use real time here vi.useRealTimers(); }); diff --git a/backend/__tests__/setup-common-mocks.ts b/backend/__tests__/setup-common-mocks.ts index 4ef4a35ee9b9..30c863419e43 100644 --- a/backend/__tests__/setup-common-mocks.ts +++ b/backend/__tests__/setup-common-mocks.ts @@ -1,42 +1,40 @@ import { vi } from "vitest"; -export function setupCommonMocks(): void { - vi.mock("../src/utils/logger", () => ({ - __esModule: true, - default: { - error: console.error, - warning: console.warn, - info: console.info, - success: console.info, - logToDb: console.info, - }, - })); - - vi.mock("swagger-stats", () => ({ - getMiddleware: - () => - (_: unknown, __: unknown, next: () => unknown): void => { - next(); - }, - })); +vi.mock("../src/utils/logger", () => ({ + __esModule: true, + default: { + error: console.error, + warning: console.warn, + info: console.info, + success: console.info, + logToDb: console.info, + }, +})); - // TODO: better approach for this when needed - // https://firebase.google.com/docs/rules/unit-tests#run_local_unit_tests_with_the_version_9_javascript_sdk - vi.mock("firebase-admin", () => ({ - __esModule: true, - default: { - auth: (): unknown => ({ - verifyIdToken: ( - _token: string, - _checkRevoked: boolean, - ): unknown /* Promise */ => - Promise.resolve({ - aud: "mockFirebaseProjectId", - auth_time: 123, - exp: 1000, - uid: "mockUid", - }), - }), +vi.mock("swagger-stats", () => ({ + getMiddleware: + () => + (_: unknown, __: unknown, next: () => unknown): void => { + next(); }, - })); -} +})); + +// TODO: better approach for this when needed +// https://firebase.google.com/docs/rules/unit-tests#run_local_unit_tests_with_the_version_9_javascript_sdk +vi.mock("firebase-admin", () => ({ + __esModule: true, + default: { + auth: (): unknown => ({ + verifyIdToken: ( + _token: string, + _checkRevoked: boolean, + ): unknown /* Promise */ => + Promise.resolve({ + aud: "mockFirebaseProjectId", + auth_time: 123, + exp: 1000, + uid: "mockUid", + }), + }), + }, +})); diff --git a/backend/__tests__/setup-tests.ts b/backend/__tests__/setup-tests.ts index ed5eb8c5fafe..4eb5cf3ba633 100644 --- a/backend/__tests__/setup-tests.ts +++ b/backend/__tests__/setup-tests.ts @@ -1,34 +1,32 @@ import { afterAll, beforeAll, afterEach, vi } from "vitest"; import { BASE_CONFIGURATION } from "../src/constants/base-configuration"; -import { setupCommonMocks } from "./setup-common-mocks"; import { __testing } from "../src/init/configuration"; process.env["MODE"] = "dev"; process.env.TZ = "UTC"; -beforeAll(async () => { - //don't add any configuration here, add to global-setup.ts instead. - vi.mock("../src/init/configuration", async (importOriginal) => { - const orig = (await importOriginal()) as any; +vi.mock("../src/init/configuration", async (importOriginal) => { + const orig = (await importOriginal()) as any; - return { - __testing: orig.__testing, - getLiveConfiguration: () => BASE_CONFIGURATION, - getCachedConfiguration: () => BASE_CONFIGURATION, - patchConfiguration: vi.fn(), - }; - }); + return { + __testing: orig.__testing, + getLiveConfiguration: () => BASE_CONFIGURATION, + getCachedConfiguration: () => BASE_CONFIGURATION, + patchConfiguration: vi.fn(), + }; +}); - vi.mock("../src/init/db", () => ({ - __esModule: true, - getDb: () => undefined, - collection: () => undefined, - close: () => { - // - }, - })); +vi.mock("../src/init/db", () => ({ + __esModule: true, + getDb: () => undefined, + collection: () => undefined, + close: () => { + // + }, +})); - setupCommonMocks(); +beforeAll(async () => { + //don't add any configuration here, add to global-setup.ts instead. }); afterEach(async () => {