From dc0e3616ef28c8e301c8f40a9570b3e0f949242a Mon Sep 17 00:00:00 2001 From: Michal Garapich Date: Wed, 27 Dec 2023 21:29:00 +0000 Subject: [PATCH] test(*): add Reservation.end() test --- src/reservation.test.ts | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/reservation.test.ts b/src/reservation.test.ts index e7defff..fb20c3e 100644 --- a/src/reservation.test.ts +++ b/src/reservation.test.ts @@ -46,6 +46,14 @@ vi.mock('./client', () => { const Client = vi.fn(); Client.prototype.httpClient = { get: vi.fn().mockResolvedValue({ + data: { + reservation: { + ...mockReservationResponse, + status: 'Ready', + }, + }, + }), + delete: vi.fn().mockResolvedValue({ data: { reservation: { ...mockReservationResponse, @@ -58,10 +66,11 @@ vi.mock('./client', () => { }); describe('Reservation', () => { + let client: Client; let reservation: Reservation; beforeEach(() => { - const client = new Client({ + client = new Client({ apiKey: 'FAKE_API_KEY', endpoint: 'FAKE_SERVEME_ENDPOINT', }); @@ -109,9 +118,20 @@ describe('Reservation', () => { }); }); - describe('#refresh', () => { + describe('#refresh()', () => { it('should refresh reservation details', async () => { await reservation.refresh(); + expect(client.httpClient.get).toHaveBeenCalledWith('/reservations/12345'); + expect(reservation.status).toEqual(ReservationStatus.ready); + }); + }); + + describe('#end()', () => { + it('should call the API', async () => { + await reservation.end(); + expect(client.httpClient.delete).toHaveBeenCalledWith( + '/reservations/12345', + ); expect(reservation.status).toEqual(ReservationStatus.ending); }); });