@@ -26,11 +26,14 @@ describe("CalendarEventBuilder", () => {
26
26
} )
27
27
. build ( ) ;
28
28
29
- expect ( event . bookerUrl ) . toBe ( "https://cal.com/user/test-slug" ) ;
30
- expect ( event . title ) . toBe ( "Test Event" ) ;
31
- expect ( event . startTime ) . toBe ( mockStartTime ) ;
32
- expect ( event . endTime ) . toBe ( mockEndTime ) ;
33
- expect ( event . additionalNotes ) . toBe ( "Some notes" ) ;
29
+ expect ( event ) . not . toBeNull ( ) ;
30
+ if ( event ) {
31
+ expect ( event . bookerUrl ) . toBe ( "https://cal.com/user/test-slug" ) ;
32
+ expect ( event . title ) . toBe ( "Test Event" ) ;
33
+ expect ( event . startTime ) . toBe ( mockStartTime ) ;
34
+ expect ( event . endTime ) . toBe ( mockEndTime ) ;
35
+ expect ( event . additionalNotes ) . toBe ( "Some notes" ) ;
36
+ }
34
37
} ) ;
35
38
36
39
it ( "should create an event with event type details" , ( ) => {
@@ -50,11 +53,14 @@ describe("CalendarEventBuilder", () => {
50
53
} )
51
54
. build ( ) ;
52
55
53
- expect ( event . type ) . toBe ( "test-slug" ) ;
54
- expect ( event . description ) . toBe ( "Test description" ) ;
55
- expect ( event . eventTypeId ) . toBe ( 123 ) ;
56
- expect ( event . hideCalendarNotes ) . toBe ( true ) ;
57
- expect ( event . hideCalendarEventDetails ) . toBe ( false ) ;
56
+ expect ( event ) . not . toBeNull ( ) ;
57
+ if ( event ) {
58
+ expect ( event . type ) . toBe ( "test-slug" ) ;
59
+ expect ( event . description ) . toBe ( "Test description" ) ;
60
+ expect ( event . eventTypeId ) . toBe ( 123 ) ;
61
+ expect ( event . hideCalendarNotes ) . toBe ( true ) ;
62
+ expect ( event . hideCalendarEventDetails ) . toBe ( false ) ;
63
+ }
58
64
} ) ;
59
65
60
66
it ( "should create an event with organizer details" , ( ) => {
@@ -82,17 +88,20 @@ describe("CalendarEventBuilder", () => {
82
88
} )
83
89
. build ( ) ;
84
90
85
- expect ( event . organizer ) . toEqual ( {
86
- id : 456 ,
87
- name : "John Doe" ,
88
-
89
- username : "johndoe" ,
90
- timeZone : "America/New_York" ,
91
- language : {
92
- translate : mockTranslate ,
93
- locale : "en" ,
94
- } ,
95
- } ) ;
91
+ expect ( event ) . not . toBeNull ( ) ;
92
+ if ( event ) {
93
+ expect ( event . organizer ) . toEqual ( {
94
+ id : 456 ,
95
+ name : "John Doe" ,
96
+
97
+ username : "johndoe" ,
98
+ timeZone : "America/New_York" ,
99
+ language : {
100
+ translate : mockTranslate ,
101
+ locale : "en" ,
102
+ } ,
103
+ } ) ;
104
+ }
96
105
} ) ;
97
106
98
107
it ( "should handle nameless organizer" , ( ) => {
@@ -119,7 +128,10 @@ describe("CalendarEventBuilder", () => {
119
128
} )
120
129
. build ( ) ;
121
130
122
- expect ( event . organizer . name ) . toBe ( "Nameless" ) ;
131
+ expect ( event ) . not . toBeNull ( ) ;
132
+ if ( event ) {
133
+ expect ( event . organizer . name ) . toBe ( "Nameless" ) ;
134
+ }
123
135
} ) ;
124
136
125
137
it ( "should create an event with attendees" , ( ) => {
@@ -158,7 +170,10 @@ describe("CalendarEventBuilder", () => {
158
170
. withAttendees ( attendees )
159
171
. build ( ) ;
160
172
161
- expect ( event . attendees ) . toEqual ( attendees ) ;
173
+ expect ( event ) . not . toBeNull ( ) ;
174
+ if ( event ) {
175
+ expect ( event . attendees ) . toEqual ( attendees ) ;
176
+ }
162
177
} ) ;
163
178
164
179
it ( "should create an event with metadata and responses" , ( ) => {
@@ -192,10 +207,13 @@ describe("CalendarEventBuilder", () => {
192
207
} )
193
208
. build ( ) ;
194
209
195
- expect ( event . additionalNotes ) . toBe ( "Some notes" ) ;
196
- expect ( event . customInputs ) . toEqual ( customInputs ) ;
197
- expect ( event . responses ) . toEqual ( responses ) ;
198
- expect ( event . userFieldsResponses ) . toEqual ( userFieldsResponses ) ;
210
+ expect ( event ) . not . toBeNull ( ) ;
211
+ if ( event ) {
212
+ expect ( event . additionalNotes ) . toBe ( "Some notes" ) ;
213
+ expect ( event . customInputs ) . toEqual ( customInputs ) ;
214
+ expect ( event . responses ) . toEqual ( responses ) ;
215
+ expect ( event . userFieldsResponses ) . toEqual ( userFieldsResponses ) ;
216
+ }
199
217
} ) ;
200
218
201
219
it ( "should create an event with location" , ( ) => {
@@ -216,8 +234,11 @@ describe("CalendarEventBuilder", () => {
216
234
} )
217
235
. build ( ) ;
218
236
219
- expect ( event . location ) . toBe ( "Conference Room A" ) ;
220
- expect ( event . conferenceCredentialId ) . toBe ( 789 ) ;
237
+ expect ( event ) . not . toBeNull ( ) ;
238
+ if ( event ) {
239
+ expect ( event . location ) . toBe ( "Conference Room A" ) ;
240
+ expect ( event . conferenceCredentialId ) . toBe ( 789 ) ;
241
+ }
221
242
} ) ;
222
243
223
244
it ( "should create an event with destination calendar" , ( ) => {
@@ -229,6 +250,8 @@ describe("CalendarEventBuilder", () => {
229
250
userId : null ,
230
251
eventTypeId : null ,
231
252
credentialId : null ,
253
+ createdAt : null ,
254
+ updatedAt : null ,
232
255
delegationCredentialId : null ,
233
256
domainWideDelegationCredentialId : null ,
234
257
} ;
@@ -247,7 +270,10 @@ describe("CalendarEventBuilder", () => {
247
270
. withDestinationCalendar ( [ destinationCalendar ] )
248
271
. build ( ) ;
249
272
250
- expect ( event . destinationCalendar ) . toEqual ( [ destinationCalendar ] ) ;
273
+ expect ( event ) . not . toBeNull ( ) ;
274
+ if ( event ) {
275
+ expect ( event . destinationCalendar ) . toEqual ( [ destinationCalendar ] ) ;
276
+ }
251
277
} ) ;
252
278
253
279
it ( "should create an event with identifiers" , ( ) => {
@@ -268,8 +294,11 @@ describe("CalendarEventBuilder", () => {
268
294
} )
269
295
. build ( ) ;
270
296
271
- expect ( event . iCalUID ) . toBe ( "ical-123" ) ;
272
- expect ( event . iCalSequence ) . toBe ( 2 ) ;
297
+ expect ( event ) . not . toBeNull ( ) ;
298
+ if ( event ) {
299
+ expect ( event . iCalUID ) . toBe ( "ical-123" ) ;
300
+ expect ( event . iCalSequence ) . toBe ( 2 ) ;
301
+ }
273
302
} ) ;
274
303
275
304
it ( "should create an event with confirmation settings" , ( ) => {
@@ -290,8 +319,11 @@ describe("CalendarEventBuilder", () => {
290
319
} )
291
320
. build ( ) ;
292
321
293
- expect ( event . requiresConfirmation ) . toBe ( true ) ;
294
- expect ( event . oneTimePassword ) . toBeUndefined ( ) ;
322
+ expect ( event ) . not . toBeNull ( ) ;
323
+ if ( event ) {
324
+ expect ( event . requiresConfirmation ) . toBe ( true ) ;
325
+ expect ( event . oneTimePassword ) . toBeUndefined ( ) ;
326
+ }
295
327
} ) ;
296
328
297
329
it ( "should set oneTimePassword to null when isConfirmedByDefault is true" , ( ) => {
@@ -312,8 +344,11 @@ describe("CalendarEventBuilder", () => {
312
344
} )
313
345
. build ( ) ;
314
346
315
- expect ( event . requiresConfirmation ) . toBe ( true ) ;
316
- expect ( event . oneTimePassword ) . toBeNull ( ) ;
347
+ expect ( event ) . not . toBeNull ( ) ;
348
+ if ( event ) {
349
+ expect ( event . requiresConfirmation ) . toBe ( true ) ;
350
+ expect ( event . oneTimePassword ) . toBeNull ( ) ;
351
+ }
317
352
} ) ;
318
353
319
354
it ( "should create an event with platform variables" , ( ) => {
@@ -336,10 +371,13 @@ describe("CalendarEventBuilder", () => {
336
371
} )
337
372
. build ( ) ;
338
373
339
- expect ( event . platformClientId ) . toBe ( "client-123" ) ;
340
- expect ( event . platformRescheduleUrl ) . toBe ( "https://platform.com/reschedule" ) ;
341
- expect ( event . platformCancelUrl ) . toBe ( "https://platform.com/cancel" ) ;
342
- expect ( event . platformBookingUrl ) . toBe ( "https://platform.com/booking" ) ;
374
+ expect ( event ) . not . toBeNull ( ) ;
375
+ if ( event ) {
376
+ expect ( event . platformClientId ) . toBe ( "client-123" ) ;
377
+ expect ( event . platformRescheduleUrl ) . toBe ( "https://platform.com/reschedule" ) ;
378
+ expect ( event . platformCancelUrl ) . toBe ( "https://platform.com/cancel" ) ;
379
+ expect ( event . platformBookingUrl ) . toBe ( "https://platform.com/booking" ) ;
380
+ }
343
381
} ) ;
344
382
345
383
it ( "should create an event with apps status" , ( ) => {
@@ -376,7 +414,10 @@ describe("CalendarEventBuilder", () => {
376
414
. withAppsStatus ( appsStatus )
377
415
. build ( ) ;
378
416
379
- expect ( event . appsStatus ) . toEqual ( appsStatus ) ;
417
+ expect ( event ) . not . toBeNull ( ) ;
418
+ if ( event ) {
419
+ expect ( event . appsStatus ) . toEqual ( appsStatus ) ;
420
+ }
380
421
} ) ;
381
422
382
423
it ( "should create an event with video call data" , ( ) => {
@@ -401,7 +442,10 @@ describe("CalendarEventBuilder", () => {
401
442
. withVideoCallData ( videoCallData )
402
443
. build ( ) ;
403
444
404
- expect ( event . videoCallData ) . toEqual ( videoCallData ) ;
445
+ expect ( event ) . not . toBeNull ( ) ;
446
+ if ( event ) {
447
+ expect ( event . videoCallData ) . toEqual ( videoCallData ) ;
448
+ }
405
449
} ) ;
406
450
407
451
it ( "should create an event with team information" , ( ) => {
@@ -435,7 +479,10 @@ describe("CalendarEventBuilder", () => {
435
479
. withTeam ( team )
436
480
. build ( ) ;
437
481
438
- expect ( event . team ) . toEqual ( team ) ;
482
+ expect ( event ) . not . toBeNull ( ) ;
483
+ if ( event ) {
484
+ expect ( event . team ) . toEqual ( team ) ;
485
+ }
439
486
} ) ;
440
487
441
488
it ( "should create an event with recurring event information" , ( ) => {
@@ -459,7 +506,10 @@ describe("CalendarEventBuilder", () => {
459
506
. withRecurring ( recurringEvent )
460
507
. build ( ) ;
461
508
462
- expect ( event . recurringEvent ) . toEqual ( recurringEvent ) ;
509
+ expect ( event ) . not . toBeNull ( ) ;
510
+ if ( event ) {
511
+ expect ( event . recurringEvent ) . toEqual ( recurringEvent ) ;
512
+ }
463
513
} ) ;
464
514
465
515
it ( "should create an event with attendee seat ID" , ( ) => {
@@ -477,7 +527,10 @@ describe("CalendarEventBuilder", () => {
477
527
. withAttendeeSeatId ( "seat-123" )
478
528
. build ( ) ;
479
529
480
- expect ( event . attendeeSeatId ) . toBe ( "seat-123" ) ;
530
+ expect ( event ) . not . toBeNull ( ) ;
531
+ if ( event ) {
532
+ expect ( event . attendeeSeatId ) . toBe ( "seat-123" ) ;
533
+ }
481
534
} ) ;
482
535
483
536
it ( "should create an event with UID" , ( ) => {
@@ -495,7 +548,10 @@ describe("CalendarEventBuilder", () => {
495
548
. withUid ( "booking-uid-123" )
496
549
. build ( ) ;
497
550
498
- expect ( event . uid ) . toBe ( "booking-uid-123" ) ;
551
+ expect ( event ) . not . toBeNull ( ) ;
552
+ if ( event ) {
553
+ expect ( event . uid ) . toBe ( "booking-uid-123" ) ;
554
+ }
499
555
} ) ;
500
556
501
557
it ( "should create an event with one-time password" , ( ) => {
@@ -513,7 +569,10 @@ describe("CalendarEventBuilder", () => {
513
569
. withOneTimePassword ( "otp123" )
514
570
. build ( ) ;
515
571
516
- expect ( event . oneTimePassword ) . toBe ( "otp123" ) ;
572
+ expect ( event ) . not . toBeNull ( ) ;
573
+ if ( event ) {
574
+ expect ( event . oneTimePassword ) . toBe ( "otp123" ) ;
575
+ }
517
576
} ) ;
518
577
519
578
it ( "should create an event with recurring event ID" , ( ) => {
@@ -531,9 +590,12 @@ describe("CalendarEventBuilder", () => {
531
590
. withRecurringEventId ( "recurring-123" )
532
591
. build ( ) ;
533
592
534
- expect ( event . existingRecurringEvent ) . toEqual ( {
535
- recurringEventId : "recurring-123" ,
536
- } ) ;
593
+ expect ( event ) . not . toBeNull ( ) ;
594
+ if ( event ) {
595
+ expect ( event . existingRecurringEvent ) . toEqual ( {
596
+ recurringEventId : "recurring-123" ,
597
+ } ) ;
598
+ }
537
599
} ) ;
538
600
539
601
it ( "should create a complete calendar event with all properties" , ( ) => {
@@ -597,6 +659,8 @@ describe("CalendarEventBuilder", () => {
597
659
userId : 1 ,
598
660
eventTypeId : 123 ,
599
661
credentialId : 1 ,
662
+ createdAt : null ,
663
+ updatedAt : null ,
600
664
delegationCredentialId : null ,
601
665
domainWideDelegationCredentialId : null ,
602
666
} ,
@@ -644,26 +708,29 @@ describe("CalendarEventBuilder", () => {
644
708
. build ( ) ;
645
709
646
710
// Test that all properties are set correctly
647
- expect ( event . title ) . toBe ( "Complete Test Event" ) ;
648
- expect ( event . type ) . toBe ( "complete-test" ) ;
649
- expect ( event . organizer . name ) . toBe ( "John Doe" ) ;
650
- expect ( event . attendees ) . toHaveLength ( 1 ) ;
651
- expect ( event . location ) . toBe ( "Conference Room A" ) ;
652
- expect ( event . iCalUID ) . toBe ( "ical-123" ) ;
653
- expect ( event . requiresConfirmation ) . toBe ( true ) ;
654
- expect ( event . platformClientId ) . toBe ( "client-123" ) ;
655
- expect ( event . appsStatus ) . toHaveLength ( 1 ) ;
656
- expect ( event . videoCallData ?. url ) . toBe ( "https://meet.example.com/123" ) ;
657
- expect ( event . team ?. name ) . toBe ( "Engineering Team" ) ;
658
- expect ( event . recurringEvent ?. count ) . toBe ( 5 ) ;
659
- expect ( event . attendeeSeatId ) . toBe ( "seat-123" ) ;
660
- expect ( event . uid ) . toBe ( "booking-uid-123" ) ;
661
- expect ( event . oneTimePassword ) . toBe ( "otp123" ) ;
711
+ expect ( event ) . not . toBeNull ( ) ;
712
+ if ( event ) {
713
+ expect ( event . title ) . toBe ( "Complete Test Event" ) ;
714
+ expect ( event . type ) . toBe ( "complete-test" ) ;
715
+ expect ( event . organizer . name ) . toBe ( "John Doe" ) ;
716
+ expect ( event . attendees ) . toHaveLength ( 1 ) ;
717
+ expect ( event . location ) . toBe ( "Conference Room A" ) ;
718
+ expect ( event . iCalUID ) . toBe ( "ical-123" ) ;
719
+ expect ( event . requiresConfirmation ) . toBe ( true ) ;
720
+ expect ( event . platformClientId ) . toBe ( "client-123" ) ;
721
+ expect ( event . appsStatus ) . toHaveLength ( 1 ) ;
722
+ expect ( event . videoCallData ?. url ) . toBe ( "https://meet.example.com/123" ) ;
723
+ expect ( event . team ?. name ) . toBe ( "Engineering Team" ) ;
724
+ expect ( event . recurringEvent ?. count ) . toBe ( 5 ) ;
725
+ expect ( event . attendeeSeatId ) . toBe ( "seat-123" ) ;
726
+ expect ( event . uid ) . toBe ( "booking-uid-123" ) ;
727
+ expect ( event . oneTimePassword ) . toBe ( "otp123" ) ;
728
+ }
662
729
} ) ;
663
730
664
- it ( "should throw an error when building without required fields" , ( ) => {
731
+ it ( "should return null when building without required fields" , ( ) => {
665
732
const builder = new CalendarEventBuilder ( ) ;
666
- expect ( ( ) => builder . build ( ) ) . toThrow ( "Missing required fields for calendar event" ) ;
733
+ expect ( builder . build ( ) ) . toBeNull ( ) ;
667
734
} ) ;
668
735
669
736
it ( "should create an event from an existing event" , ( ) => {
@@ -684,8 +751,11 @@ describe("CalendarEventBuilder", () => {
684
751
} )
685
752
. build ( ) ;
686
753
687
- expect ( event . title ) . toBe ( "Updated Event" ) ;
688
- expect ( event . type ) . toBe ( "existing-type" ) ;
754
+ expect ( event ) . not . toBeNull ( ) ;
755
+ if ( event ) {
756
+ expect ( event . title ) . toBe ( "Updated Event" ) ;
757
+ expect ( event . type ) . toBe ( "existing-type" ) ;
758
+ }
689
759
} ) ;
690
760
691
761
it ( "should propagate disableCancelling and disableRescheduling" , ( ) => {
@@ -706,7 +776,10 @@ describe("CalendarEventBuilder", () => {
706
776
} )
707
777
. build ( ) ;
708
778
709
- expect ( event . disableCancelling ) . toBe ( true ) ;
710
- expect ( event . disableRescheduling ) . toBe ( true ) ;
779
+ expect ( event ) . not . toBeNull ( ) ;
780
+ if ( event ) {
781
+ expect ( event . disableCancelling ) . toBe ( true ) ;
782
+ expect ( event . disableRescheduling ) . toBe ( true ) ;
783
+ }
711
784
} ) ;
712
785
} ) ;
0 commit comments