diff --git a/src/Stays/Accommodation/Accommodation.spec.ts b/src/Stays/Accommodation/Accommodation.spec.ts new file mode 100644 index 00000000..d5aed799 --- /dev/null +++ b/src/Stays/Accommodation/Accommodation.spec.ts @@ -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) + }) +}) diff --git a/src/Stays/Accommodation/Accommodation.ts b/src/Stays/Accommodation/Accommodation.ts new file mode 100644 index 00000000..8e2c6e28 --- /dev/null +++ b/src/Stays/Accommodation/Accommodation.ts @@ -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> => + this.request({ + method: 'POST', + path: `${this.path}/suggestions`, + data: { + query: query, + }, + }) +} diff --git a/src/Stays/Accommodation/index.ts b/src/Stays/Accommodation/index.ts new file mode 100644 index 00000000..a5a45243 --- /dev/null +++ b/src/Stays/Accommodation/index.ts @@ -0,0 +1 @@ +export * from './Accommodation' diff --git a/src/Stays/Stays.ts b/src/Stays/Stays.ts index 1034efee..9825cd4b 100644 --- a/src/Stays/Stays.ts +++ b/src/Stays/Stays.ts @@ -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' @@ -12,6 +13,7 @@ export class Stays extends Resource { */ path: string + public accommodation: Accommodation public searchResults: SearchResults public quotes: Quotes public bookings: Bookings @@ -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) diff --git a/src/Stays/StaysTypes.ts b/src/Stays/StaysTypes.ts index 837bd3dd..103d112c 100644 --- a/src/Stays/StaysTypes.ts +++ b/src/Stays/StaysTypes.ts @@ -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. */ diff --git a/src/Stays/mocks.ts b/src/Stays/mocks.ts index dc640ce5..c22768c5 100644 --- a/src/Stays/mocks.ts +++ b/src/Stays/mocks.ts @@ -1,6 +1,7 @@ // eslint-disable spellcheck/spell-checker import { StaysAccommodation, + StaysAccommodationSuggestion, StaysBooking, StaysQuote, StaysSearchResult, @@ -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, +}