import axios from 'axios'; import { HostexApiClient } from '../client/index.js'; jest.mock('axios'); const mockedAxios = axios as jest.Mocked; function makeClient() { const mockInstance = { request: jest.fn(), patch: jest.fn(), interceptors: { request: { use: jest.fn() }, response: { use: jest.fn() } }, }; mockedAxios.create.mockReturnValue(mockInstance as any); return { client: new HostexApiClient({ accessToken: 'test-token' }), mockInstance }; } describe('HostexApiClient.updateReservationBasicInfo', () => { it('targets the stay_code and strips both codes from the body', async () => { const { client, mockInstance } = makeClient(); mockInstance.patch.mockResolvedValue({ data: { error_code: 200 } }); await client.updateReservationBasicInfo({ stay_code: 'ST1', remarks: 'late arrival' }); expect(mockInstance.patch).toHaveBeenCalledWith('/reservations/ST1', { remarks: 'late arrival', }); }); it('falls back to reservation_code for backward compatibility', async () => { const { client, mockInstance } = makeClient(); mockInstance.patch.mockResolvedValue({ data: { error_code: 200 } }); await client.updateReservationBasicInfo({ reservation_code: 'R1', remarks: 'x' }); expect(mockInstance.patch).toHaveBeenCalledWith('/reservations/R1', { remarks: 'x' }); }); it('throws when both stay_code and reservation_code are missing', async () => { const { client } = makeClient(); await expect( client.updateReservationBasicInfo({ remarks: 'x' } as any) ).rejects.toThrow('stay_code is required'); }); });