Skip to content

Commit 6f6d178

Browse files
authored
feat: add stays loyalty programmes resource (#937)
1 parent a033b25 commit 6f6d178

File tree

7 files changed

+76
-5
lines changed

7 files changed

+76
-5
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": "2.13.0",
3+
"version": "2.14.0",
44
"description": "Javascript client library for the Duffel API",
55
"main": "dist/index.js",
66
"module": "dist/index.es.js",
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import nock from 'nock'
2+
import { Duffel } from '../../index'
3+
import { MOCK_LOYALTY_PROGRAMMES } from '../mocks'
4+
5+
const duffel = new Duffel({ token: 'mockToken' })
6+
describe('Stays/LoyaltyProgrammes', () => {
7+
afterEach(() => {
8+
nock.cleanAll()
9+
})
10+
11+
it('should send a get to /stays/loyalty_programmes when `list` is called', async () => {
12+
const mockResponse = { data: MOCK_LOYALTY_PROGRAMMES }
13+
14+
nock(/(.*)/).get('/stays/loyalty_programmes').reply(200, mockResponse)
15+
16+
const response = await duffel.stays.loyaltyProgrammes.list()
17+
18+
expect(response.data).toEqual(mockResponse.data)
19+
})
20+
})
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Client } from '../../Client'
2+
import { StaysLoyaltyProgramme } from '../StaysTypes'
3+
import { Resource } from '../../Resource'
4+
import { DuffelResponse } from '../../types'
5+
6+
export class LoyaltyProgrammes extends Resource {
7+
/**
8+
* Endpoint path
9+
*/
10+
path: string
11+
12+
constructor(client: Client) {
13+
super(client)
14+
this.path = 'stays/loyalty_programmes'
15+
}
16+
17+
/**
18+
* List all the loyalty programmes supported by Duffel Stays
19+
*/
20+
public list = async (): Promise<DuffelResponse<StaysLoyaltyProgramme[]>> =>
21+
this.request({
22+
method: 'GET',
23+
path: this.path,
24+
})
25+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './LoyaltyProgrammes'

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 { LoyaltyProgrammes } from './LoyaltyProgrammes'
67
import { Bookings } from './Bookings'
78
import { Quotes } from './Quotes'
89
import { SearchResults } from './SearchResults'
@@ -14,6 +15,7 @@ export class Stays extends Resource {
1415
path: string
1516

1617
public accommodation: Accommodation
18+
public loyaltyProgrammes: LoyaltyProgrammes
1719
public searchResults: SearchResults
1820
public quotes: Quotes
1921
public bookings: Bookings
@@ -23,6 +25,7 @@ export class Stays extends Resource {
2325
this.path = 'stays'
2426

2527
this.accommodation = new Accommodation(client)
28+
this.loyaltyProgrammes = new LoyaltyProgrammes(client)
2629
this.searchResults = new SearchResults(client)
2730
this.quotes = new Quotes(client)
2831
this.bookings = new Bookings(client)

src/Stays/StaysTypes.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export interface StaysRateCancellationTimeline {
5353
currency: string
5454
}
5555

56-
export type StaysLoyaltyProgramme =
56+
export type StaysLoyaltyProgrammeReference =
5757
| 'wyndham_rewards'
5858
| 'choice_privileges'
5959
| 'marriott_bonvoy'
@@ -178,7 +178,7 @@ export interface StaysRate {
178178
* If the rate does not support a loyalty programme, this will be null.
179179
* The duffel_hotel_group_rewards value is an example programme for testing and integration purposes, and will only appear on Duffel Hotel Group test hotel rates.
180180
*/
181-
supported_loyalty_programme: StaysLoyaltyProgramme | null
181+
supported_loyalty_programme: StaysLoyaltyProgrammeReference | null
182182

183183
/**
184184
* The source of the rate.
@@ -398,6 +398,11 @@ export interface StaysAccommodation {
398398
* Rooms for the accommodation
399399
*/
400400
rooms: StaysRoom[]
401+
402+
/**
403+
* The loyalty programme that this accommodation supports.
404+
*/
405+
supported_loyalty_programme: StaysLoyaltyProgrammeReference | null
401406
}
402407

403408
export interface StaysAccommodationSuggestion {
@@ -519,7 +524,7 @@ export interface StaysQuote {
519524
/**
520525
* The loyalty programme that this quote supports.
521526
*/
522-
supported_loyalty_programme: StaysLoyaltyProgramme | null
527+
supported_loyalty_programme: StaysLoyaltyProgrammeReference | null
523528

524529
/**
525530
* A client key to authenticate with Duffel's Card Component when creating a tokenised card.
@@ -600,7 +605,7 @@ export interface StaysBooking {
600605
/**
601606
* The loyalty programme that this booking supports.
602607
*/
603-
supported_loyalty_programme: StaysLoyaltyProgramme | null
608+
supported_loyalty_programme: StaysLoyaltyProgrammeReference | null
604609

605610
/**
606611
* Loyalty account number to associate with this booking. Use this only when the quote has a supported_loyalty_programme indicated. Otherwise, this will result into an error.
@@ -668,3 +673,9 @@ export interface StaysSearchResult {
668673
rooms: number
669674
guests: Array<Guest>
670675
}
676+
677+
export interface StaysLoyaltyProgramme {
678+
reference: StaysLoyaltyProgrammeReference
679+
name: string
680+
logo_url: string | null
681+
}

src/Stays/mocks.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
StaysAccommodation,
44
StaysAccommodationSuggestion,
55
StaysBooking,
6+
StaysLoyaltyProgramme,
67
StaysQuote,
78
StaysSearchResult,
89
} from './StaysTypes'
@@ -149,6 +150,7 @@ export const MOCK_ACCOMMODATION: StaysAccommodation = {
149150
chain: {
150151
name: 'The Ritz-Carlton',
151152
},
153+
supported_loyalty_programme: 'duffel_hotel_group_rewards',
152154
}
153155

154156
export const MOCK_SEARCH_RESULT: StaysSearchResult = {
@@ -228,3 +230,12 @@ export const MOCK_ACCOMMODATION_SUGGESTION: StaysAccommodationSuggestion = {
228230
accommodation_name: MOCK_ACCOMMODATION.name,
229231
accommodation_location: MOCK_ACCOMMODATION.location,
230232
}
233+
234+
export const MOCK_LOYALTY_PROGRAMMES: StaysLoyaltyProgramme[] = [
235+
{
236+
reference: 'duffel_hotel_group_rewards',
237+
name: 'Duffel Hotel Group Rewards',
238+
logo_url:
239+
'https://assets.duffel.com/img/stays/loyalty-programmes/full-color-logo/duffel_hotel_group_rewards-square.svg',
240+
},
241+
]

0 commit comments

Comments
 (0)