@@ -56,4 +56,63 @@ describe('Stays', () => {
5656 const response = await duffel . stays . search ( mockSearchParams )
5757 expect ( response . data ) . toEqual ( mockResponse . data )
5858 } )
59+
60+ it ( 'should alternatively accept `guests` with `accommodation` as a search criteria and post it to /stays/search' , async ( ) => {
61+ const mockResponse = { data : { results : [ MOCK_SEARCH_RESULT ] } }
62+ const mockSearchParams = {
63+ accommodation : {
64+ ids : [ 'acc_12345' ] ,
65+ fetch_rates : true ,
66+ } ,
67+ check_in_date : '2023-10-20' ,
68+ check_out_date : '2023-10-24' ,
69+ guests : [
70+ { type : 'adult' } ,
71+ { type : 'adult' } ,
72+ { type : 'child' , age : 5 } ,
73+ { type : 'child' , age : 11 } ,
74+ ] ,
75+ rooms : 2 ,
76+ }
77+
78+ nock ( / ( .* ) / )
79+ . post ( '/stays/search' , ( body ) => {
80+ expect ( body . data ) . toEqual ( mockSearchParams )
81+ return true
82+ } )
83+ . reply ( 200 , mockResponse )
84+ const response = await duffel . stays . search ( mockSearchParams )
85+ expect ( response . data ) . toEqual ( mockResponse . data )
86+ } )
87+
88+ it ( 'should alternatively accept `guests` with `location` as a search criteria and post it to /stays/search' , async ( ) => {
89+ const mockResponse = { data : { results : [ MOCK_SEARCH_RESULT ] } }
90+ const mockSearchParams = {
91+ location : {
92+ radius : 5 ,
93+ geographic_coordinates : {
94+ latitude : 40.73061 ,
95+ longitude : - 73.935242 ,
96+ } ,
97+ } ,
98+ check_in_date : '2023-10-20' ,
99+ check_out_date : '2023-10-24' ,
100+ guests : [
101+ { type : 'adult' } ,
102+ { type : 'adult' } ,
103+ { type : 'child' , age : 5 } ,
104+ { type : 'child' , age : 11 } ,
105+ ] ,
106+ rooms : 2 ,
107+ }
108+
109+ nock ( / ( .* ) / )
110+ . post ( '/stays/search' , ( body ) => {
111+ expect ( body . data ) . toEqual ( mockSearchParams )
112+ return true
113+ } )
114+ . reply ( 200 , mockResponse )
115+ const response = await duffel . stays . search ( mockSearchParams )
116+ expect ( response . data ) . toEqual ( mockResponse . data )
117+ } )
59118} )
0 commit comments