Scheduling infrastructure for absolutely everyone.
fix: cancel workflow (#26915)
Anik Dhabal Babu04c9453d5c6d
diff --git a/packages/features/bookings/lib/handleCancelBooking.ts b/packages/features/bookings/lib/handleCancelBooking.tsindex c579edae99a..483b9e919c5 100644--- a/packages/features/bookings/lib/handleCancelBooking.ts+++ b/packages/features/bookings/lib/handleCancelBooking.ts@@ -402,6 +402,7 @@ async function handler(input: CancelBookingInput, dependencies?: Dependencies) {platformBookingUrl,customReplyToEmail: bookingToDelete.eventType?.customReplyToEmail,organizationId: ownerProfile?.organizationId ?? null,+ schedulingType: bookingToDelete.eventType?.schedulingType,};const dataForWebhooks = { evt, webhooks, eventTypeInfo };diff --git a/packages/features/bookings/lib/handleCancelBooking/test/handleCancelBooking.test.ts b/packages/features/bookings/lib/handleCancelBooking/test/handleCancelBooking.test.tsindex e1c15fddaac..9bbe4784126 100644--- a/packages/features/bookings/lib/handleCancelBooking/test/handleCancelBooking.test.ts+++ b/packages/features/bookings/lib/handleCancelBooking/test/handleCancelBooking.test.ts@@ -436,6 +436,145 @@ describe("Cancel Booking", () => {});});+ test("Should send EMAIL_HOST cancel workflow notification to both primary and secondary hosts in round robin events", async ({+ emails,+ }) => {+ const handleCancelBooking = (await import("@calcom/features/bookings/lib/handleCancelBooking")).default;++ const booker = getBooker({+ email: "[email protected]",+ name: "Booker",+ });++ const primaryHost = getOrganizer({+ name: "Primary Host",+ email: "[email protected]",+ id: 101,+ schedules: [TestData.schedules.IstWorkHours],+ credentials: [getGoogleCalendarCredential()],+ selectedCalendars: [TestData.selectedCalendars.google],+ });++ const secondaryHost = getOrganizer({+ name: "Secondary Host",+ email: "[email protected]",+ id: 102,+ schedules: [TestData.schedules.IstWorkHours],+ credentials: [getGoogleCalendarCredential()],+ selectedCalendars: [TestData.selectedCalendars.google],+ });++ const uidOfBookingToBeCancelled = "round-robin-email-host-workflow-uid";+ const idOfBookingToBeCancelled = 2040;+ const { dateString: plus1DateString } = getDate({ dateIncrement: 1 });++ await createBookingScenario(+ getScenarioData({+ eventTypes: [+ {+ id: 2,+ slotInterval: 30,+ length: 30,+ schedulingType: "ROUND_ROBIN",+ teamId: 1,+ users: [+ {+ id: 101,+ },+ {+ id: 102,+ },+ ],+ hosts: [+ {+ userId: 101,+ isFixed: false,+ },+ {+ userId: 102,+ isFixed: false,+ },+ ],+ },+ ],+ workflows: [+ {+ id: 1,+ name: "Cancel Email Host Workflow",+ teamId: 1,+ trigger: "EVENT_CANCELLED",+ action: "EMAIL_HOST",+ template: "REMINDER",+ activeOn: [2],+ },+ ],+ bookings: [+ {+ id: idOfBookingToBeCancelled,+ uid: uidOfBookingToBeCancelled,+ eventTypeId: 2,+ userId: 101,+ responses: {+ email: booker.email,+ name: booker.name,+ location: { optionValue: "", value: BookingLocations.CalVideo },+ },+ status: BookingStatus.ACCEPTED,+ startTime: `${plus1DateString}T05:00:00.000Z`,+ endTime: `${plus1DateString}T05:30:00.000Z`,+ attendees: [+ {+ email: booker.email,+ timeZone: "Asia/Kolkata",+ locale: "en",+ },+ {+ email: secondaryHost.email,+ timeZone: "Asia/Kolkata",+ locale: "en",+ },+ ],+ },+ ],+ users: [primaryHost, secondaryHost],+ apps: [TestData.apps["daily-video"]],+ })+ );++ mockSuccessfulVideoMeetingCreation({+ metadataLookupKey: "dailyvideo",+ videoMeetingData: {+ id: "MOCK_ID",+ password: "MOCK_PASS",+ url: `http://mock-dailyvideo.example.com/meeting-3`,+ },+ });++ mockCalendarToHaveNoBusySlots("googlecalendar", {+ create: {+ id: "MOCKED_GOOGLE_CALENDAR_EVENT_ID_3",+ },+ });++ const result = await handleCancelBooking({+ bookingData: {+ id: idOfBookingToBeCancelled,+ uid: uidOfBookingToBeCancelled,+ cancelledBy: primaryHost.email,+ cancellationReason: "Testing EMAIL_HOST workflow sends to secondary host in round robin",+ },+ });++ expect(result.success).toBe(true);+ expect(result.bookingId).toBe(idOfBookingToBeCancelled);+ expect(result.bookingUid).toBe(uidOfBookingToBeCancelled);++ expectWorkflowToBeTriggered({+ emailsToReceive: [primaryHost.email, secondaryHost.email],+ emails,+ });+ });+test("Should block cancelling past bookings", async () => {const handleCancelBooking = (await import("@calcom/features/bookings/lib/handleCancelBooking")).default;