first commit
This commit is contained in:
13
calcom/tests/libs/__mocks__/CalendarManager.ts
Normal file
13
calcom/tests/libs/__mocks__/CalendarManager.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { beforeEach, vi } from "vitest";
|
||||
import { mockReset, mockDeep } from "vitest-mock-extended";
|
||||
|
||||
import type * as CalendarManager from "@calcom/core/CalendarManager";
|
||||
|
||||
vi.mock("@calcom/core/CalendarManager", () => CalendarManagerMock);
|
||||
|
||||
beforeEach(() => {
|
||||
mockReset(CalendarManagerMock);
|
||||
});
|
||||
|
||||
const CalendarManagerMock = mockDeep<typeof CalendarManager>();
|
||||
export default CalendarManagerMock;
|
||||
17
calcom/tests/libs/__mocks__/app-store.ts
Normal file
17
calcom/tests/libs/__mocks__/app-store.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { beforeEach, vi } from "vitest";
|
||||
import { mockReset, mockDeep } from "vitest-mock-extended";
|
||||
|
||||
import type * as appStore from "@calcom/app-store";
|
||||
|
||||
vi.mock("@calcom/app-store", () => appStoreMock);
|
||||
|
||||
beforeEach(() => {
|
||||
mockReset(appStoreMock);
|
||||
});
|
||||
|
||||
const appStoreMock = mockDeep<typeof appStore>({
|
||||
fallbackMockImplementation: () => {
|
||||
throw new Error("Unimplemented");
|
||||
},
|
||||
});
|
||||
export default appStoreMock;
|
||||
29
calcom/tests/libs/__mocks__/checkRateLimitAndThrowError.ts
Normal file
29
calcom/tests/libs/__mocks__/checkRateLimitAndThrowError.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { beforeEach, vi } from "vitest";
|
||||
import { mockReset, mockDeep } from "vitest-mock-extended";
|
||||
|
||||
import type * as checkRateLimitAndThrowError from "@calcom/lib/checkRateLimitAndThrowError";
|
||||
|
||||
vi.mock("@calcom/lib/checkRateLimitAndThrowError", () => checkRateLimitAndThrowErrorMock);
|
||||
|
||||
beforeEach(() => {
|
||||
mockReset(checkRateLimitAndThrowErrorMock);
|
||||
});
|
||||
|
||||
const checkRateLimitAndThrowErrorMock = mockDeep<typeof checkRateLimitAndThrowError>();
|
||||
|
||||
export const scenarios = {
|
||||
fakeRateLimitPassed: () => {
|
||||
// It doesn't matter what the implementation is, as long as it resolves without error
|
||||
checkRateLimitAndThrowErrorMock.checkRateLimitAndThrowError.mockResolvedValue(undefined);
|
||||
},
|
||||
fakeRateLimitFailed: () => {
|
||||
const error = new Error("FAKE_RATE_LIMIT_ERROR");
|
||||
// It doesn't matter what the implementation is, as long as it resolves without error
|
||||
checkRateLimitAndThrowErrorMock.checkRateLimitAndThrowError.mockImplementation(() => {
|
||||
throw error;
|
||||
});
|
||||
return error.message;
|
||||
},
|
||||
};
|
||||
|
||||
export default checkRateLimitAndThrowErrorMock;
|
||||
21
calcom/tests/libs/__mocks__/getTranslation.ts
Normal file
21
calcom/tests/libs/__mocks__/getTranslation.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { beforeEach, vi } from "vitest";
|
||||
import { mockReset, mockDeep } from "vitest-mock-extended";
|
||||
|
||||
import type * as getTranslation from "@calcom/lib/server/i18n";
|
||||
|
||||
vi.mock("@calcom/lib/server/i18n", () => getTranslationMock);
|
||||
|
||||
beforeEach(() => {
|
||||
mockReset(getTranslationMock);
|
||||
});
|
||||
|
||||
const getTranslationMock = mockDeep<typeof getTranslation>();
|
||||
|
||||
export const mock = {
|
||||
fakeIdentityFn: () =>
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
//@ts-ignore
|
||||
getTranslationMock.getTranslation.mockImplementation(async () => (key: string) => key),
|
||||
};
|
||||
|
||||
export default getTranslationMock;
|
||||
13
calcom/tests/libs/__mocks__/libServerI18n.ts
Normal file
13
calcom/tests/libs/__mocks__/libServerI18n.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { beforeEach, vi } from "vitest";
|
||||
import { mockReset, mockDeep } from "vitest-mock-extended";
|
||||
|
||||
import type * as i18n from "@calcom/lib/server/i18n";
|
||||
|
||||
vi.mock("@calcom/lib/server/i18n", () => i18nMock);
|
||||
|
||||
beforeEach(() => {
|
||||
mockReset(i18nMock);
|
||||
});
|
||||
|
||||
const i18nMock = mockDeep<typeof i18n>();
|
||||
export default i18nMock;
|
||||
70
calcom/tests/libs/__mocks__/prisma.ts
Normal file
70
calcom/tests/libs/__mocks__/prisma.ts
Normal file
@@ -0,0 +1,70 @@
|
||||
import { PrismockClient } from "prismock";
|
||||
import { beforeEach, vi } from "vitest";
|
||||
|
||||
import logger from "@calcom/lib/logger";
|
||||
import * as selects from "@calcom/prisma/selects";
|
||||
|
||||
vi.mock("@calcom/prisma", () => ({
|
||||
default: prisma,
|
||||
prisma,
|
||||
readonlyPrisma: prisma,
|
||||
...selects,
|
||||
}));
|
||||
|
||||
const handlePrismockBugs = () => {
|
||||
const __updateBooking = prismock.booking.update;
|
||||
const __findFirstOrThrowBooking = prismock.booking.findFirstOrThrow;
|
||||
const __findManyWebhook = prismock.webhook.findMany;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
prismock.booking.update = (...rest: any[]) => {
|
||||
// There is a bug in prismock where it considers `createMany` and `create` itself to have the data directly
|
||||
// In booking flows, we encounter such scenario, so let's fix that here directly till it's fixed in prismock
|
||||
if (rest[0].data.references?.createMany) {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
rest[0].data.references.createMany = rest[0].data.references?.createMany.data;
|
||||
logger.silly("Fixed Prismock bug");
|
||||
}
|
||||
if (rest[0].data.references?.create) {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
rest[0].data.references.create = rest[0].data.references?.create.data;
|
||||
logger.silly("Fixed Prismock bug-1");
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
return __updateBooking(...rest);
|
||||
};
|
||||
|
||||
prismock.booking.findFirstOrThrow = (...rest: any[]) => {
|
||||
const { where } = rest[0];
|
||||
delete where.NOT;
|
||||
logger.silly("Fixed Prismock bug with using NOT in where clause");
|
||||
|
||||
return __findFirstOrThrowBooking(...rest);
|
||||
};
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
prismock.webhook.findMany = (...rest: any[]) => {
|
||||
// There is some bug in prismock where it can't handle complex where clauses
|
||||
if (rest[0].where?.OR && rest[0].where.AND) {
|
||||
rest[0].where = undefined;
|
||||
logger.silly("Fixed Prismock bug-2");
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
return __findManyWebhook(...rest);
|
||||
};
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
prismock.reset();
|
||||
handlePrismockBugs();
|
||||
});
|
||||
|
||||
const prismock = new PrismockClient();
|
||||
|
||||
const prisma = prismock;
|
||||
export default prisma;
|
||||
18
calcom/tests/libs/__mocks__/prismaMock.ts
Normal file
18
calcom/tests/libs/__mocks__/prismaMock.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { beforeEach, vi } from "vitest";
|
||||
import { mockDeep, mockReset } from "vitest-mock-extended";
|
||||
|
||||
import type { PrismaClient } from "@calcom/prisma";
|
||||
|
||||
vi.mock("@calcom/prisma", () => ({
|
||||
default: prisma,
|
||||
prisma,
|
||||
availabilityUserSelect: vi.fn(),
|
||||
userSelect: vi.fn(),
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
mockReset(prisma);
|
||||
});
|
||||
|
||||
const prisma = mockDeep<PrismaClient>();
|
||||
export default prisma;
|
||||
13
calcom/tests/libs/__mocks__/reminderScheduler.ts
Normal file
13
calcom/tests/libs/__mocks__/reminderScheduler.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { beforeEach, vi } from "vitest";
|
||||
import { mockReset, mockDeep } from "vitest-mock-extended";
|
||||
|
||||
import type * as reminderScheduler from "@calcom/features/ee/workflows/lib/reminders/reminderScheduler";
|
||||
|
||||
vi.mock("@calcom/features/ee/workflows/lib/reminders/reminderScheduler", () => reminderSchedulerMock);
|
||||
|
||||
beforeEach(() => {
|
||||
mockReset(reminderSchedulerMock);
|
||||
});
|
||||
|
||||
const reminderSchedulerMock = mockDeep<typeof reminderScheduler>();
|
||||
export default reminderSchedulerMock;
|
||||
13
calcom/tests/libs/__mocks__/videoClient.ts
Normal file
13
calcom/tests/libs/__mocks__/videoClient.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { beforeEach, vi } from "vitest";
|
||||
import { mockReset, mockDeep } from "vitest-mock-extended";
|
||||
|
||||
import type * as videoClient from "@calcom/core/videoClient";
|
||||
|
||||
vi.mock("@calcom/core/videoClient", () => videoClientMock);
|
||||
|
||||
beforeEach(() => {
|
||||
mockReset(videoClientMock);
|
||||
});
|
||||
|
||||
const videoClientMock = mockDeep<typeof videoClient>();
|
||||
export default videoClientMock;
|
||||
Reference in New Issue
Block a user