diff --git a/apps/web/test/pages/api/webhook/app-credential.test.ts b/apps/web/test/pages/api/webhook/app-credential.test.ts index f76eda52b6..a4cfb267ce 100644 --- a/apps/web/test/pages/api/webhook/app-credential.test.ts +++ b/apps/web/test/pages/api/webhook/app-credential.test.ts @@ -6,6 +6,7 @@ import { createMocks } from "node-mocks-http"; import { afterAll, describe, expect, test, vi } from "vitest"; import { symmetricEncrypt } from "@calcom/lib/crypto"; +import { buildApp, buildUser } from "@calcom/lib/test/builder"; import prisma from "@calcom/prisma"; import handler from "../../../../pages/api/webhook/app-credential"; @@ -47,19 +48,22 @@ describe("app-credential webhook", () => { prisma, }); - prismaMock.user.findUnique.mockResolvedValue({ id: 1 }); - prismaMock.app.findUnique.mockResolvedValue({ - slug: "office365-calendar", - dirName: "office365calendar", - keys: "test-keys", - }); - - prismaMock.credential.create.mockImplementation(() => { - return { + prismaMock.user.findUnique.mockResolvedValue( + buildUser({ id: 1, - userId: 1, - }; - }); + username: "test", + name: "Test User", + email: "test@example.com", + }) + ); + + prismaMock.app.findUnique.mockResolvedValue( + buildApp({ + slug: "office365-calendar", + dirName: "office365calendar", + keys: "test-keys", + }) + ); await handler(req, res); diff --git a/packages/lib/test/builder.ts b/packages/lib/test/builder.ts index 7769023a59..063b89da4e 100644 --- a/packages/lib/test/builder.ts +++ b/packages/lib/test/builder.ts @@ -1,5 +1,5 @@ import { faker } from "@faker-js/faker"; -import type { Booking, EventType, Prisma, Webhook } from "@prisma/client"; +import type { App, Booking, EventType, Prisma, Webhook } from "@prisma/client"; import type { TFunction } from "next-i18next"; import { BookingStatus } from "@calcom/prisma/enums"; @@ -227,3 +227,17 @@ export const buildUser = >(user?: T): UserPayload ...user, }; }; + +export const buildApp = (app?: Partial): App => { + return { + categories: null, + createdAt: new Date(), + updatedAt: new Date(), + credentials: null, + payments: null, + Webhook: null, + ApiKey: null, + enabled: true, + ...app, + }; +};