Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/features/bookings/lib/handleCancelBooking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ async function handler(input: CancelBookingInput, dependencies?: Dependencies) {
isPlatformManagedUserBooking: bookingToDelete.user.isPlatformManaged,
} satisfies HandleCancelBookingResponse;

const parsedMetadata = bookingMetadataSchema.safeParse(bookingToDelete.metadata || {});

const promises = webhooks.map((webhook) =>
sendPayload(webhook.secret, eventTrigger, new Date().toISOString(), webhook, {
...evt,
Expand All @@ -431,6 +433,7 @@ async function handler(input: CancelBookingInput, dependencies?: Dependencies) {
smsReminderNumber: bookingToDelete.smsReminderNumber || undefined,
cancelledBy: cancelledBy,
requestReschedule: false,
...(parsedMetadata.success && parsedMetadata.data ? { metadata: parsedMetadata.data } : {}),
}).catch((e) => {
logger.error(
`Error executing webhook for event: ${eventTrigger}, URL: ${webhook.subscriberUrl}, bookingId: ${evt.bookingId}, bookingUid: ${evt.uid}`,
Expand All @@ -441,7 +444,6 @@ async function handler(input: CancelBookingInput, dependencies?: Dependencies) {
await Promise.all(promises);

const workflows = await getAllWorkflowsFromEventType(bookingToDelete.eventType, bookingToDelete.userId);
const parsedMetadata = bookingMetadataSchema.safeParse(bookingToDelete.metadata || {});

const creditService = new CreditService();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ describe("Cancel Booking", () => {
organizer,
location: BookingLocations.CalVideo,
subscriberUrl: "http://my-webhook.example.com",
metadata: {
videoCallUrl: "https://existing-daily-video-call-url.example.com",
},
payload: {
cancelledBy: organizer.email,
organizer: {
Expand Down Expand Up @@ -271,6 +274,9 @@ describe("Cancel Booking", () => {
organizer,
location: BookingLocations.CalVideo,
subscriberUrl: "http://my-webhook.example.com",
metadata: {
videoCallUrl: "https://existing-daily-video-call-url.example.com",
},
payload: {
cancelledBy: organizer.email,
organizer: {
Expand Down Expand Up @@ -375,6 +381,9 @@ describe("Cancel Booking", () => {
status: BookingStatus.ACCEPTED,
startTime: `${plus1DateString}T05:00:00.000Z`,
endTime: `${plus1DateString}T05:30:00.000Z`,
metadata: {
myCustomKey: "myCustomValue",
},
attendees: [
{
email: hostAttendee.email,
Expand Down Expand Up @@ -423,6 +432,9 @@ describe("Cancel Booking", () => {
organizer,
location: BookingLocations.CalVideo,
subscriberUrl: "http://my-webhook.example.com",
metadata: {
myCustomKey: "myCustomValue",
},
payload: {
cancelledBy: organizer.email,
organizer: {
Expand Down Expand Up @@ -1180,6 +1192,9 @@ describe("Cancel Booking", () => {
},
location: BookingLocations.CalVideo,
subscriberUrl: "http://my-webhook.example.com",
metadata: {
videoCallUrl: "https://existing-daily-video-call-url.example.com",
},
payload: {
cancelledBy: organizer.email,
organizer: {
Expand Down
4 changes: 3 additions & 1 deletion packages/testing/src/lib/bookingScenario/expects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1152,12 +1152,14 @@ export function expectBookingCancelledWebhookToHaveBeenFired({
location,
subscriberUrl,
payload,
metadata,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to include metadata in cancelled booking webhook payload or did you mean to just touch on tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include metadata in cancelled booking webhook payload

}: {
organizer: { email: string; name: string; username?: string; usernameInOrg?: string };
booker: { email: string; name: string };
subscriberUrl: string;
location: string;
payload?: Record<string, unknown>;
metadata?: Record<string, unknown> | null;
}) {
const organizerPayload = {
username: organizer.username,
Expand All @@ -1169,7 +1171,7 @@ export function expectBookingCancelledWebhookToHaveBeenFired({
payload: {
...payload,
organizer: organizerPayload,
metadata: null,
...(metadata !== undefined ? { metadata } : {}),
responses: {
name: {
label: "name",
Expand Down