From 8deedfd36146909801b8b5d2f4eb44c01dc98125 Mon Sep 17 00:00:00 2001 From: Vikas Patil <112180774+vikaspatil0021@users.noreply.github.com> Date: Mon, 6 May 2024 13:44:09 +0530 Subject: [PATCH] fix: Booking Cancelled Webhook - Organiser webhook payload is missing id. #14697 (#14745) * fix: include id information to be consistent with create/reschedule flows * fix: include username as well * function expectBookingCancelledWebhookToHaveBeenFired created * chore: undo yarn.lock --------- Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Co-authored-by: Udit Takkar --- .../web/test/utils/bookingScenario/expects.ts | 38 +++++++++++++++++++ .../bookings/lib/handleCancelBooking.ts | 8 +++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/apps/web/test/utils/bookingScenario/expects.ts b/apps/web/test/utils/bookingScenario/expects.ts index c01bc1745ea5b..3600a4adca45d 100644 --- a/apps/web/test/utils/bookingScenario/expects.ts +++ b/apps/web/test/utils/bookingScenario/expects.ts @@ -975,6 +975,44 @@ export function expectBookingRescheduledWebhookToHaveBeenFired({ }); } +export function expectBookingCancelledWebhookToHaveBeenFired({ + booker, + location, + subscriberUrl, + payload, +}: { + organizer: { email: string; name: string }; + booker: { email: string; name: string }; + subscriberUrl: string; + location: string; + payload?: Record; +}) { + expectWebhookToHaveBeenCalledWith(subscriberUrl, { + triggerEvent: "BOOKING_CANCELLED", + payload: { + ...payload, + metadata: null, + responses: { + booker: { + label: "your_name", + value: booker.name, + isHidden: false, + }, + email: { + label: "email_address", + value: booker.email, + isHidden: false, + }, + location: { + label: "location", + value: { optionValue: "", value: location }, + isHidden: false, + }, + }, + }, + }); +} + export function expectBookingPaymentIntiatedWebhookToHaveBeenFired({ booker, location, diff --git a/packages/features/bookings/lib/handleCancelBooking.ts b/packages/features/bookings/lib/handleCancelBooking.ts index a368fea99609a..49d8ae7f5dd14 100644 --- a/packages/features/bookings/lib/handleCancelBooking.ts +++ b/packages/features/bookings/lib/handleCancelBooking.ts @@ -200,6 +200,8 @@ async function handler(req: CustomRequest) { id: bookingToDelete.userId, }, select: { + id: true, + username:true, name: true, email: true, timeZone: true, @@ -255,6 +257,8 @@ async function handler(req: CustomRequest) { startTime: bookingToDelete?.startTime ? dayjs(bookingToDelete.startTime).format() : "", endTime: bookingToDelete?.endTime ? dayjs(bookingToDelete.endTime).format() : "", organizer: { + id: organizer.id, + username: organizer.username || undefined, email: bookingToDelete?.userPrimaryEmail ?? organizer.email, name: organizer.name ?? "Nameless", timeZone: organizer.timeZone, @@ -272,8 +276,8 @@ async function handler(req: CustomRequest) { destinationCalendar: bookingToDelete?.destinationCalendar ? [bookingToDelete?.destinationCalendar] : bookingToDelete?.user.destinationCalendar - ? [bookingToDelete?.user.destinationCalendar] - : [], + ? [bookingToDelete?.user.destinationCalendar] + : [], cancellationReason: cancellationReason, ...(teamMembers && { team: { name: bookingToDelete?.eventType?.team?.name || "Nameless", members: teamMembers, id: teamId! },