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(), post: 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.createProperty', () => { it('sends POST /properties with title', async () => { const { client, mockInstance } = makeClient(); mockInstance.post.mockResolvedValue({ data: { error_code: 200, data: { property_id: 42 } }, }); const res = await client.createProperty({ title: 'Sea View Loft' }); expect(mockInstance.post).toHaveBeenCalledWith('/properties', { title: 'Sea View Loft' }); expect(res.data?.property_id).toBe(42); }); it('throws when title is missing', async () => { const { client } = makeClient(); await expect(client.createProperty({} as any)).rejects.toThrow('title is required'); }); }); describe('HostexApiClient.createRoomType', () => { it('sends POST /room_types with title and property_ids', async () => { const { client, mockInstance } = makeClient(); mockInstance.post.mockResolvedValue({ data: { error_code: 200, data: { room_type_id: 7 } }, }); const res = await client.createRoomType({ title: 'Deluxe King', property_ids: [1, 2] }); expect(mockInstance.post).toHaveBeenCalledWith('/room_types', { title: 'Deluxe King', property_ids: [1, 2], }); expect(res.data?.room_type_id).toBe(7); }); it('throws when title is missing', async () => { const { client } = makeClient(); await expect(client.createRoomType({} as any)).rejects.toThrow('title is required'); }); });