Skip to content

Commit b02c8c1

Browse files
authored
Merge pull request #928 from duffelhq/jo-bound-suggestion-to-location
Add optional location parameter to suggestions SDK
2 parents ff2cbb2 + 746f5f4 commit b02c8c1

File tree

4 files changed

+43
-9
lines changed

4 files changed

+43
-9
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@duffel/api",
3-
"version": "2.12.0",
3+
"version": "2.12.1",
44
"description": "Javascript client library for the Duffel API",
55
"main": "dist/index.js",
66
"module": "dist/index.es.js",

src/Stays/Accommodation/Accommodation.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,38 @@ describe('Stays/Accommodation', () => {
99
})
1010

1111
it('should post to /stays/suggestions when `suggestions` is called', async () => {
12+
const query = 'rits'
13+
const location = {
14+
geographic_coordinates: { latitude: 51.5287398, longitude: -0.2664005 },
15+
radius: 5,
16+
}
17+
18+
const mockResponse = { data: [MOCK_ACCOMMODATION_SUGGESTION] }
19+
20+
nock(/(.*)/)
21+
.post('/stays/accommodation/suggestions', (body) => {
22+
expect(body.data.query).toEqual(query)
23+
expect(body.data.location).toEqual(location)
24+
25+
return true
26+
})
27+
.reply(200, mockResponse)
28+
29+
const response = await duffel.stays.accommodation.suggestions(
30+
query,
31+
location,
32+
)
33+
expect(response.data).toEqual(mockResponse.data)
34+
})
35+
36+
it('should post to /stays/suggestions without a location when `suggestions` is called with only a query', async () => {
1237
const query = 'rits'
1338
const mockResponse = { data: [MOCK_ACCOMMODATION_SUGGESTION] }
1439

1540
nock(/(.*)/)
1641
.post('/stays/accommodation/suggestions', (body) => {
1742
expect(body.data.query).toEqual(query)
43+
expect(body.data.location).toBeUndefined()
1844
return true
1945
})
2046
.reply(200, mockResponse)

src/Stays/Accommodation/Accommodation.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { Client } from '../../Client'
2-
import { StaysAccommodationSuggestion, StaysAccommodation } from '../StaysTypes'
2+
import {
3+
LocationParams,
4+
StaysAccommodationSuggestion,
5+
StaysAccommodation,
6+
} from '../StaysTypes'
37
import { Resource } from '../../Resource'
48
import { DuffelResponse } from '../../types'
59

@@ -20,12 +24,14 @@ export class Accommodation extends Resource {
2024
*/
2125
public suggestions = async (
2226
query: string,
27+
location?: LocationParams,
2328
): Promise<DuffelResponse<StaysAccommodationSuggestion[]>> =>
2429
this.request({
2530
method: 'POST',
2631
path: `${this.path}/suggestions`,
2732
data: {
2833
query: query,
34+
location: location,
2935
},
3036
})
3137

src/Stays/StaysTypes.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -633,14 +633,16 @@ type CommonStaysSearchParams = {
633633
check_out_date: string
634634
} & OccupancyCriteria
635635

636-
type LocationSearchParams = {
637-
location: {
638-
radius: number
639-
geographic_coordinates: {
640-
latitude: number
641-
longitude: number
642-
}
636+
export type LocationParams = {
637+
radius: number
638+
geographic_coordinates: {
639+
latitude: number
640+
longitude: number
643641
}
642+
}
643+
644+
type LocationSearchParams = {
645+
location: LocationParams
644646
} & CommonStaysSearchParams
645647

646648
type AccommodationSearchParams = {

0 commit comments

Comments
 (0)