1- import { beforeEach , describe , expect , test , vi } from "vitest" ;
2-
31import type { CalendarSubscriptionEventItem } from "@calcom/features/calendar-subscription/lib/CalendarSubscriptionPort.interface" ;
42import type { BookingRepository } from "@calcom/lib/server/repository/booking" ;
53import type { SelectedCalendar } from "@calcom/prisma/client" ;
6-
4+ import { beforeEach , describe , expect , test , vi } from "vitest" ;
75import { CalendarSyncService } from "../CalendarSyncService" ;
86
97const { mockHandleCancelBooking, mockCreateBooking } = vi . hoisted ( ( ) => ( {
@@ -206,6 +204,21 @@ describe("CalendarSyncService", () => {
206204 } ) ;
207205 } ) ;
208206
207+ test ( "should handle default Cal.diy iCalUID" , async ( ) => {
208+ const eventWithCalDiyUID : CalendarSubscriptionEventItem = {
209+ ...mockCalComEvent ,
210+ iCalUID : "test-booking-uid@Cal.diy" ,
211+ } ;
212+
213+ mockBookingRepository . findBookingByUidWithEventType = vi . fn ( ) . mockResolvedValue ( mockBooking ) ;
214+
215+ await service . handleEvents ( mockSelectedCalendar , [ eventWithCalDiyUID ] ) ;
216+
217+ expect ( mockBookingRepository . findBookingByUidWithEventType ) . toHaveBeenCalledWith ( {
218+ bookingUid : "test-booking-uid" ,
219+ } ) ;
220+ } ) ;
221+
209222 test ( "should handle events with null iCalUID" , async ( ) => {
210223 const eventWithNullUID : CalendarSubscriptionEventItem = {
211224 ...mockCalComEvent ,
@@ -279,7 +292,9 @@ describe("CalendarSyncService", () => {
279292 mockHandleCancelBooking . mockRejectedValue ( new Error ( "Cancellation failed" ) ) ;
280293
281294 // Should not throw - errors are caught and logged
282- await expect ( service . cancelBooking ( mockCancelledEvent , mockSelectedCalendar . userId ) ) . resolves . not . toThrow ( ) ;
295+ await expect (
296+ service . cancelBooking ( mockCancelledEvent , mockSelectedCalendar . userId )
297+ ) . resolves . not . toThrow ( ) ;
283298
284299 expect ( mockBookingRepository . findBookingByUidWithEventType ) . toHaveBeenCalled ( ) ;
285300 expect ( mockHandleCancelBooking ) . toHaveBeenCalled ( ) ;
@@ -290,7 +305,9 @@ describe("CalendarSyncService", () => {
290305 . fn ( )
291306 . mockRejectedValue ( new Error ( "DB connection failed" ) ) ;
292307
293- await expect ( service . cancelBooking ( mockCancelledEvent , mockSelectedCalendar . userId ) ) . resolves . not . toThrow ( ) ;
308+ await expect (
309+ service . cancelBooking ( mockCancelledEvent , mockSelectedCalendar . userId )
310+ ) . resolves . not . toThrow ( ) ;
294311
295312 expect ( mockBookingRepository . findBookingByUidWithEventType ) . toHaveBeenCalled ( ) ;
296313 expect ( mockHandleCancelBooking ) . not . toHaveBeenCalled ( ) ;
@@ -489,7 +506,9 @@ describe("CalendarSyncService", () => {
489506 mockCreateBooking . mockRejectedValue ( new Error ( "Rescheduling failed" ) ) ;
490507
491508 // Should not throw - errors are caught and logged
492- await expect ( service . rescheduleBooking ( eventWithDifferentStart , mockSelectedCalendar . userId ) ) . resolves . not . toThrow ( ) ;
509+ await expect (
510+ service . rescheduleBooking ( eventWithDifferentStart , mockSelectedCalendar . userId )
511+ ) . resolves . not . toThrow ( ) ;
493512
494513 expect ( mockBookingRepository . findBookingByUidWithEventType ) . toHaveBeenCalled ( ) ;
495514 expect ( mockCreateBooking ) . toHaveBeenCalled ( ) ;
@@ -500,7 +519,9 @@ describe("CalendarSyncService", () => {
500519 . fn ( )
501520 . mockRejectedValue ( new Error ( "DB connection failed" ) ) ;
502521
503- await expect ( service . rescheduleBooking ( mockCalComEvent , mockSelectedCalendar . userId ) ) . resolves . not . toThrow ( ) ;
522+ await expect (
523+ service . rescheduleBooking ( mockCalComEvent , mockSelectedCalendar . userId )
524+ ) . resolves . not . toThrow ( ) ;
504525
505526 expect ( mockBookingRepository . findBookingByUidWithEventType ) . toHaveBeenCalled ( ) ;
506527 expect ( mockCreateBooking ) . not . toHaveBeenCalled ( ) ;
0 commit comments