Skip to content

Commit 3269016

Browse files
committed
feat: allow guests as payload and receive it in some responses
1 parent f139f09 commit 3269016

File tree

3 files changed

+81
-6
lines changed

3 files changed

+81
-6
lines changed

src/Stays/Stays.spec.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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
})

src/Stays/StaysTypes.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,12 @@ export interface StaysQuote {
530530
* The number of rooms this quote is for
531531
*/
532532
rooms: number
533+
534+
/*
535+
* A list of guests representing the requested occupancy for this quote
536+
*/
537+
538+
guests: Array<Guest>
533539
}
534540

535541
export type StaysBookingStatus = 'confirmed' | 'cancelled'
@@ -606,12 +612,19 @@ export interface StaysBooking {
606612
key_collection: StaysBookingKeyCollection | null
607613
}
608614

609-
interface CommonStaysSearchParams {
615+
export type Guest = {
616+
type: string
617+
age?: number
618+
}
619+
620+
type OccupancyCriteria = {
621+
rooms: number
622+
} & ({ adults: number } | { guests: Array<Guest> })
623+
624+
type CommonStaysSearchParams = {
610625
check_in_date: string
611626
check_out_date: string
612-
adults: number
613-
rooms: number
614-
}
627+
} & OccupancyCriteria
615628

616629
type LocationSearchParams = {
617630
location: {
@@ -639,4 +652,5 @@ export interface StaysSearchResult {
639652
accommodation: StaysAccommodation
640653
adults: number
641654
rooms: number
655+
guests: Array<Guest>
642656
}

src/Stays/mocks.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,9 @@ export const MOCK_SEARCH_RESULT: StaysSearchResult = {
155155
id: 'sta_something',
156156
check_in_date: '2023-03-24',
157157
check_out_date: '2023-03-28',
158-
adults: 1,
158+
adults: 2,
159159
rooms: 1,
160+
guests: [{ type: 'adult' }, { type: 'adult' }],
160161
}
161162

162163
export const MOCK_BOOKING: StaysBooking = {
@@ -213,6 +214,7 @@ export const MOCK_QUOTE: StaysQuote = {
213214
due_at_accommodation_currency: 'USD',
214215
supported_loyalty_programme: 'duffel_hotel_group_rewards',
215216
card_component_key: null,
216-
adults: 1,
217+
adults: 2,
217218
rooms: 1,
219+
guests: [{ type: 'adult' }, { type: 'adult' }],
218220
}

0 commit comments

Comments
 (0)