Skip to content

Commit

Permalink
feat: create SDK interface for accommodation listing
Browse files Browse the repository at this point in the history
  • Loading branch information
jekku committed Nov 5, 2024
1 parent 0c8c253 commit 93ef682
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
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": "3.1.1",
"version": "3.2.0",
"description": "Javascript client library for the Duffel API",
"main": "dist/index.js",
"module": "dist/index.es.js",
Expand Down
33 changes: 33 additions & 0 deletions src/Stays/Accommodation/Accommodation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,37 @@ describe('Stays/Accommodation', () => {
const response = await duffel.stays.accommodation.get(id)
expect(response.data).toEqual(mockResponse.data)
})

it('should send GET to /stays/accommodation when `list` is called', async () => {
const mockResponse = {
data: [MOCK_ACCOMMODATION],
meta: { limit: 1, before: null, after: null },
}

const params = {
radius: 7,
latitude: 13.5276927,
longitude: 122.1160988,
}

nock(/(.*)/)
.get(`/stays/accommodation`)
.query((queryObject) => {
expect(parseInt(queryObject.radius as string)).toEqual(params.radius)
expect(parseFloat(queryObject.latitude as string)).toEqual(
params.latitude,
)
expect(parseFloat(queryObject.longitude as string)).toEqual(
params.longitude,
)

return true
})
.reply(200, mockResponse)

const response = await duffel.stays.accommodation.list(params)

expect(response.data).toEqual(mockResponse.data)
expect(response.meta).toEqual(mockResponse.meta)
})
})
10 changes: 10 additions & 0 deletions src/Stays/Accommodation/Accommodation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Client } from '../../Client'
import {
LocationParams,
ListAccommodationParams,
StaysAccommodationSuggestion,
StaysAccommodation,
} from '../StaysTypes'
Expand Down Expand Up @@ -46,4 +47,13 @@ export class Accommodation extends Resource {
method: 'GET',
path: `${this.path}/${id}`,
})

public list = (
params: ListAccommodationParams,
): Promise<DuffelResponse<StaysAccommodation[]>> =>
this.request({
method: 'GET',
path: `${this.path}`,
params: params,
})
}
13 changes: 9 additions & 4 deletions src/Stays/StaysTypes.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { PaginationMeta } from './../types'

export type StaysBedType = 'single' | 'double' | 'queen' | 'king' | 'sofabed'

export interface StaysBed {
Expand Down Expand Up @@ -628,10 +630,7 @@ interface CommonStaysSearchParams {

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

type LocationSearchParams = {
Expand All @@ -647,6 +646,12 @@ type AccommodationSearchParams = {

export type StaysSearchParams = LocationSearchParams | AccommodationSearchParams

export interface ListAccommodationParams extends PaginationMeta {
radius?: LocationParams['radius']
latitude: GeographicCoordinates['latitude']
longitude: GeographicCoordinates['longitude']
}

export interface StaysSearchResult {
id: string
check_in_date: string
Expand Down

0 comments on commit 93ef682

Please sign in to comment.