11import nock from 'nock'
22import { Duffel } from '../index'
33import { MOCK_SEARCH_RESULT } from './mocks'
4+ import { StaysSearchParams } from './StaysTypes'
45
56const duffel = new Duffel ( { token : 'mockToken' } )
67describe ( 'Stays' , ( ) => {
@@ -10,7 +11,7 @@ describe('Stays', () => {
1011
1112 it ( 'should post location params to /stays/search when `search` is called' , async ( ) => {
1213 const mockResponse = { data : { results : [ MOCK_SEARCH_RESULT ] } }
13- const mockSearchParams = {
14+ const mockSearchParams : StaysSearchParams = {
1415 location : {
1516 radius : 5 ,
1617 geographic_coordinates : {
@@ -36,7 +37,7 @@ describe('Stays', () => {
3637
3738 it ( 'should post accommodation params to /stays/search when `search` is called' , async ( ) => {
3839 const mockResponse = { data : { results : [ MOCK_SEARCH_RESULT ] } }
39- const mockSearchParams = {
40+ const mockSearchParams : StaysSearchParams = {
4041 accommodation : {
4142 ids : [ 'acc_12345' ] ,
4243 fetch_rates : true ,
@@ -56,4 +57,63 @@ describe('Stays', () => {
5657 const response = await duffel . stays . search ( mockSearchParams )
5758 expect ( response . data ) . toEqual ( mockResponse . data )
5859 } )
60+
61+ it ( 'should alternatively accept `guests` with `accommodation` as a search criteria and post it to /stays/search' , async ( ) => {
62+ const mockResponse = { data : { results : [ MOCK_SEARCH_RESULT ] } }
63+ const mockSearchParams : StaysSearchParams = {
64+ accommodation : {
65+ ids : [ 'acc_12345' ] ,
66+ fetch_rates : true ,
67+ } ,
68+ check_in_date : '2023-10-20' ,
69+ check_out_date : '2023-10-24' ,
70+ guests : [
71+ { type : 'adult' } ,
72+ { type : 'adult' } ,
73+ { type : 'child' , age : 5 } ,
74+ { type : 'child' , age : 11 } ,
75+ ] ,
76+ rooms : 2 ,
77+ }
78+
79+ nock ( / ( .* ) / )
80+ . post ( '/stays/search' , ( body ) => {
81+ expect ( body . data ) . toEqual ( mockSearchParams )
82+ return true
83+ } )
84+ . reply ( 200 , mockResponse )
85+ const response = await duffel . stays . search ( mockSearchParams )
86+ expect ( response . data ) . toEqual ( mockResponse . data )
87+ } )
88+
89+ it ( 'should alternatively accept `guests` with `location` as a search criteria and post it to /stays/search' , async ( ) => {
90+ const mockResponse = { data : { results : [ MOCK_SEARCH_RESULT ] } }
91+ const mockSearchParams : StaysSearchParams = {
92+ location : {
93+ radius : 5 ,
94+ geographic_coordinates : {
95+ latitude : 40.73061 ,
96+ longitude : - 73.935242 ,
97+ } ,
98+ } ,
99+ check_in_date : '2023-10-20' ,
100+ check_out_date : '2023-10-24' ,
101+ guests : [
102+ { type : 'adult' } ,
103+ { type : 'adult' } ,
104+ { type : 'child' , age : 5 } ,
105+ { type : 'child' , age : 11 } ,
106+ ] ,
107+ rooms : 2 ,
108+ }
109+
110+ nock ( / ( .* ) / )
111+ . post ( '/stays/search' , ( body ) => {
112+ expect ( body . data ) . toEqual ( mockSearchParams )
113+ return true
114+ } )
115+ . reply ( 200 , mockResponse )
116+ const response = await duffel . stays . search ( mockSearchParams )
117+ expect ( response . data ) . toEqual ( mockResponse . data )
118+ } )
59119} )
0 commit comments