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(), delete: 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.getCalendarShareLinks', () => { it('sends GET /calendar_share_links and unwraps data', async () => { const { client, mockInstance } = makeClient(); const payload = { total: 1, calendar_share_links: [{ id: 1, scope: 'entire', url: 'https://x', property_ids: [] }] }; mockInstance.request.mockResolvedValue({ data: { error_code: 200, data: payload } }); const res = await client.getCalendarShareLinks(); expect(mockInstance.request).toHaveBeenCalledWith({ method: 'GET', url: '/calendar_share_links', params: undefined, }); expect(res).toEqual(payload); }); }); describe('HostexApiClient.createCalendarShareLink', () => { it('sends POST /calendar_share_links with scope partial and property_ids', async () => { const { client, mockInstance } = makeClient(); mockInstance.post.mockResolvedValue({ data: { error_code: 200, data: { calendar_share_link: { id: 9 } } } }); await client.createCalendarShareLink({ scope: 'partial', property_ids: [1] }); expect(mockInstance.post).toHaveBeenCalledWith('/calendar_share_links', { scope: 'partial', property_ids: [1], }); }); it('rejects scope partial without property_ids', async () => { const { client } = makeClient(); await expect(client.createCalendarShareLink({ scope: 'partial' })).rejects.toThrow(); }); it('allows scope entire without property_ids', async () => { const { client, mockInstance } = makeClient(); mockInstance.post.mockResolvedValue({ data: { error_code: 200, data: { calendar_share_link: { id: 3 } } } }); await client.createCalendarShareLink({ scope: 'entire' }); expect(mockInstance.post).toHaveBeenCalledWith('/calendar_share_links', { scope: 'entire' }); }); }); describe('HostexApiClient.deleteCalendarShareLink', () => { it('sends DELETE /calendar_share_links/:id', async () => { const { client, mockInstance } = makeClient(); mockInstance.delete.mockResolvedValue({ data: { error_code: 200 } }); await client.deleteCalendarShareLink(9); expect(mockInstance.delete).toHaveBeenCalledWith('/calendar_share_links/9'); }); });