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": "3.2.0",
"version": "3.3.0",
"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/Brands/Brands.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import nock from 'nock'
import { Duffel } from '../../index'
import { MOCK_BRAND } from '../mocks'

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

it('should get to /stays/brands when `list` is called', async () => {
const mockResponse = { data: [MOCK_BRAND] }

nock(/(.*)/).get('/stays/brands').reply(200, mockResponse)
const response = await duffel.stays.brands.list()
expect(response.data).toEqual(mockResponse.data)
})

it('should get to /stays/brands/{id} when `get` is called', async () => {
const mockResponse = { data: MOCK_BRAND }

nock(/(.*)/).get(`/stays/brands/${MOCK_BRAND.id}`).reply(200, mockResponse)
const response = await duffel.stays.brands.get(MOCK_BRAND.id)
expect(response.data).toEqual(mockResponse.data)
})
})
37 changes: 37 additions & 0 deletions src/Stays/Brands/Brands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { Client } from '../../Client'
import { StaysAccommodationBrand } from '../StaysTypes'
import { Resource } from '../../Resource'
import { DuffelResponse } from '../../types'

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

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

/**
* Get a brand
* @param {string} brandId - The ID of the brand
*/
public get = async (
brandId: string,
): Promise<DuffelResponse<StaysAccommodationBrand>> =>
this.request({
method: 'GET',
path: `${this.path}/${brandId}`,
})

/**
* List brands
*/
public list = async (): Promise<DuffelResponse<StaysAccommodationBrand[]>> =>
this.request({
method: 'GET',
path: this.path,
})
}
1 change: 1 addition & 0 deletions src/Stays/Brands/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Brands'
3 changes: 3 additions & 0 deletions src/Stays/Stays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { StaysSearchParams, StaysSearchResult } from './StaysTypes'
import { Resource } from '../Resource'
import { DuffelResponse } from '../types'
import { Accommodation } from './Accommodation'
import { Brands } from './Brands'
import { LoyaltyProgrammes } from './LoyaltyProgrammes'
import { Bookings } from './Bookings'
import { Quotes } from './Quotes'
Expand All @@ -16,6 +17,7 @@ export class Stays extends Resource {

public accommodation: Accommodation
public loyaltyProgrammes: LoyaltyProgrammes
public brands: Brands
public searchResults: SearchResults
public quotes: Quotes
public bookings: Bookings
Expand All @@ -25,6 +27,7 @@ export class Stays extends Resource {
this.path = 'stays'

this.accommodation = new Accommodation(client)
this.brands = new Brands(client)
this.loyaltyProgrammes = new LoyaltyProgrammes(client)
this.searchResults = new SearchResults(client)
this.quotes = new Quotes(client)
Expand Down
7 changes: 7 additions & 0 deletions src/Stays/StaysTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,11 @@ export interface StaysLocation {
geographic_coordinates: GeographicCoordinates | null
}

export interface StaysAccommodationBrand {
name: string
id: string
}

export interface StaysAccommodation {
/**
* Duffel ID for this accommodation. Useful for searching availability
Expand All @@ -317,6 +322,8 @@ export interface StaysAccommodation {
*/
chain: StaysChain | null

brand: StaysAccommodationBrand | null

/**
* Check in and check out related information
*/
Expand Down
9 changes: 8 additions & 1 deletion 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,
StaysAccommodationBrand,
StaysAccommodationSuggestion,
StaysBooking,
StaysLoyaltyProgramme,
Expand All @@ -9,6 +10,11 @@ import {
} from './StaysTypes'
import { StaysBookingPayload } from './Bookings/Bookings'

export const MOCK_BRAND: StaysAccommodationBrand = {
id: 'bra_DQPneLbCejxRuxAqD7amaW',
name: 'The Ritz-Carlton',
}

export const MOCK_ACCOMMODATION: StaysAccommodation = {
id: 'acc_0000AWr2VsUNIF1Vl91xg0',
amenities: [
Expand Down Expand Up @@ -143,8 +149,9 @@ export const MOCK_ACCOMMODATION: StaysAccommodation = {
key_collection: {
instructions: 'Key is at the property. Collect from the lock box.',
},
brand: MOCK_BRAND,
chain: {
name: 'The Ritz-Carlton',
name: 'Marriott International',
},
supported_loyalty_programme: 'duffel_hotel_group_rewards',
}
Expand Down