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(), 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.getChannelAccounts', () => { it('sends GET /channel_accounts with filters and unwraps data', async () => { const { client, mockInstance } = makeClient(); const payload = { channel_accounts: [{ id: 1, channel_type: 'airbnb', auth_status: 'active' }], total: 1, }; mockInstance.request.mockResolvedValue({ data: { error_code: 200, data: payload }, }); const res = await client.getChannelAccounts({ channel_type: 'airbnb' }); expect(mockInstance.request).toHaveBeenCalledWith({ method: 'GET', url: '/channel_accounts', params: { channel_type: 'airbnb' }, }); expect(res).toEqual(payload); }); }); describe('HostexApiClient.getListings', () => { it('sends GET /listings with filters and unwraps data', async () => { const { client, mockInstance } = makeClient(); const payload = { listings: [{ id: 3, listing_id: 'L1' }], total: 1 }; mockInstance.request.mockResolvedValue({ data: { error_code: 200, data: payload }, }); const res = await client.getListings({ channel_account_id: 5, offset: 0, limit: 20 }); expect(mockInstance.request).toHaveBeenCalledWith({ method: 'GET', url: '/listings', params: { channel_account_id: 5, offset: 0, limit: 20 }, }); expect(res).toEqual(payload); }); });