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(), patch: 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.updateConversationNote', () => { it('sends PATCH /conversations/:id/note with the note body', async () => { const { client, mockInstance } = makeClient(); mockInstance.patch.mockResolvedValue({ data: { error_code: 200, data: { id: 'c1', note: 'VIP guest' } }, }); await client.updateConversationNote({ conversation_id: 'c1', note: 'VIP guest' }); expect(mockInstance.patch).toHaveBeenCalledWith('/conversations/c1/note', { note: 'VIP guest', }); }); it('allows an empty string note (clears the note)', async () => { const { client, mockInstance } = makeClient(); mockInstance.patch.mockResolvedValue({ data: { error_code: 200, data: { id: 'c1', note: null } }, }); await client.updateConversationNote({ conversation_id: 'c1', note: '' }); expect(mockInstance.patch).toHaveBeenCalledWith('/conversations/c1/note', { note: '' }); }); it('throws when conversation_id is missing', async () => { const { client } = makeClient(); await expect( client.updateConversationNote({ note: 'x' } as any) ).rejects.toThrow('conversation_id is required'); }); });