Skip to content

Commit d241e4b

Browse files
authored
Merge pull request #981 from duffelhq/jo-brand-sdk
Expose brands to JS SDK
2 parents e8da68d + 58532ef commit d241e4b

File tree

7 files changed

+83
-2
lines changed

7 files changed

+83
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@duffel/api",
3-
"version": "3.2.0",
3+
"version": "3.3.0",
44
"description": "Javascript client library for the Duffel API",
55
"main": "dist/index.js",
66
"module": "dist/index.es.js",

src/Stays/Brands/Brands.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import nock from 'nock'
2+
import { Duffel } from '../../index'
3+
import { MOCK_BRAND } from '../mocks'
4+
5+
const duffel = new Duffel({ token: 'mockToken' })
6+
describe('Stays/Brands', () => {
7+
afterEach(() => {
8+
nock.cleanAll()
9+
})
10+
11+
it('should get to /stays/brands when `list` is called', async () => {
12+
const mockResponse = { data: [MOCK_BRAND] }
13+
14+
nock(/(.*)/).get('/stays/brands').reply(200, mockResponse)
15+
const response = await duffel.stays.brands.list()
16+
expect(response.data).toEqual(mockResponse.data)
17+
})
18+
19+
it('should get to /stays/brands/{id} when `get` is called', async () => {
20+
const mockResponse = { data: MOCK_BRAND }
21+
22+
nock(/(.*)/).get(`/stays/brands/${MOCK_BRAND.id}`).reply(200, mockResponse)
23+
const response = await duffel.stays.brands.get(MOCK_BRAND.id)
24+
expect(response.data).toEqual(mockResponse.data)
25+
})
26+
})

src/Stays/Brands/Brands.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { Client } from '../../Client'
2+
import { StaysAccommodationBrand } from '../StaysTypes'
3+
import { Resource } from '../../Resource'
4+
import { DuffelResponse } from '../../types'
5+
6+
export class Brands extends Resource {
7+
/**
8+
* Endpoint path
9+
*/
10+
path: string
11+
12+
constructor(client: Client) {
13+
super(client)
14+
this.path = 'stays/brands'
15+
}
16+
17+
/**
18+
* Get a brand
19+
* @param {string} brandId - The ID of the brand
20+
*/
21+
public get = async (
22+
brandId: string,
23+
): Promise<DuffelResponse<StaysAccommodationBrand>> =>
24+
this.request({
25+
method: 'GET',
26+
path: `${this.path}/${brandId}`,
27+
})
28+
29+
/**
30+
* List brands
31+
*/
32+
public list = async (): Promise<DuffelResponse<StaysAccommodationBrand[]>> =>
33+
this.request({
34+
method: 'GET',
35+
path: this.path,
36+
})
37+
}

src/Stays/Brands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './Brands'

src/Stays/Stays.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { StaysSearchParams, StaysSearchResult } from './StaysTypes'
33
import { Resource } from '../Resource'
44
import { DuffelResponse } from '../types'
55
import { Accommodation } from './Accommodation'
6+
import { Brands } from './Brands'
67
import { LoyaltyProgrammes } from './LoyaltyProgrammes'
78
import { Bookings } from './Bookings'
89
import { Quotes } from './Quotes'
@@ -16,6 +17,7 @@ export class Stays extends Resource {
1617

1718
public accommodation: Accommodation
1819
public loyaltyProgrammes: LoyaltyProgrammes
20+
public brands: Brands
1921
public searchResults: SearchResults
2022
public quotes: Quotes
2123
public bookings: Bookings
@@ -25,6 +27,7 @@ export class Stays extends Resource {
2527
this.path = 'stays'
2628

2729
this.accommodation = new Accommodation(client)
30+
this.brands = new Brands(client)
2831
this.loyaltyProgrammes = new LoyaltyProgrammes(client)
2932
this.searchResults = new SearchResults(client)
3033
this.quotes = new Quotes(client)

src/Stays/StaysTypes.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,11 @@ export interface StaysLocation {
301301
geographic_coordinates: GeographicCoordinates | null
302302
}
303303

304+
export interface StaysAccommodationBrand {
305+
name: string
306+
id: string
307+
}
308+
304309
export interface StaysAccommodation {
305310
/**
306311
* Duffel ID for this accommodation. Useful for searching availability
@@ -317,6 +322,8 @@ export interface StaysAccommodation {
317322
*/
318323
chain: StaysChain | null
319324

325+
brand: StaysAccommodationBrand | null
326+
320327
/**
321328
* Check in and check out related information
322329
*/

src/Stays/mocks.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// eslint-disable spellcheck/spell-checker
22
import {
33
StaysAccommodation,
4+
StaysAccommodationBrand,
45
StaysAccommodationSuggestion,
56
StaysBooking,
67
StaysLoyaltyProgramme,
@@ -9,6 +10,11 @@ import {
910
} from './StaysTypes'
1011
import { StaysBookingPayload } from './Bookings/Bookings'
1112

13+
export const MOCK_BRAND: StaysAccommodationBrand = {
14+
id: 'bra_DQPneLbCejxRuxAqD7amaW',
15+
name: 'The Ritz-Carlton',
16+
}
17+
1218
export const MOCK_ACCOMMODATION: StaysAccommodation = {
1319
id: 'acc_0000AWr2VsUNIF1Vl91xg0',
1420
amenities: [
@@ -143,8 +149,9 @@ export const MOCK_ACCOMMODATION: StaysAccommodation = {
143149
key_collection: {
144150
instructions: 'Key is at the property. Collect from the lock box.',
145151
},
152+
brand: MOCK_BRAND,
146153
chain: {
147-
name: 'The Ritz-Carlton',
154+
name: 'Marriott International',
148155
},
149156
supported_loyalty_programme: 'duffel_hotel_group_rewards',
150157
}

0 commit comments

Comments
 (0)