File tree Expand file tree Collapse file tree 7 files changed +74
-1
lines changed Expand file tree Collapse file tree 7 files changed +74
-1
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " @duffel/api" ,
3- "version" : " 2.10 .0" ,
3+ "version" : " 2.11 .0" ,
44 "description" : " Javascript client library for the Duffel API" ,
55 "main" : " dist/index.js" ,
66 "module" : " dist/index.es.js" ,
Original file line number Diff line number Diff line change 1+ import nock from 'nock'
2+ import { Duffel } from '../../index'
3+ import { MOCK_ACCOMMODATION_SUGGESTION } from '../mocks'
4+
5+ const duffel = new Duffel ( { token : 'mockToken' } )
6+ describe ( 'Stays/Accommodation' , ( ) => {
7+ afterEach ( ( ) => {
8+ nock . cleanAll ( )
9+ } )
10+
11+ it ( 'should post to /stays/suggestions when `suggestions` is called' , async ( ) => {
12+ const query = 'rits'
13+ const mockResponse = { data : [ MOCK_ACCOMMODATION_SUGGESTION ] }
14+
15+ nock ( / ( .* ) / )
16+ . post ( '/stays/accommodation/suggestions' , ( body ) => {
17+ expect ( body . data . query ) . toEqual ( query )
18+ return true
19+ } )
20+ . reply ( 200 , mockResponse )
21+
22+ const response = await duffel . stays . accommodation . suggestions ( query )
23+ expect ( response . data ) . toEqual ( mockResponse . data )
24+ } )
25+ } )
Original file line number Diff line number Diff line change 1+ import { Client } from '../../Client'
2+ import { StaysAccommodationSuggestion } from '../StaysTypes'
3+ import { Resource } from '../../Resource'
4+ import { DuffelResponse } from '../../types'
5+
6+ export class Accommodation extends Resource {
7+ /**
8+ * Endpoint path
9+ */
10+ path : string
11+
12+ constructor ( client : Client ) {
13+ super ( client )
14+ this . path = 'stays/accommodation'
15+ }
16+
17+ /**
18+ * Get suggestions for accommodation given a query string.
19+ * @param {string } query - The query string for the search
20+ */
21+ public suggestions = async (
22+ query : string ,
23+ ) : Promise < DuffelResponse < StaysAccommodationSuggestion [ ] > > =>
24+ this . request ( {
25+ method : 'POST' ,
26+ path : `${ this . path } /suggestions` ,
27+ data : {
28+ query : query ,
29+ } ,
30+ } )
31+ }
Original file line number Diff line number Diff line change 1+ export * from './Accommodation'
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { Client } from '../Client'
22import { StaysSearchParams , StaysSearchResult } from './StaysTypes'
33import { Resource } from '../Resource'
44import { DuffelResponse } from '../types'
5+ import { Accommodation } from './Accommodation'
56import { Bookings } from './Bookings'
67import { Quotes } from './Quotes'
78import { SearchResults } from './SearchResults'
@@ -12,6 +13,7 @@ export class Stays extends Resource {
1213 */
1314 path : string
1415
16+ public accommodation : Accommodation
1517 public searchResults : SearchResults
1618 public quotes : Quotes
1719 public bookings : Bookings
@@ -20,6 +22,7 @@ export class Stays extends Resource {
2022 super ( client )
2123 this . path = 'stays'
2224
25+ this . accommodation = new Accommodation ( client )
2326 this . searchResults = new SearchResults ( client )
2427 this . quotes = new Quotes ( client )
2528 this . bookings = new Bookings ( client )
Original file line number Diff line number Diff line change @@ -400,6 +400,12 @@ export interface StaysAccommodation {
400400 rooms : StaysRoom [ ]
401401}
402402
403+ export interface StaysAccommodationSuggestion {
404+ accommodation_id : StaysAccommodation [ 'id' ]
405+ accommodation_name : StaysAccommodation [ 'name' ]
406+ accommodation_location : StaysLocation
407+ }
408+
403409/**
404410 * Represents a quote for a stay.
405411 */
Original file line number Diff line number Diff line change 11// eslint-disable spellcheck/spell-checker
22import {
33 StaysAccommodation ,
4+ StaysAccommodationSuggestion ,
45 StaysBooking ,
56 StaysQuote ,
67 StaysSearchResult ,
@@ -218,3 +219,9 @@ export const MOCK_QUOTE: StaysQuote = {
218219 rooms : 1 ,
219220 guests : [ { type : 'adult' } , { type : 'adult' } ] ,
220221}
222+
223+ export const MOCK_ACCOMMODATION_SUGGESTION : StaysAccommodationSuggestion = {
224+ accommodation_id : MOCK_ACCOMMODATION . id ,
225+ accommodation_name : MOCK_ACCOMMODATION . name ,
226+ accommodation_location : MOCK_ACCOMMODATION . location ,
227+ }
You can’t perform that action at this time.
0 commit comments