Skip to content

Commit

Permalink
[STAYS-521] Add cancel booking to Stays (#745)
Browse files Browse the repository at this point in the history
* feat(stays): add cancel to Booking resource

* test(stays): add cancel booking test
  • Loading branch information
matthewp5 authored Jun 1, 2023
1 parent 5cc20a8 commit ed2df82
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/Stays/Bookings/Bookings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,19 @@ describe('Stays/Bookings', () => {
const response = await duffel.stays.bookings.get('bok_123')
expect(response.data).toEqual(mockResponse.data)
})

it('should post to /stays/bookings/{id}/actions/cancel when `cancel` is called', async () => {
const mockResponse = {
data: {
...MOCK_BOOKING,
status: 'cancelled',
},
}

nock(/(.*)/)
.post('/stays/bookings/bok_123/actions/cancel')
.reply(200, mockResponse)
const response = await duffel.stays.bookings.cancel('bok_123')
expect(response.data).toEqual(mockResponse.data)
})
})
14 changes: 13 additions & 1 deletion src/Stays/Bookings/Bookings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,23 @@ export class Bookings extends Resource {
})

/**
* list bookings
* List bookings
*/
public list = async (): Promise<DuffelResponse<StaysBooking[]>> =>
this.request({
method: 'GET',
path: this.path,
})

/**
* Cancel a booking
* @param {string} bookingId - The ID of the booking
*/
public cancel = async (
bookindId: string
): Promise<DuffelResponse<StaysBooking>> =>
this.request({
method: 'POST',
path: `${this.path}/${bookindId}/actions/cancel`,
})
}

0 comments on commit ed2df82

Please sign in to comment.