Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@duffel/api",
"version": "2.12.0",
"version": "2.12.1",
"description": "Javascript client library for the Duffel API",
"main": "dist/index.js",
"module": "dist/index.es.js",
Expand Down
26 changes: 26 additions & 0 deletions src/Stays/Accommodation/Accommodation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,38 @@ describe('Stays/Accommodation', () => {
})

it('should post to /stays/suggestions when `suggestions` is called', async () => {
const query = 'rits'
const location = {
geographic_coordinates: { latitude: 51.5287398, longitude: -0.2664005 },
radius: 5,
}

const mockResponse = { data: [MOCK_ACCOMMODATION_SUGGESTION] }

nock(/(.*)/)
.post('/stays/accommodation/suggestions', (body) => {
expect(body.data.query).toEqual(query)
expect(body.data.location).toEqual(location)

return true
})
.reply(200, mockResponse)

const response = await duffel.stays.accommodation.suggestions(
query,
location,
)
expect(response.data).toEqual(mockResponse.data)
})

it('should post to /stays/suggestions without a location when `suggestions` is called with only a query', async () => {
const query = 'rits'
const mockResponse = { data: [MOCK_ACCOMMODATION_SUGGESTION] }

nock(/(.*)/)
.post('/stays/accommodation/suggestions', (body) => {
expect(body.data.query).toEqual(query)
expect(body.data.location).toBeUndefined()
return true
})
.reply(200, mockResponse)
Expand Down
8 changes: 7 additions & 1 deletion src/Stays/Accommodation/Accommodation.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { Client } from '../../Client'
import { StaysAccommodationSuggestion, StaysAccommodation } from '../StaysTypes'
import {
LocationParams,
StaysAccommodationSuggestion,
StaysAccommodation,
} from '../StaysTypes'
import { Resource } from '../../Resource'
import { DuffelResponse } from '../../types'

Expand All @@ -20,12 +24,14 @@ export class Accommodation extends Resource {
*/
public suggestions = async (
query: string,
location?: LocationParams,
): Promise<DuffelResponse<StaysAccommodationSuggestion[]>> =>
this.request({
method: 'POST',
path: `${this.path}/suggestions`,
data: {
query: query,
location: location,
},
})

Expand Down
16 changes: 9 additions & 7 deletions src/Stays/StaysTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,14 +633,16 @@ type CommonStaysSearchParams = {
check_out_date: string
} & OccupancyCriteria

type LocationSearchParams = {
location: {
radius: number
geographic_coordinates: {
latitude: number
longitude: number
}
export type LocationParams = {
radius: number
geographic_coordinates: {
latitude: number
longitude: number
}
}

type LocationSearchParams = {
location: LocationParams
} & CommonStaysSearchParams

type AccommodationSearchParams = {
Expand Down