From 519ceaba7eded2c8d54c1777aaa7e093973d8b85 Mon Sep 17 00:00:00 2001 From: Vikas Patil <112180774+vikaspatil0021@users.noreply.github.com> Date: Fri, 26 Apr 2024 11:12:23 +0000 Subject: [PATCH] created expectBookingCancelledWebhookToHaveBeenFired function --- .../web/test/utils/bookingScenario/expects.ts | 166 +++++++++++------- 1 file changed, 102 insertions(+), 64 deletions(-) diff --git a/apps/web/test/utils/bookingScenario/expects.ts b/apps/web/test/utils/bookingScenario/expects.ts index a018ebae9d03e7..b18064ff958948 100644 --- a/apps/web/test/utils/bookingScenario/expects.ts +++ b/apps/web/test/utils/bookingScenario/expects.ts @@ -215,12 +215,12 @@ expect.extend({ const bookingTimeRange = expectedEmail.bookingTimeRange; const when = bookingTimeRange ? formatDateToWhenFormat( - { - start: bookingTimeRange.start, - end: bookingTimeRange.end, - }, - bookingTimeRange.timeZone - ) + { + start: bookingTimeRange.start, + end: bookingTimeRange.end, + }, + bookingTimeRange.timeZone + ) : null; const expectedEmailContent = { @@ -244,9 +244,8 @@ expect.extend({ return; } - const expectedRrule = `FREQ=${ - expectedRecurrence.freq === 0 ? "YEARLY" : expectedRecurrence.freq === 1 ? "MONTHLY" : "WEEKLY" - };COUNT=${expectedRecurrence.count};INTERVAL=${expectedRecurrence.interval}`; + const expectedRrule = `FREQ=${expectedRecurrence.freq === 0 ? "YEARLY" : expectedRecurrence.freq === 1 ? "MONTHLY" : "WEEKLY" + };COUNT=${expectedRecurrence.count};INTERVAL=${expectedRecurrence.interval}`; logger.silly({ expectedRrule, @@ -395,24 +394,24 @@ export function expectSuccessfulBookingCreationEmails({ subHeading: "", links: recurrence ? [ - { - href: `${bookingUrlOrigin}/booking/${booking.uid}?cancel=true&allRemainingBookings=true`, - text: "cancel", - }, - ] + { + href: `${bookingUrlOrigin}/booking/${booking.uid}?cancel=true&allRemainingBookings=true`, + text: "cancel", + }, + ] : [ - { - href: `${bookingUrlOrigin}/reschedule/${booking.uid}`, - text: "reschedule", - }, - ], + { + href: `${bookingUrlOrigin}/reschedule/${booking.uid}`, + text: "reschedule", + }, + ], ...(bookingTimeRange ? { - bookingTimeRange: { - ...bookingTimeRange, - timeZone: organizer.timeZone, - }, - } + bookingTimeRange: { + ...bookingTimeRange, + timeZone: organizer.timeZone, + }, + } : null), to: `${destinationEmail ?? organizer.email}`, ics: { @@ -432,12 +431,12 @@ export function expectSuccessfulBookingCreationEmails({ subHeading: "emailed_you_and_any_other_attendees", ...(bookingTimeRange ? { - bookingTimeRange: { - ...bookingTimeRange, - // Using the default timezone - timeZone: booker.timeZone || DEFAULT_TIMEZONE_BOOKER, - }, - } + bookingTimeRange: { + ...bookingTimeRange, + // Using the default timezone + timeZone: booker.timeZone || DEFAULT_TIMEZONE_BOOKER, + }, + } : null), to: `${booker.name} <${booker.email}>`, ics: { @@ -448,17 +447,17 @@ export function expectSuccessfulBookingCreationEmails({ }, links: recurrence ? [ - { - href: `${bookingUrlOrigin}/booking/${booking.uid}?cancel=true&allRemainingBookings=true`, - text: "cancel", - }, - ] + { + href: `${bookingUrlOrigin}/booking/${booking.uid}?cancel=true&allRemainingBookings=true`, + text: "cancel", + }, + ] : [ - { - href: `${bookingUrlOrigin}/reschedule/${booking.uid}`, - text: "reschedule", - }, - ], + { + href: `${bookingUrlOrigin}/reschedule/${booking.uid}`, + text: "reschedule", + }, + ], }, `${booker.name} <${booker.email}>` ); @@ -472,11 +471,11 @@ export function expectSuccessfulBookingCreationEmails({ subHeading: "", ...(bookingTimeRange ? { - bookingTimeRange: { - ...bookingTimeRange, - timeZone: otherTeamMember.timeZone || DEFAULT_TIMEZONE_BOOKER, - }, - } + bookingTimeRange: { + ...bookingTimeRange, + timeZone: otherTeamMember.timeZone || DEFAULT_TIMEZONE_BOOKER, + }, + } : null), // Don't know why but organizer and team members of the eventType don'thave their name here like Booker to: `${otherTeamMember.email}`, @@ -510,11 +509,11 @@ export function expectSuccessfulBookingCreationEmails({ subHeading: "emailed_you_and_any_other_attendees", ...(bookingTimeRange ? { - bookingTimeRange: { - ...bookingTimeRange, - timeZone: guest.timeZone || DEFAULT_TIMEZONE_BOOKER, - }, - } + bookingTimeRange: { + ...bookingTimeRange, + timeZone: guest.timeZone || DEFAULT_TIMEZONE_BOOKER, + }, + } : null), to: `${guest.email}`, ics: { @@ -941,6 +940,45 @@ 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, @@ -982,15 +1020,15 @@ export function expectSuccessfulCalendarEventCreationInCalendar( }, expected: | { - calendarId?: string | null; - videoCallUrl: string; - destinationCalendars?: Partial[]; - } + calendarId?: string | null; + videoCallUrl: string; + destinationCalendars?: Partial[]; + } | { - calendarId?: string | null; - videoCallUrl: string; - destinationCalendars?: Partial[]; - }[] + calendarId?: string | null; + videoCallUrl: string; + destinationCalendars?: Partial[]; + }[] ) { const expecteds = expected instanceof Array ? expected : [expected]; expect(calendarMock.createEventCalls.length).toBe(expecteds.length); @@ -1003,13 +1041,13 @@ export function expectSuccessfulCalendarEventCreationInCalendar( expect.objectContaining({ destinationCalendar: expected.calendarId ? [ - expect.objectContaining({ - externalId: expected.calendarId, - }), - ] + expect.objectContaining({ + externalId: expected.calendarId, + }), + ] : expected.destinationCalendars - ? expect.arrayContaining(expected.destinationCalendars.map((cal) => expect.objectContaining(cal))) - : null, + ? expect.arrayContaining(expected.destinationCalendars.map((cal) => expect.objectContaining(cal))) + : null, videoCallData: expect.objectContaining({ url: expected.videoCallUrl, }),