feat: Setups prisma accelerate (#11324)

This commit is contained in:
Omar López authored and GitHub committed 2023-09-19 21:02:57 +00:00
1 parent 21a0b67b5a
commit 560ec244e8
15 files changed
+150 -49

No files matched your search

@@ -23,6 +23,7 @@ const MOCK_DATA: Mockdata = {
describe("Check Booking Limits Tests", () => {
it("Should return no errors", async () => {
// @ts-expect-error Prisma v5 typings are not yet available
prismaMock.booking.count.mockResolvedValue(0);
expect(
checkBookingLimits(MOCK_DATA.bookingLimits, MOCK_DATA.startDate, MOCK_DATA.id)
@@ -30,6 +31,7 @@ describe("Check Booking Limits Tests", () => {
});
it("Should throw an error", async () => {
// Mock there being two a day
// @ts-expect-error Prisma v5 typings are not yet available
prismaMock.booking.count.mockResolvedValue(2);
expect(
checkBookingLimits(MOCK_DATA.bookingLimits, MOCK_DATA.startDate, MOCK_DATA.id)
@@ -37,6 +39,7 @@ describe("Check Booking Limits Tests", () => {
});
it("Should pass with multiple booking limits", async () => {
// @ts-expect-error Prisma v5 typings are not yet available
prismaMock.booking.count.mockResolvedValue(0);
expect(
checkBookingLimits(
@@ -50,6 +53,7 @@ describe("Check Booking Limits Tests", () => {
).resolves.toBeTruthy();
});
it("Should pass with multiple booking limits with one undefined", async () => {
// @ts-expect-error Prisma v5 typings are not yet available
prismaMock.booking.count.mockResolvedValue(0);
expect(
checkBookingLimits(
@@ -63,6 +67,7 @@ describe("Check Booking Limits Tests", () => {
).resolves.toBeTruthy();
});
it("Should handle mutiple limits correctly", async () => {
// @ts-expect-error Prisma v5 typings are not yet available
prismaMock.booking.count.mockResolvedValue(1);
expect(
checkBookingLimit({
@@ -72,6 +77,7 @@ describe("Check Booking Limits Tests", () => {
eventId: MOCK_DATA.id,
})
).resolves.not.toThrow();
// @ts-expect-error Prisma v5 typings are not yet available
prismaMock.booking.count.mockResolvedValue(3);
expect(
checkBookingLimit({
+1
View File
@@ -13,6 +13,7 @@ import { getDate, getGoogleCalendarCredential, createBookingScenario } from "../
// TODO: Mock properly
prismaMock.eventType.findUnique.mockResolvedValue(null);
// @ts-expect-error Prisma v5 typings are not yet available
prismaMock.user.findMany.mockResolvedValue([]);
vi.mock("@calcom/lib/constants", () => ({
@@ -10,6 +10,7 @@ import type { CompleteEventType, CompleteWorkflowsOnEventTypes } from "@calcom/p
const mockFindFirstEventType = (data?: Partial<CompleteEventType>) => {
const eventType = buildEventType(data as Partial<EventType>);
// @ts-expect-error Prisma v5 typings are not yet available
prismaMock.eventType.findFirst.mockResolvedValue(eventType as EventType);
return eventType;
};
@@ -30,6 +31,7 @@ describe("handleChildrenEventTypes", () => {
describe("Shortcircuits", () => {
it("Returns message 'No managed event type'", async () => {
mockFindFirstEventType();
// @ts-expect-error Prisma v5 typings are not yet available
const result = await updateChildrenEventTypes({
eventTypeId: 1,
oldEventType: { children: [], team: { name: "" } },
@@ -38,6 +40,7 @@ describe("handleChildrenEventTypes", () => {
currentUserId: 1,
hashedLink: undefined,
connectedLink: null,
// @ts-expect-error Prisma v5 typings are not yet available
prisma: prismaMock,
});
expect(result.newUserIds).toEqual(undefined);
@@ -57,6 +60,7 @@ describe("handleChildrenEventTypes", () => {
currentUserId: 1,
hashedLink: undefined,
connectedLink: null,
// @ts-expect-error Prisma v5 typings are not yet available
prisma: prismaMock,
});
expect(result.newUserIds).toEqual(undefined);
@@ -82,6 +86,7 @@ describe("handleChildrenEventTypes", () => {
currentUserId: 1,
hashedLink: undefined,
connectedLink: null,
// @ts-expect-error Prisma v5 typings are not yet available
prisma: prismaMock,
});
expect(result.newUserIds).toEqual(undefined);
@@ -111,6 +116,7 @@ describe("handleChildrenEventTypes", () => {
currentUserId: 1,
hashedLink: undefined,
connectedLink: null,
// @ts-expect-error Prisma v5 typings are not yet available
prisma: prismaMock,
});
expect(prismaMock.eventType.create).toHaveBeenCalledWith({
@@ -157,6 +163,7 @@ describe("handleChildrenEventTypes", () => {
currentUserId: 1,
hashedLink: "somestring",
connectedLink: null,
// @ts-expect-error Prisma v5 typings are not yet available
prisma: prismaMock,
});
expect(prismaMock.eventType.update).toHaveBeenCalledWith({
@@ -190,6 +197,7 @@ describe("handleChildrenEventTypes", () => {
currentUserId: 1,
hashedLink: undefined,
connectedLink: null,
// @ts-expect-error Prisma v5 typings are not yet available
prisma: prismaMock,
});
expect(result.newUserIds).toEqual([]);
@@ -214,6 +222,7 @@ describe("handleChildrenEventTypes", () => {
currentUserId: 1,
hashedLink: undefined,
connectedLink: null,
// @ts-expect-error Prisma v5 typings are not yet available
prisma: prismaMock,
});
// Have been called
@@ -244,6 +253,7 @@ describe("handleChildrenEventTypes", () => {
currentUserId: 1,
hashedLink: undefined,
connectedLink: null,
// @ts-expect-error Prisma v5 typings are not yet available
prisma: prismaMock,
});
expect(prismaMock.eventType.create).toHaveBeenCalledWith({
@@ -290,6 +300,7 @@ describe("handleChildrenEventTypes", () => {
currentUserId: 1,
hashedLink: undefined,
connectedLink: null,
// @ts-expect-error Prisma v5 typings are not yet available
prisma: prismaMock,
});
expect(prismaMock.eventType.update).toHaveBeenCalledWith({
@@ -348,6 +359,7 @@ describe("handleChildrenEventTypes", () => {
currentUserId: 1,
hashedLink: undefined,
connectedLink: null,
// @ts-expect-error Prisma v5 typings are not yet available
prisma: prismaMock,
});
expect(prismaMock.eventType.create).toHaveBeenCalledWith({
@@ -36,6 +36,7 @@ it("can find lucky user with maximize availability", async () => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
prismaMock.user.findMany.mockResolvedValue(users);
// @ts-expect-error Prisma v5 typings are not yet available
prismaMock.booking.findMany.mockResolvedValue([]);
await expect(
+9 -4
View File
@@ -176,9 +176,11 @@ async function addBookings(bookings: InputBooking[], eventTypes: InputEventType[
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
prismaMock.booking.findMany.mockImplementation((findManyArg) => {
// @ts-expect-error Prisma v5 breaks this
const where = findManyArg?.where || {};
return new Promise((resolve) => {
resolve(
// @ts-expect-error Prisma v5 breaks this
bookings
// We can improve this filter to support the entire where clause but that isn't necessary yet. So, handle what we know we pass to `findMany` and is needed
.filter((booking) => {
@@ -222,6 +224,7 @@ async function addBookings(bookings: InputBooking[], eventTypes: InputEventType[
async function addWebhooks(webhooks: InputWebhook[]) {
prismaMock.webhook.findMany.mockResolvedValue(
// @ts-expect-error Prisma v5 breaks this
webhooks.map((webhook) => {
return {
...webhook,
@@ -242,13 +245,16 @@ function addUsers(users: InputUser[]) {
// @ts-ignore
prismaMock.user.findUniqueOrThrow.mockImplementation((findUniqueArgs) => {
return new Promise((resolve) => {
// @ts-expect-error Prisma v5 breaks this
resolve({
// @ts-expect-error Prisma v5 breaks this
email: `IntegrationTestUser${findUniqueArgs?.where.id}@example.com`,
} as unknown as PrismaUser);
});
});
prismaMock.user.findMany.mockResolvedValue(
// @ts-expect-error Prisma v5 breaks this
users.map((user) => {
return {
...user,
@@ -265,6 +271,7 @@ export async function createBookingScenario(data: ScenarioData) {
const eventType = addEventTypes(data.eventTypes, data.users);
if (data.apps) {
// @ts-expect-error Prisma v5 breaks this
prismaMock.app.findMany.mockResolvedValue(data.apps as PrismaApp[]);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
@@ -562,9 +569,8 @@ export function getScenarioData({
}
export function mockEnableEmailFeature() {
// @ts-expect-error Prisma v5 breaks this
prismaMock.feature.findMany.mockResolvedValue([
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
{
slug: "emails",
// It's a kill switch
@@ -574,8 +580,7 @@ export function mockEnableEmailFeature() {
}
export function mockNoTranslations() {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
// @ts-expect-error FIXME
i18nMock.getTranslation.mockImplementation(() => {
return new Promise((resolve) => {
const identityFn = (key: string) => key;