2
0

first commit

This commit is contained in:
2024-08-09 00:39:27 +02:00
commit 79688abe2e
5698 changed files with 497838 additions and 0 deletions

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;

View 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;