|
| 1 | +import { |
| 2 | + createBookingScenario, |
| 3 | + getOrganizer, |
| 4 | + getScenarioData, |
| 5 | + TestData, |
| 6 | + mockSuccessfulVideoMeetingCreation, |
| 7 | +} from "@calcom/web/test/utils/bookingScenario/bookingScenario"; |
| 8 | + |
| 9 | +import { describe, it, beforeEach, vi, expect } from "vitest"; |
| 10 | + |
| 11 | +import * as handleConfirmationModule from "@calcom/features/bookings/lib/handleConfirmation"; |
| 12 | +import { BookingStatus } from "@calcom/prisma/enums"; |
| 13 | +import { confirmHandler } from "@calcom/trpc/server/routers/viewer/bookings/confirm.handler"; |
| 14 | +import type { TrpcSessionUser } from "@calcom/trpc/server/types"; |
| 15 | + |
| 16 | +describe("confirmHandler", () => { |
| 17 | + beforeEach(() => { |
| 18 | + vi.clearAllMocks(); |
| 19 | + }); |
| 20 | + |
| 21 | + it("should pass hideCalendarNotes property to CalendarEvent when enabled", async () => { |
| 22 | + vi.setSystemTime("2050-01-07T00:00:00Z"); |
| 23 | + |
| 24 | + const handleConfirmationSpy = vi.spyOn(handleConfirmationModule, "handleConfirmation"); |
| 25 | + |
| 26 | + const attendeeUser = getOrganizer({ |
| 27 | + |
| 28 | + name: "test name", |
| 29 | + id: 102, |
| 30 | + schedules: [TestData.schedules.IstWorkHours], |
| 31 | + }); |
| 32 | + |
| 33 | + const organizer = getOrganizer({ |
| 34 | + name: "Organizer", |
| 35 | + |
| 36 | + id: 101, |
| 37 | + schedules: [TestData.schedules.IstWorkHours], |
| 38 | + }); |
| 39 | + |
| 40 | + const uidOfBooking = "hideNotes123"; |
| 41 | + const iCalUID = `${uidOfBooking}@Cal.com`; |
| 42 | + |
| 43 | + const plus1DateString = "2050-01-08"; |
| 44 | + |
| 45 | + await createBookingScenario( |
| 46 | + getScenarioData({ |
| 47 | + eventTypes: [ |
| 48 | + { |
| 49 | + id: 1, |
| 50 | + slotInterval: 15, |
| 51 | + length: 15, |
| 52 | + locations: [], |
| 53 | + hideCalendarNotes: true, |
| 54 | + hideCalendarEventDetails: true, |
| 55 | + requiresConfirmation: true, |
| 56 | + users: [ |
| 57 | + { |
| 58 | + id: 101, |
| 59 | + }, |
| 60 | + ], |
| 61 | + }, |
| 62 | + ], |
| 63 | + bookings: [ |
| 64 | + { |
| 65 | + id: 101, |
| 66 | + uid: uidOfBooking, |
| 67 | + eventTypeId: 1, |
| 68 | + status: BookingStatus.PENDING, |
| 69 | + startTime: `${plus1DateString}T05:00:00.000Z`, |
| 70 | + endTime: `${plus1DateString}T05:15:00.000Z`, |
| 71 | + references: [], |
| 72 | + iCalUID, |
| 73 | + location: "integrations:daily", |
| 74 | + attendees: [attendeeUser], |
| 75 | + responses: { name: attendeeUser.name, email: attendeeUser.email, notes: "Sensitive information" }, |
| 76 | + }, |
| 77 | + ], |
| 78 | + organizer, |
| 79 | + apps: [TestData.apps["daily-video"]], |
| 80 | + }) |
| 81 | + ); |
| 82 | + |
| 83 | + mockSuccessfulVideoMeetingCreation({ |
| 84 | + metadataLookupKey: "dailyvideo", |
| 85 | + }); |
| 86 | + |
| 87 | + const ctx = { |
| 88 | + user: { |
| 89 | + id: organizer.id, |
| 90 | + name: organizer.name, |
| 91 | + timeZone: organizer.timeZone, |
| 92 | + username: organizer.username, |
| 93 | + } as NonNullable<TrpcSessionUser>, |
| 94 | + }; |
| 95 | + |
| 96 | + const res = await confirmHandler({ |
| 97 | + ctx, |
| 98 | + input: { bookingId: 101, confirmed: true, reason: "", emailsEnabled: true }, |
| 99 | + }); |
| 100 | + |
| 101 | + expect(res?.status).toBe(BookingStatus.ACCEPTED); |
| 102 | + expect(handleConfirmationSpy).toHaveBeenCalledTimes(1); |
| 103 | + |
| 104 | + const handleConfirmationCall = handleConfirmationSpy.mock.calls[0][0]; |
| 105 | + const calendarEvent = handleConfirmationCall.evt; |
| 106 | + |
| 107 | + expect(calendarEvent.hideCalendarNotes).toBe(true); |
| 108 | + expect(calendarEvent.hideCalendarEventDetails).toBe(true); |
| 109 | + }); |
| 110 | +}); |
0 commit comments