Skip to content

Commit aa51218

Browse files
authored
perf: move to disable prisma client extension inference (calcom#23692)
* perf: move to disable prisma client extension inference * Prisma doesn't like it when you pass Record<string, unknown> * API v1 type fixes * Missed one * Fix unit test fail due to faulty expect * Assigning to prisma InputJsonValue/Array must be done as object, not interface * Fix @calcom/web ts error, teams not defined * Run eslint formatter * fixed the routingFormHelpers file causing a failing app store e2e test
1 parent 38bc5fb commit aa51218

24 files changed

Lines changed: 295 additions & 253 deletions

File tree

apps/api/v1/pages/api/credential-sync/_patch.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import type { NextApiRequest } from "next";
33
import { OAuth2UniversalSchema } from "@calcom/app-store/_utils/oauth/universalSchema";
44
import { symmetricDecrypt } from "@calcom/lib/crypto";
55
import { defaultResponder } from "@calcom/lib/server/defaultResponder";
6-
import prisma from "@calcom/prisma";
6+
import { prisma } from "@calcom/prisma";
7+
import type { Prisma } from "@calcom/prisma/client";
78

89
import { schemaCredentialPatchParams, schemaCredentialPatchBody } from "~/lib/validations/credential-sync";
910

@@ -71,7 +72,7 @@ async function handler(req: NextApiRequest) {
7172
userId,
7273
},
7374
data: {
74-
key,
75+
key: key as unknown as Prisma.InputJsonValue,
7576
},
7677
select: {
7778
id: true,

apps/api/v1/pages/api/credential-sync/_post.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import { appStoreMetadata } from "@calcom/app-store/appStoreMetaData";
66
import { symmetricDecrypt } from "@calcom/lib/crypto";
77
import { HttpError } from "@calcom/lib/http-error";
88
import { defaultResponder } from "@calcom/lib/server/defaultResponder";
9-
import prisma from "@calcom/prisma";
9+
import { prisma } from "@calcom/prisma";
10+
import type { Prisma } from "@calcom/prisma/client";
1011
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";
1112

1213
import { schemaCredentialPostBody, schemaCredentialPostParams } from "~/lib/validations/credential-sync";
@@ -92,7 +93,7 @@ async function handler(req: NextApiRequest) {
9293
data: {
9394
userId,
9495
appId: appSlug,
95-
key,
96+
key: key as unknown as Prisma.InputJsonValue,
9697
type: appMetadata.type,
9798
},
9899
select: credentialForCalendarServiceSelect,

apps/api/v1/test/lib/attendees/_post.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe("POST /api/attendees", () => {
7777

7878
const userBooking = { id: 1 };
7979

80-
prismaMock.booking.findFirst.mockResolvedValue(userBooking);
80+
prismaMock.booking.findFirst.mockResolvedValue(userBooking as any);
8181

8282
const attendeeData = {
8383
id: 1,

apps/api/v1/test/lib/bookings/[id]/_delete.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ beforeEach(() => {
2525
id: userId,
2626
email: "test@example.com",
2727
name: "Test User",
28-
});
28+
} as any);
2929
});
3030

3131
afterEach(() => {

apps/api/v1/test/lib/bookings/[id]/_patch.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ beforeEach(() => {
2020
id: userId,
2121
email: "test@example.com",
2222
name: "Test User",
23-
});
23+
} as any);
2424
});
2525

2626
afterEach(() => {

apps/api/v1/test/lib/bookings/_get.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ beforeEach(() => {
3030
id: userId,
3131
email: "test@example.com",
3232
name: "Test User",
33-
});
33+
} as any);
3434
(getAccessibleUsers as any).mockResolvedValue([userId]);
3535
(retrieveOrgScopedAccessibleUsers as any).mockResolvedValue([userId]);
3636

3737
prismaMock.membership.findMany.mockResolvedValue([
3838
{
39+
// @ts-expect-error Will be fixed by Prisma 6.7.0 upgrade mock changes - which uses vitest-mock-extended
3940
team: {
4041
id: 1,
4142
isOrganization: true,
@@ -48,7 +49,7 @@ beforeEach(() => {
4849
id: userId,
4950
email: "test@example.com",
5051
},
51-
]);
52+
] as any);
5253
});
5354

5455
afterEach(() => {

apps/api/v1/test/lib/bookings/_post.test.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import { getEventTypesFromDB } from "@calcom/features/bookings/lib/handleNewBook
1111
import sendPayload from "@calcom/features/webhooks/lib/sendOrSchedulePayload";
1212
import { ErrorCode } from "@calcom/lib/errorCodes";
1313
import { buildBooking, buildEventType, buildWebhook, buildUser } from "@calcom/lib/test/builder";
14-
import prisma from "@calcom/prisma";
14+
import { prisma } from "@calcom/prisma";
1515
import type { Booking } from "@calcom/prisma/client";
16-
import { CreationSource } from "@calcom/prisma/enums";
16+
import { CreationSource, BookingStatus } from "@calcom/prisma/enums";
1717

1818
import handler from "../../../pages/api/bookings/_post";
1919

@@ -303,6 +303,7 @@ describe("POST /api/bookings", () => {
303303

304304
prismaMock.eventType.findUniqueOrThrow.mockResolvedValue({
305305
...buildEventType({ recurringEvent: { freq: 2, count: 12, interval: 1 } }),
306+
// @ts-expect-error requires mockDeep which will be introduced in the Prisma 6.7.0 upgrade, ignore for now.
306307
profile: { organizationId: null },
307308
hosts: [],
308309
users: [buildUser()],
@@ -340,6 +341,7 @@ describe("POST /api/bookings", () => {
340341

341342
prismaMock.eventType.findUniqueOrThrow.mockResolvedValue({
342343
...buildEventType({ recurringEvent: { freq: 2, count: 12, interval: 1 } }),
344+
// @ts-expect-error requires mockDeep which will be introduced in the Prisma 6.7.0 upgrade, ignore for now.
343345
profile: { organizationId: null },
344346
hosts: [],
345347
users: [buildUser()],
@@ -376,6 +378,7 @@ describe("POST /api/bookings", () => {
376378

377379
prismaMock.eventType.findUniqueOrThrow.mockResolvedValue({
378380
...buildEventType({ profileId: null }),
381+
// @ts-expect-error requires mockDeep which will be introduced in the Prisma 6.7.0 upgrade, ignore for now.
379382
profile: { organizationId: null },
380383
hosts: [],
381384
users: [buildUser()],
@@ -417,6 +420,7 @@ describe("POST /api/bookings", () => {
417420

418421
prismaMock.eventType.findUniqueOrThrow.mockResolvedValue({
419422
...buildEventType({ profileId: null, length: 15 }),
423+
// @ts-expect-error requires mockDeep which will be introduced in the Prisma 6.7.0 upgrade, ignore for now.
420424
profile: { organizationId: null },
421425
hosts: [],
422426
users: [buildUser()],
@@ -468,7 +472,7 @@ describe("POST /api/bookings", () => {
468472

469473
prismaMock.booking.findUnique.mockResolvedValue({
470474
...originalBooking,
471-
status: "cancelled",
475+
status: "CANCELLED",
472476
});
473477

474478
const { req, res } = createMocks<CustomNextApiRequest, CustomNextApiResponse>({
@@ -492,6 +496,7 @@ describe("POST /api/bookings", () => {
492496

493497
prismaMock.eventType.findUniqueOrThrow.mockResolvedValue({
494498
...buildEventType({ profileId: null, length: 15 }),
499+
// @ts-expect-error requires mockDeep which will be introduced in the Prisma 6.7.0 upgrade, ignore for now.
495500
profile: { organizationId: null },
496501
hosts: [],
497502
users: [buildUser()],
@@ -532,7 +537,7 @@ describe("POST /api/bookings", () => {
532537
const previousBooking = await prisma.booking.findUnique({
533538
where: { uid: "original-booking-uid" },
534539
});
535-
expect(previousBooking?.status).toBe("cancelled");
540+
expect(previousBooking?.status).toBe(BookingStatus.CANCELLED);
536541
});
537542

538543
test("Creates source as api_v1", async () => {
@@ -556,6 +561,7 @@ describe("POST /api/bookings", () => {
556561

557562
prismaMock.eventType.findUniqueOrThrow.mockResolvedValue({
558563
...buildEventType({ profileId: null, length: 15 }),
564+
// @ts-expect-error requires mockDeep which will be introduced in the Prisma 6.7.0 upgrade, ignore for now.
559565
profile: { organizationId: null },
560566
hosts: [],
561567
users: [buildUser()],
@@ -627,6 +633,7 @@ describe("POST /api/bookings", () => {
627633

628634
prismaMock.eventType.findUniqueOrThrow.mockResolvedValue({
629635
...buildEventType({ profileId: null, length: 15 }),
636+
// @ts-expect-error requires mockDeep which will be introduced in the Prisma 6.7.0 upgrade, ignore for now.
630637
profile: { organizationId: null },
631638
hosts: [],
632639
users: [buildUser()],
@@ -684,6 +691,7 @@ describe("POST /api/bookings", () => {
684691

685692
prismaMock.eventType.findUniqueOrThrow.mockResolvedValue({
686693
...buildEventType({ recurringEvent: { freq: 2, count: 12, interval: 1 } }),
694+
// @ts-expect-error requires mockDeep which will be introduced in the Prisma 6.7.0 upgrade, ignore for now.
687695
profile: { organizationId: null },
688696
hosts: [],
689697
users: [buildUser()],

apps/api/v1/test/lib/event-types/[id]/_delete.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ describe("DELETE /api/event-types/[id]", () => {
5050
// Mocking team.findUnique
5151
prismaMock.team.findUnique.mockResolvedValue({
5252
id: teamId,
53+
// @ts-expect-error requires mockDeep which will be introduced in the Prisma 6.7.0 upgrade, ignore for now.
5354
members: [
5455
{ userId: memberUser, role: MembershipRole.MEMBER, teamId: teamId },
5556
{ userId: adminUser, role: MembershipRole.ADMIN, teamId: teamId },

apps/api/v1/test/lib/event-types/[id]/_get.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ describe("GET /api/event-types/[id]", () => {
8484

8585
prismaMock.team.findFirst.mockResolvedValue({
8686
id: teamId,
87+
// @ts-expect-error requires mockDeep which will be introduced in the Prisma 6.7.0 upgrade, ignore for now.
8788
members: [
8889
{
8990
userId,

0 commit comments

Comments
 (0)