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.updateAirbnbPriceAndRules', () => { it('sends POST /listings/airbnb/price_and_rules', async () => { const { client, mockInstance } = makeClient(); mockInstance.post.mockResolvedValue({ data: { error_code: 200 } }); await client.updateAirbnbPriceAndRules({ listing_id: 'L1', settings: { base_price: 100 } }); expect(mockInstance.post).toHaveBeenCalledWith('/listings/airbnb/price_and_rules', { listing_id: 'L1', settings: { base_price: 100 }, }); }); it('throws when listing_id is missing', async () => { const { client } = makeClient(); await expect( client.updateAirbnbPriceAndRules({ settings: {} } as any) ).rejects.toThrow('listing_id is required'); }); it('throws when settings is missing', async () => { const { client } = makeClient(); await expect( client.updateAirbnbPriceAndRules({ listing_id: 'L1' } as any) ).rejects.toThrow('settings is required'); }); }); describe('HostexApiClient.updateVrboPriceAndRules', () => { it('sends POST /listings/vrbo/price_and_rules', async () => { const { client, mockInstance } = makeClient(); mockInstance.post.mockResolvedValue({ data: { error_code: 200 } }); await client.updateVrboPriceAndRules({ listing_id: 'L2', settings: { minimum_stay: 2 } }); expect(mockInstance.post).toHaveBeenCalledWith('/listings/vrbo/price_and_rules', { listing_id: 'L2', settings: { minimum_stay: 2 }, }); }); }); describe('HostexApiClient.getPricingRatios', () => { it('sends GET /pricing_ratios with property_id', async () => { const { client, mockInstance } = makeClient(); const payload = { link_type: 'property', link_id: 3, channels: [] }; mockInstance.request.mockResolvedValue({ data: { error_code: 200, data: payload } }); const res = await client.getPricingRatios({ property_id: 3 }); expect(mockInstance.request).toHaveBeenCalledWith({ method: 'GET', url: '/pricing_ratios', params: { property_id: 3 }, }); expect(res).toEqual(payload); }); it('rejects when neither property_id nor room_type_id is provided', async () => { const { client } = makeClient(); await expect(client.getPricingRatios({})).rejects.toThrow( 'Exactly one of property_id or room_type_id is required' ); }); it('rejects when both property_id and room_type_id are provided', async () => { const { client } = makeClient(); await expect( client.getPricingRatios({ property_id: 1, room_type_id: 2 }) ).rejects.toThrow('Exactly one of property_id or room_type_id is required'); }); });