Skip to content

Commit

Permalink
feat: make duffel.stays.accommodation.suggestions API call
Browse files Browse the repository at this point in the history
  • Loading branch information
jekku committed Jun 25, 2024
1 parent 20fa8f9 commit 6d9a728
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Stays/Accommodation/Accommodation.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import nock from 'nock'
import { Duffel } from '../../index'
import { MOCK_ACCOMMODATION_SUGGESTION } from '../mocks'

const duffel = new Duffel({ token: 'mockToken' })
describe('Stays/Accommodation', () => {
afterEach(() => {
nock.cleanAll()
})

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

nock(/(.*)/)
.post('/stays/accommodation/suggestions', (body) => {
expect(body.data.query).toEqual(query)
return true
})
.reply(200, mockResponse)

const response = await duffel.stays.accommodation.suggestions(query)
expect(response.data).toEqual(mockResponse.data)
})
})
31 changes: 31 additions & 0 deletions src/Stays/Accommodation/Accommodation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Client } from '../../Client'
import { StaysAccommodationSuggestion } from '../StaysTypes'
import { Resource } from '../../Resource'
import { DuffelResponse } from '../../types'

export class Accommodation extends Resource {
/**
* Endpoint path
*/
path: string

constructor(client: Client) {
super(client)
this.path = 'stays/accommodation'
}

/**
* Create a booking
* @param {object} payload - The booking payload, including quote id and guest information
*/
public suggestions = async (
query: string,
): Promise<DuffelResponse<StaysAccommodationSuggestion[]>> =>
this.request({
method: 'POST',
path: `${this.path}/suggestions`,
data: {
query: query,
},
})
}
1 change: 1 addition & 0 deletions src/Stays/Accommodation/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Accommodation'
3 changes: 3 additions & 0 deletions src/Stays/Stays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Client } from '../Client'
import { StaysSearchParams, StaysSearchResult } from './StaysTypes'
import { Resource } from '../Resource'
import { DuffelResponse } from '../types'
import { Accommodation } from './Accommodation'
import { Bookings } from './Bookings'
import { Quotes } from './Quotes'
import { SearchResults } from './SearchResults'
Expand All @@ -12,6 +13,7 @@ export class Stays extends Resource {
*/
path: string

public accommodation: Accommodation
public searchResults: SearchResults
public quotes: Quotes
public bookings: Bookings
Expand All @@ -20,6 +22,7 @@ export class Stays extends Resource {
super(client)
this.path = 'stays'

this.accommodation = new Accommodation(client)
this.searchResults = new SearchResults(client)
this.quotes = new Quotes(client)
this.bookings = new Bookings(client)
Expand Down
6 changes: 6 additions & 0 deletions src/Stays/StaysTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,12 @@ export interface StaysAccommodation {
rooms: StaysRoom[]
}

export interface StaysAccommodationSuggestion {
accommodation_id: StaysAccommodation['id']
accommodation_name: StaysAccommodation['name']
accommodation_location: StaysLocation
}

/**
* Represents a quote for a stay.
*/
Expand Down
7 changes: 7 additions & 0 deletions src/Stays/mocks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// eslint-disable spellcheck/spell-checker
import {
StaysAccommodation,
StaysAccommodationSuggestion,
StaysBooking,
StaysQuote,
StaysSearchResult,
Expand Down Expand Up @@ -218,3 +219,9 @@ export const MOCK_QUOTE: StaysQuote = {
rooms: 1,
guests: [{ type: 'adult' }, { type: 'adult' }],
}

export const MOCK_ACCOMMODATION_SUGGESTION: StaysAccommodationSuggestion = {
accommodation_id: MOCK_ACCOMMODATION.id,
accommodation_name: MOCK_ACCOMMODATION.name,
accommodation_location: MOCK_ACCOMMODATION.location,
}

0 comments on commit 6d9a728

Please sign in to comment.