diff --git a/src/Stays/Bookings/Bookings.spec.ts b/src/Stays/Bookings/Bookings.spec.ts index 2c16c9fa..d856806e 100644 --- a/src/Stays/Bookings/Bookings.spec.ts +++ b/src/Stays/Bookings/Bookings.spec.ts @@ -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) + }) }) diff --git a/src/Stays/Bookings/Bookings.ts b/src/Stays/Bookings/Bookings.ts index fa78a17c..cec55032 100644 --- a/src/Stays/Bookings/Bookings.ts +++ b/src/Stays/Bookings/Bookings.ts @@ -52,11 +52,23 @@ export class Bookings extends Resource { }) /** - * list bookings + * List bookings */ public list = async (): Promise> => this.request({ method: 'GET', path: this.path, }) + + /** + * Cancel a booking + * @param {string} bookingId - The ID of the booking + */ + public cancel = async ( + bookindId: string + ): Promise> => + this.request({ + method: 'POST', + path: `${this.path}/${bookindId}/actions/cancel`, + }) }