@@ -66,6 +66,8 @@ describe("Organizations Bookings Endpoints 2024-08-13", () => {
6666 let orgEventTypeId2 : number ;
6767 let nonOrgEventTypeId : number ;
6868
69+ let collectiveOrgBookingUid : string ;
70+
6971 beforeAll ( async ( ) => {
7072 const moduleRef = await withApiAuth (
7173 orgUserEmail2 ,
@@ -91,12 +93,17 @@ describe("Organizations Bookings Endpoints 2024-08-13", () => {
9193 schedulesService = moduleRef . get < SchedulesService_2024_04_15 > ( SchedulesService_2024_04_15 ) ;
9294
9395 organization = await organizationsRepositoryFixture . create ( { name : "organization bookings" } ) ;
96+ oAuthClient = await createOAuthClient ( organization . id ) ;
9497 team1 = await teamRepositoryFixture . create ( {
9598 name : "team orgs booking 1" ,
9699 isOrganization : false ,
97100 parent : { connect : { id : organization . id } } ,
101+ createdByOAuthClient : {
102+ connect : {
103+ id : oAuthClient . id ,
104+ } ,
105+ } ,
98106 } ) ;
99- oAuthClient = await createOAuthClient ( organization . id ) ;
100107
101108 nonOrgUser1 = await userRepositoryFixture . create ( {
102109 email : nonOrgUserEmail1 ,
@@ -315,6 +322,7 @@ describe("Organizations Bookings Endpoints 2024-08-13", () => {
315322
316323 if ( responseDataIsBooking ( responseBody . data ) ) {
317324 const data : BookingOutput_2024_08_13 = responseBody . data ;
325+ collectiveOrgBookingUid = data . uid ;
318326 expect ( data . id ) . toBeDefined ( ) ;
319327 expect ( data . uid ) . toBeDefined ( ) ;
320328 expect ( data . hosts . length ) . toEqual ( 1 ) ;
@@ -669,6 +677,125 @@ describe("Organizations Bookings Endpoints 2024-08-13", () => {
669677 ) ;
670678 } ) ;
671679 } ) ;
680+
681+ describe ( "get by bookingUid param" , ( ) => {
682+ it ( "should get a specific booking by bookingUid query param" , async ( ) => {
683+ return request ( app . getHttpServer ( ) )
684+ . get ( `/v2/organizations/${ organization . id } /bookings?bookingUid=${ collectiveOrgBookingUid } ` )
685+ . set ( CAL_API_VERSION_HEADER , VERSION_2024_08_13 )
686+ . set ( X_CAL_CLIENT_ID , oAuthClient . id )
687+ . set ( X_CAL_SECRET_KEY , oAuthClient . secret )
688+ . expect ( 200 )
689+ . then ( async ( response ) => {
690+ const responseBody : GetBookingsOutput_2024_08_13 = response . body ;
691+ expect ( responseBody . status ) . toEqual ( SUCCESS_STATUS ) ;
692+ expect ( responseBody . data ) . toBeDefined ( ) ;
693+
694+ const data : (
695+ | BookingOutput_2024_08_13
696+ | RecurringBookingOutput_2024_08_13
697+ | GetSeatedBookingOutput_2024_08_13
698+ ) [ ] = responseBody . data ;
699+ expect ( data . length ) . toEqual ( 1 ) ;
700+ expect ( responseDataIsBooking ( data [ 0 ] ) ) . toBe ( true ) ;
701+
702+ if ( responseDataIsBooking ( data [ 0 ] ) ) {
703+ const booking : BookingOutput_2024_08_13 = data [ 0 ] ;
704+ expect ( booking . uid ) . toEqual ( collectiveOrgBookingUid ) ;
705+ expect ( booking . eventTypeId ) . toEqual ( orgEventTypeId ) ;
706+ expect ( booking . status ) . toEqual ( "accepted" ) ;
707+ expect ( booking . attendees . length ) . toEqual ( 2 ) ;
708+ expect ( booking . attendees [ 0 ] . name ) . toEqual ( "alice" ) ;
709+ expect ( booking . attendees [ 0 ] . email ) . toEqual ( "alice@gmail.com" ) ;
710+ } else {
711+ throw new Error ( "Expected single booking but received different response type" ) ;
712+ }
713+ } ) ;
714+ } ) ;
715+
716+ it ( "should return empty array for non-existent booking UID query param" , async ( ) => {
717+ const nonExistentUid = "non-existent-booking-uid" ;
718+
719+ return request ( app . getHttpServer ( ) )
720+ . get ( `/v2/organizations/${ organization . id } /bookings?bookingUid=${ nonExistentUid } ` )
721+ . set ( CAL_API_VERSION_HEADER , VERSION_2024_08_13 )
722+ . set ( X_CAL_CLIENT_ID , oAuthClient . id )
723+ . set ( X_CAL_SECRET_KEY , oAuthClient . secret )
724+ . expect ( 200 )
725+ . then ( async ( response ) => {
726+ const responseBody : GetBookingsOutput_2024_08_13 = response . body ;
727+ expect ( responseBody . status ) . toEqual ( SUCCESS_STATUS ) ;
728+ expect ( responseBody . data ) . toBeDefined ( ) ;
729+ expect ( responseBody . data . length ) . toEqual ( 0 ) ;
730+ } ) ;
731+ } ) ;
732+
733+ it ( "should return empty array for booking UID not belonging to the organization" , async ( ) => {
734+ const regularUser = await userRepositoryFixture . create ( {
735+ email : `org-bookings-regular-user-${ Math . floor ( Math . random ( ) * 10000 ) } @api.com` ,
736+ name : "Regular User" ,
737+ } ) ;
738+
739+ const regularUserEventType = await eventTypesRepositoryFixture . create (
740+ {
741+ title : `regular-user-event-type-${ Math . floor ( Math . random ( ) * 10000 ) } ` ,
742+ slug : `regular-user-event-type-${ Math . floor ( Math . random ( ) * 10000 ) } ` ,
743+ length : 60 ,
744+ bookingFields : [ ] ,
745+ locations : [ ] ,
746+ } ,
747+ regularUser . id
748+ ) ;
749+
750+ const regularUserBooking = await bookingsRepositoryFixture . create ( {
751+ user : {
752+ connect : {
753+ id : regularUser . id ,
754+ } ,
755+ } ,
756+ startTime : new Date ( Date . UTC ( 2030 , 0 , 15 , 13 , 0 , 0 ) ) ,
757+ endTime : new Date ( Date . UTC ( 2030 , 0 , 15 , 14 , 0 , 0 ) ) ,
758+ title : "Regular user booking" ,
759+ uid : `regular-user-booking-${ Math . floor ( Math . random ( ) * 10000 ) } ` ,
760+ eventType : {
761+ connect : {
762+ id : regularUserEventType . id ,
763+ } ,
764+ } ,
765+ location : "https://meet.google.com/regular-user" ,
766+ customInputs : { } ,
767+ metadata : { } ,
768+ status : "ACCEPTED" ,
769+ responses : {
770+ name : "Regular Attendee" ,
771+ email : "regular@example.com" ,
772+ } ,
773+ attendees : {
774+ create : {
775+ email : "regular@example.com" ,
776+ name : "Regular Attendee" ,
777+ locale : "en" ,
778+ timeZone : "Europe/Rome" ,
779+ } ,
780+ } ,
781+ } ) ;
782+
783+ return request ( app . getHttpServer ( ) )
784+ . get ( `/v2/organizations/${ organization . id } /bookings?bookingUid=${ regularUserBooking . uid } ` )
785+ . set ( CAL_API_VERSION_HEADER , VERSION_2024_08_13 )
786+ . set ( X_CAL_CLIENT_ID , oAuthClient . id )
787+ . set ( X_CAL_SECRET_KEY , oAuthClient . secret )
788+ . expect ( 200 )
789+ . then ( async ( response ) => {
790+ const responseBody : GetBookingsOutput_2024_08_13 = response . body ;
791+ expect ( responseBody . status ) . toEqual ( SUCCESS_STATUS ) ;
792+ expect ( responseBody . data ) . toBeDefined ( ) ;
793+ expect ( responseBody . data . length ) . toEqual ( 0 ) ;
794+
795+ await userRepositoryFixture . delete ( regularUser . id ) ;
796+ } ) ;
797+ } ) ;
798+ } ) ;
672799 } ) ;
673800
674801 async function createOAuthClient ( organizationId : number ) {
0 commit comments