diff --git a/apps/web/test/lib/confirm.handler.test.ts b/apps/web/test/lib/confirm.handler.test.ts new file mode 100644 index 0000000000..f6cfc16d65 --- /dev/null +++ b/apps/web/test/lib/confirm.handler.test.ts @@ -0,0 +1,110 @@ +import { + createBookingScenario, + getOrganizer, + getScenarioData, + TestData, + mockSuccessfulVideoMeetingCreation, +} from "@calcom/web/test/utils/bookingScenario/bookingScenario"; + +import { describe, it, beforeEach, vi, expect } from "vitest"; + +import * as handleConfirmationModule from "@calcom/features/bookings/lib/handleConfirmation"; +import { BookingStatus } from "@calcom/prisma/enums"; +import type { TrpcSessionUser } from "@calcom/trpc/server/types"; +import { confirmHandler } from "@calcom/trpc/server/routers/viewer/bookings/confirm.handler"; + +describe("confirmHandler", () => { + beforeEach(() => { + vi.clearAllMocks(); + }); + + it("should pass hideCalendarNotes property to CalendarEvent when enabled", async () => { + vi.setSystemTime("2050-01-07T00:00:00Z"); + + const handleConfirmationSpy = vi.spyOn(handleConfirmationModule, "handleConfirmation"); + + const attendeeUser = getOrganizer({ + email: "test@example.com", + name: "test name", + id: 102, + schedules: [TestData.schedules.IstWorkHours], + }); + + const organizer = getOrganizer({ + name: "Organizer", + email: "organizer@example.com", + id: 101, + schedules: [TestData.schedules.IstWorkHours], + }); + + const uidOfBooking = "hideNotes123"; + const iCalUID = `${uidOfBooking}@Cal.com`; + + const plus1DateString = "2050-01-08"; + + await createBookingScenario( + getScenarioData({ + eventTypes: [ + { + id: 1, + slotInterval: 15, + length: 15, + locations: [], + hideCalendarNotes: true, + hideCalendarEventDetails: true, + requiresConfirmation: true, + users: [ + { + id: 101, + }, + ], + }, + ], + bookings: [ + { + id: 101, + uid: uidOfBooking, + eventTypeId: 1, + status: BookingStatus.PENDING, + startTime: `${plus1DateString}T05:00:00.000Z`, + endTime: `${plus1DateString}T05:15:00.000Z`, + references: [], + iCalUID, + location: "integrations:daily", + attendees: [attendeeUser], + responses: { name: attendeeUser.name, email: attendeeUser.email, notes: "Sensitive information" }, + }, + ], + organizer, + apps: [TestData.apps["daily-video"]], + }) + ); + + mockSuccessfulVideoMeetingCreation({ + metadataLookupKey: "dailyvideo", + }); + + const ctx = { + user: { + id: organizer.id, + name: organizer.name, + timeZone: organizer.timeZone, + username: organizer.username, + } as NonNullable, + }; + + const res = await confirmHandler({ + ctx, + input: { bookingId: 101, confirmed: true, reason: "", emailsEnabled: true }, + }); + + expect(res?.status).toBe(BookingStatus.ACCEPTED); + expect(handleConfirmationSpy).toHaveBeenCalledTimes(1); + + const handleConfirmationCall = handleConfirmationSpy.mock.calls[0][0]; + const calendarEvent = handleConfirmationCall.evt; + + expect(calendarEvent.hideCalendarNotes).toBe(true); + expect(calendarEvent.hideCalendarEventDetails).toBe(true); + }); +}); diff --git a/packages/trpc/server/routers/viewer/bookings/confirm.handler.test.ts b/packages/trpc/server/routers/viewer/bookings/confirm.handler.test.ts index 06f6b47793..33f3f3980d 100644 --- a/packages/trpc/server/routers/viewer/bookings/confirm.handler.test.ts +++ b/packages/trpc/server/routers/viewer/bookings/confirm.handler.test.ts @@ -200,4 +200,4 @@ describe.skip("confirmHandler", () => { expect(res?.status).toBe(BookingStatus.REJECTED); expectWorkflowToBeTriggered({ emailsToReceive: [organizer.email], emails }); }); -}); +}); \ No newline at end of file diff --git a/packages/trpc/server/routers/viewer/bookings/confirm.handler.ts b/packages/trpc/server/routers/viewer/bookings/confirm.handler.ts index f7b151fc4b..c1d99929e8 100644 --- a/packages/trpc/server/routers/viewer/bookings/confirm.handler.ts +++ b/packages/trpc/server/routers/viewer/bookings/confirm.handler.ts @@ -85,6 +85,8 @@ export const confirmHandler = async ({ ctx, input }: ConfirmOptions) => { price: true, bookingFields: true, hideOrganizerEmail: true, + hideCalendarNotes: true, + hideCalendarEventDetails: true, disableGuests: true, customReplyToEmail: true, metadata: true, @@ -233,6 +235,8 @@ export const confirmHandler = async ({ ctx, input }: ConfirmOptions) => { : [], requiresConfirmation: booking?.eventType?.requiresConfirmation ?? false, hideOrganizerEmail: booking.eventType?.hideOrganizerEmail, + hideCalendarNotes: booking.eventType?.hideCalendarNotes, + hideCalendarEventDetails: booking.eventType?.hideCalendarEventDetails, eventTypeId: booking.eventType?.id, customReplyToEmail: booking.eventType?.customReplyToEmail, team: !!booking.eventType?.team