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 automation actions', () => { it('getAutomationActions sends GET /automation/actions and unwraps data', async () => { const { client, mockInstance } = makeClient(); const payload = { actions: [], total: 0 }; mockInstance.request.mockResolvedValue({ data: { error_code: 200, data: payload } }); const res = await client.getAutomationActions({ type: 'message' }); expect(mockInstance.request).toHaveBeenCalledWith({ method: 'GET', url: '/automation/actions', params: { type: 'message' }, }); expect(res).toEqual(payload); }); it('getAutomationActions throws when type is missing', async () => { const { client } = makeClient(); await expect(client.getAutomationActions({} as any)).rejects.toThrow('type is required'); }); it('deleteAutomationAction sends DELETE /automation/actions/:planId', async () => { const { client, mockInstance } = makeClient(); mockInstance.delete.mockResolvedValue({ data: { error_code: 200 } }); await client.deleteAutomationAction(12); expect(mockInstance.delete).toHaveBeenCalledWith('/automation/actions/12'); }); it('executeAutomationAction sends POST /automation/actions/:planId/execute', async () => { const { client, mockInstance } = makeClient(); mockInstance.post.mockResolvedValue({ data: { error_code: 200 } }); await client.executeAutomationAction(12); expect(mockInstance.post).toHaveBeenCalledWith('/automation/actions/12/execute'); }); });