import axios from 'axios'; import { HostexApiClient } from '../client/index.js'; jest.mock('axios'); const mockedAxios = axios as jest.Mocked; describe('HostexApiClient approve/decline reservation', () => { let client: HostexApiClient; let mockInstance: any; beforeEach(() => { mockInstance = { request: jest.fn(), post: jest.fn(), interceptors: { request: { use: jest.fn() }, response: { use: jest.fn() }, }, }; mockedAxios.create.mockReturnValue(mockInstance as any); client = new HostexApiClient({ accessToken: 'test-token' }); }); describe('approveReservation', () => { it('sends POST /reservations/:code/approve', async () => { mockInstance.post.mockResolvedValue({ data: { error_code: 200, message: 'success' }, }); await client.approveReservation('RES-001'); expect(mockInstance.post).toHaveBeenCalledWith( '/reservations/RES-001/approve' ); }); it('throws when reservationCode is missing', async () => { await expect(client.approveReservation('')).rejects.toThrow(); }); }); describe('declineReservation', () => { it('sends POST /reservations/:code/decline', async () => { mockInstance.post.mockResolvedValue({ data: { error_code: 200, message: 'success' }, }); await client.declineReservation('RES-002'); expect(mockInstance.post).toHaveBeenCalledWith( '/reservations/RES-002/decline' ); }); it('throws when reservationCode is missing', async () => { await expect(client.declineReservation('')).rejects.toThrow(); }); }); });