Skip to content

Commit

Permalink
chore: upgrade to prisma 5.3.1 (calcom#11666)
Browse files Browse the repository at this point in the history
Co-authored-by: Peer Richelsen <[email protected]>
  • Loading branch information
zomars and PeerRich authored Oct 12, 2023
1 parent 2c5cb6a commit 2080345
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 523 deletions.
6 changes: 0 additions & 6 deletions apps/web/test/lib/checkBookingLimits.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,20 @@ 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)
).resolves.toBeTruthy();
});
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)
).rejects.toThrowError();
});

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(
Expand All @@ -53,7 +50,6 @@ 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(
Expand All @@ -67,7 +63,6 @@ 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({
Expand All @@ -77,7 +72,6 @@ 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({
Expand Down
13 changes: 1 addition & 12 deletions apps/web/test/lib/handleChildrenEventTypes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ 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;
};
Expand All @@ -31,7 +30,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: "" } },
Expand All @@ -40,7 +39,6 @@ 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);
Expand All @@ -60,7 +58,6 @@ 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);
Expand All @@ -86,7 +83,6 @@ 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);
Expand Down Expand Up @@ -116,7 +112,6 @@ 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({
Expand Down Expand Up @@ -163,7 +158,6 @@ 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({
Expand Down Expand Up @@ -197,7 +191,6 @@ describe("handleChildrenEventTypes", () => {
currentUserId: 1,
hashedLink: undefined,
connectedLink: null,
// @ts-expect-error Prisma v5 typings are not yet available
prisma: prismaMock,
});
expect(result.newUserIds).toEqual([]);
Expand All @@ -222,7 +215,6 @@ describe("handleChildrenEventTypes", () => {
currentUserId: 1,
hashedLink: undefined,
connectedLink: null,
// @ts-expect-error Prisma v5 typings are not yet available
prisma: prismaMock,
});
// Have been called
Expand Down Expand Up @@ -253,7 +245,6 @@ 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({
Expand Down Expand Up @@ -300,7 +291,6 @@ 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({
Expand Down Expand Up @@ -359,7 +349,6 @@ 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({
Expand Down
3 changes: 0 additions & 3 deletions apps/web/test/lib/team-event-types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ it("can find lucky user with maximize availability", async () => {
});
const users = [user1, user2];
// TODO: we may be able to use native prisma generics somehow?
// 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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ test("Calendar Cache is being called", async () => {
// First call won't have a cache
.mockResolvedValueOnce(null)
// Second call will have a cache
// @ts-expect-error expects a "null" here due to previous call
.mockResolvedValueOnce(calendarCacheResponse);

// prismaMock.calendarCache.create.mock.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Prisma } from "@prisma/client";
import short from "short-uuid";
import { v5 as uuidv5 } from "uuid";
import type { DeepMockProxy } from "vitest-mock-extended";

import { sendSlugReplacementEmail } from "@calcom/emails/email-manager";
import { getTranslation } from "@calcom/lib/server/i18n";
Expand Down Expand Up @@ -41,7 +42,7 @@ interface handleChildrenEventTypesProps {
};
}[]
| undefined;
prisma: PrismaClient;
prisma: PrismaClient | DeepMockProxy<PrismaClient>;
}

const sendAllSlugReplacementEmails = async (
Expand Down
6 changes: 3 additions & 3 deletions packages/prisma/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
},
"dependencies": {
"@calcom/lib": "*",
"@prisma/client": "^5.2.0",
"@prisma/client": "^5.4.2",
"@prisma/extension-accelerate": "^0.6.2",
"@prisma/generator-helper": "^5.2.0",
"prisma": "^5.2.0",
"@prisma/generator-helper": "^5.4.2",
"prisma": "^5.4.2",
"ts-node": "^10.9.1",
"zod": "^3.22.2",
"zod-prisma": "^0.5.4"
Expand Down
20 changes: 10 additions & 10 deletions packages/trpc/server/routers/viewer/bookings/get.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ async function getBookings({
},
};

const filtersCombined: Prisma.BookingWhereInput[] =
filters &&
Object.keys(filters).map((key) => {
return bookingWhereInputFilters[key];
});

const filtersCombined: Prisma.BookingWhereInput[] = !filters
? []
: Object.keys(filters)
.map((key) => bookingWhereInputFilters[key])
// On prisma 5.4.2 passing undefined to where "AND" causes an error
.filter(Boolean);
const bookingSelect = {
...bookingMinimalSelect,
uid: true,
Expand Down Expand Up @@ -257,7 +257,7 @@ async function getBookings({
userId: user.id,
},
],
AND: [passedBookingsStatusFilter, ...(filtersCombined ?? [])],
AND: [passedBookingsStatusFilter, ...filtersCombined],
},
orderBy,
take: take + 1,
Expand All @@ -274,7 +274,7 @@ async function getBookings({
},
},
],
AND: [passedBookingsStatusFilter, ...(filtersCombined ?? [])],
AND: [passedBookingsStatusFilter, ...filtersCombined],
},
orderBy,
take: take + 1,
Expand All @@ -298,7 +298,7 @@ async function getBookings({
},
},
],
AND: [passedBookingsStatusFilter, ...(filtersCombined ?? [])],
AND: [passedBookingsStatusFilter, ...filtersCombined],
},
orderBy,
take: take + 1,
Expand All @@ -317,7 +317,7 @@ async function getBookings({
},
},
],
AND: [passedBookingsStatusFilter, ...(filtersCombined ?? [])],
AND: [passedBookingsStatusFilter, ...filtersCombined],
},
orderBy,
take: take + 1,
Expand Down
Loading

0 comments on commit 2080345

Please sign in to comment.