@@ -12,6 +12,8 @@ import { NestExpressApplication } from "@nestjs/platform-express";
12
12
import { Test } from "@nestjs/testing" ;
13
13
import { User } from "@prisma/client" ;
14
14
import * as request from "supertest" ;
15
+ import { AttendeeRepositoryFixture } from "test/fixtures/repository/attendee.repository.fixture" ;
16
+ import { BookingSeatRepositoryFixture } from "test/fixtures/repository/booking-seat.repository.fixture" ;
15
17
import { BookingsRepositoryFixture } from "test/fixtures/repository/bookings.repository.fixture" ;
16
18
import { EventTypesRepositoryFixture } from "test/fixtures/repository/event-types.repository.fixture" ;
17
19
import { SelectedSlotsRepositoryFixture } from "test/fixtures/repository/selected-slots.repository.fixture" ;
@@ -250,6 +252,8 @@ describe("Slots Endpoints", () => {
250
252
let eventTypesRepositoryFixture : EventTypesRepositoryFixture ;
251
253
let selectedSlotsRepositoryFixture : SelectedSlotsRepositoryFixture ;
252
254
let bookingsRepositoryFixture : BookingsRepositoryFixture ;
255
+ let bookingSeatsRepositoryFixture : BookingSeatRepositoryFixture ;
256
+ let attendeesRepositoryFixture : AttendeeRepositoryFixture ;
253
257
254
258
const userEmail = `slots-${ randomString ( ) } -controller-e2e@api.com` ;
255
259
const userName = "bob" ;
@@ -258,6 +262,9 @@ describe("Slots Endpoints", () => {
258
262
let eventTypeSlug : string ;
259
263
let reservedSlotUid : string ;
260
264
265
+ const seatedEventTypeSlug = "peer-coding-seated" ;
266
+ let seatedEventTypeId : number ;
267
+
261
268
beforeAll ( async ( ) => {
262
269
const moduleRef = await withApiAuth (
263
270
userEmail ,
@@ -283,6 +290,8 @@ describe("Slots Endpoints", () => {
283
290
eventTypesRepositoryFixture = new EventTypesRepositoryFixture ( moduleRef ) ;
284
291
selectedSlotsRepositoryFixture = new SelectedSlotsRepositoryFixture ( moduleRef ) ;
285
292
bookingsRepositoryFixture = new BookingsRepositoryFixture ( moduleRef ) ;
293
+ bookingSeatsRepositoryFixture = new BookingSeatRepositoryFixture ( moduleRef ) ;
294
+ attendeesRepositoryFixture = new AttendeeRepositoryFixture ( moduleRef ) ;
286
295
287
296
user = await userRepositoryFixture . create ( {
288
297
email : userEmail ,
@@ -291,7 +300,7 @@ describe("Slots Endpoints", () => {
291
300
} ) ;
292
301
293
302
// nxte(Lauris): this creates default schedule monday to friday from 9AM to 5PM in Europe/Rome timezone
294
- const userSchedule = await schedulesService . createUserSchedule ( user . id , {
303
+ await schedulesService . createUserSchedule ( user . id , {
295
304
name : `slots-schedule-${ randomString ( ) } -slots.controller.e2e-spec` ,
296
305
timeZone : "Europe/Rome" ,
297
306
isDefault : true ,
@@ -306,9 +315,24 @@ describe("Slots Endpoints", () => {
306
315
} ,
307
316
user . id
308
317
) ;
318
+
309
319
eventTypeId = eventType . id ;
310
320
eventTypeSlug = eventType . slug ;
311
321
322
+ const seatedEvent = await eventTypesRepositoryFixture . create (
323
+ {
324
+ title : `slots-event-type-seated-${ randomString ( ) } -slots.controller.e2e-spec` ,
325
+ slug : `slots-event-type-seated-${ randomString ( ) } -slots.controller.e2e-spec` ,
326
+ length : 60 ,
327
+ seatsPerTimeSlot : 5 ,
328
+ seatsShowAttendees : true ,
329
+ seatsShowAvailabilityCount : true ,
330
+ locations : [ { type : "inPerson" , address : "via 10, rome, italy" } ] ,
331
+ } ,
332
+ user . id
333
+ ) ;
334
+ seatedEventTypeId = seatedEvent . id ;
335
+
312
336
app = moduleRef . createNestApplication ( ) ;
313
337
bootstrap ( app as NestExpressApplication ) ;
314
338
@@ -445,7 +469,7 @@ describe("Slots Endpoints", () => {
445
469
446
470
it ( "should do a booking and slot should not be available at that time" , async ( ) => {
447
471
const startTime = "2050-09-05T11:00:00.000Z" ;
448
- await bookingsRepositoryFixture . create ( {
472
+ const booking = await bookingsRepositoryFixture . create ( {
449
473
uid : `booking-uid-${ eventTypeId } ` ,
450
474
title : "booking title" ,
451
475
startTime,
@@ -486,6 +510,179 @@ describe("Slots Endpoints", () => {
486
510
expect ( slots ) . toEqual ( {
487
511
slots : { ...expectedSlotsUTC . slots , "2050-09-05" : expectedSlotsUTC2050_09_05 } ,
488
512
} ) ;
513
+
514
+ await bookingsRepositoryFixture . deleteById ( booking . id ) ;
515
+ } ) ;
516
+
517
+ it ( "should do a booking for seated event and slot should show attendees count and bookingUid" , async ( ) => {
518
+ const startTime = "2050-09-05T11:00:00.000Z" ;
519
+ const booking = await bookingsRepositoryFixture . create ( {
520
+ uid : `booking-uid-${ seatedEventTypeId } ` ,
521
+ title : "booking title" ,
522
+ startTime,
523
+ endTime : "2050-09-05T12:00:00.000Z" ,
524
+ eventType : {
525
+ connect : {
526
+ id : seatedEventTypeId ,
527
+ } ,
528
+ } ,
529
+ metadata : { } ,
530
+ responses : {
531
+ name : "tester" ,
532
+ email : "tester@example.com" ,
533
+ guests : [ ] ,
534
+ } ,
535
+ user : {
536
+ connect : {
537
+ id : user . id ,
538
+ } ,
539
+ } ,
540
+ } ) ;
541
+
542
+ const attendee = await attendeesRepositoryFixture . create ( {
543
+ name : "tester" ,
544
+ email : "tester@example.com" ,
545
+ timeZone : "Europe/London" ,
546
+ booking : {
547
+ connect : {
548
+ id : booking . id ,
549
+ } ,
550
+ } ,
551
+ } ) ;
552
+
553
+ bookingSeatsRepositoryFixture . create ( {
554
+ referenceUid : "100" ,
555
+ data : { } ,
556
+ booking : {
557
+ connect : {
558
+ id : booking . id ,
559
+ } ,
560
+ } ,
561
+ attendee : {
562
+ connect : {
563
+ id : attendee . id ,
564
+ } ,
565
+ } ,
566
+ } ) ;
567
+
568
+ const response = await request ( app . getHttpServer ( ) )
569
+ . get (
570
+ `/api/v2/slots/available?eventTypeId=${ seatedEventTypeId } &startTime=2050-09-05&endTime=2050-09-10`
571
+ )
572
+ . expect ( 200 ) ;
573
+
574
+ const responseBody = response . body ;
575
+ expect ( responseBody . status ) . toEqual ( SUCCESS_STATUS ) ;
576
+ const slots = responseBody . data ;
577
+
578
+ expect ( slots ) . toBeDefined ( ) ;
579
+ const days = Object . keys ( slots . slots ) ;
580
+ expect ( days . length ) . toEqual ( 5 ) ;
581
+
582
+ const expectedSlotsUTC2050_09_05 = [
583
+ { time : "2050-09-05T07:00:00.000Z" } ,
584
+ { time : "2050-09-05T08:00:00.000Z" } ,
585
+ { time : "2050-09-05T09:00:00.000Z" } ,
586
+ { time : "2050-09-05T10:00:00.000Z" } ,
587
+ { time : "2050-09-05T11:00:00.000Z" , attendees : 1 , bookingUid : booking . uid } ,
588
+ { time : "2050-09-05T12:00:00.000Z" } ,
589
+ { time : "2050-09-05T13:00:00.000Z" } ,
590
+ { time : "2050-09-05T14:00:00.000Z" } ,
591
+ ] ;
592
+
593
+ expect ( slots ) . toEqual ( {
594
+ slots : { ...expectedSlotsUTC . slots , "2050-09-05" : expectedSlotsUTC2050_09_05 } ,
595
+ } ) ;
596
+
597
+ await bookingsRepositoryFixture . deleteById ( booking . id ) ;
598
+ } ) ;
599
+
600
+ it ( "should do a booking for seated event and slot should show attendees count and bookingUid in range format" , async ( ) => {
601
+ const startTime = "2050-09-05T11:00:00.000Z" ;
602
+ const booking = await bookingsRepositoryFixture . create ( {
603
+ uid : `booking-uid-${ seatedEventTypeId } ` ,
604
+ title : "booking title" ,
605
+ startTime,
606
+ endTime : "2050-09-05T12:00:00.000Z" ,
607
+ eventType : {
608
+ connect : {
609
+ id : seatedEventTypeId ,
610
+ } ,
611
+ } ,
612
+ metadata : { } ,
613
+ responses : {
614
+ name : "tester" ,
615
+ email : "tester@example.com" ,
616
+ guests : [ ] ,
617
+ } ,
618
+ user : {
619
+ connect : {
620
+ id : user . id ,
621
+ } ,
622
+ } ,
623
+ } ) ;
624
+
625
+ const attendee = await attendeesRepositoryFixture . create ( {
626
+ name : "tester" ,
627
+ email : "tester@example.com" ,
628
+ timeZone : "Europe/London" ,
629
+ booking : {
630
+ connect : {
631
+ id : booking . id ,
632
+ } ,
633
+ } ,
634
+ } ) ;
635
+
636
+ bookingSeatsRepositoryFixture . create ( {
637
+ referenceUid : "100" ,
638
+ data : { } ,
639
+ booking : {
640
+ connect : {
641
+ id : booking . id ,
642
+ } ,
643
+ } ,
644
+ attendee : {
645
+ connect : {
646
+ id : attendee . id ,
647
+ } ,
648
+ } ,
649
+ } ) ;
650
+
651
+ const response = await request ( app . getHttpServer ( ) )
652
+ . get (
653
+ `/api/v2/slots/available?eventTypeId=${ seatedEventTypeId } &startTime=2050-09-05&endTime=2050-09-10&slotFormat=range`
654
+ )
655
+ . expect ( 200 ) ;
656
+
657
+ const responseBody = response . body ;
658
+ expect ( responseBody . status ) . toEqual ( SUCCESS_STATUS ) ;
659
+ const slots = responseBody . data ;
660
+
661
+ expect ( slots ) . toBeDefined ( ) ;
662
+ const days = Object . keys ( slots . slots ) ;
663
+ expect ( days . length ) . toEqual ( 5 ) ;
664
+
665
+ const expectedSlotsUTC2050_09_05 = [
666
+ { startTime : "2050-09-05T07:00:00.000Z" , endTime : "2050-09-05T08:00:00.000Z" } ,
667
+ { startTime : "2050-09-05T08:00:00.000Z" , endTime : "2050-09-05T09:00:00.000Z" } ,
668
+ { startTime : "2050-09-05T09:00:00.000Z" , endTime : "2050-09-05T10:00:00.000Z" } ,
669
+ { startTime : "2050-09-05T10:00:00.000Z" , endTime : "2050-09-05T11:00:00.000Z" } ,
670
+ {
671
+ startTime : "2050-09-05T11:00:00.000Z" ,
672
+ endTime : "2050-09-05T12:00:00.000Z" ,
673
+ attendees : 1 ,
674
+ bookingUid : booking . uid ,
675
+ } ,
676
+ { startTime : "2050-09-05T12:00:00.000Z" , endTime : "2050-09-05T13:00:00.000Z" } ,
677
+ { startTime : "2050-09-05T13:00:00.000Z" , endTime : "2050-09-05T14:00:00.000Z" } ,
678
+ { startTime : "2050-09-05T14:00:00.000Z" , endTime : "2050-09-05T15:00:00.000Z" } ,
679
+ ] ;
680
+
681
+ expect ( slots ) . toEqual ( {
682
+ slots : { ...expectedSlotsUTCRange . slots , "2050-09-05" : expectedSlotsUTC2050_09_05 } ,
683
+ } ) ;
684
+
685
+ await bookingsRepositoryFixture . deleteById ( booking . id ) ;
489
686
} ) ;
490
687
491
688
afterAll ( async ( ) => {
0 commit comments