agenthub/tests/remoteClient.test.ts
2026-06-25 12:32:11 +02:00

32 lines
985 B
TypeScript

import { describe, it, expect, beforeEach, vi } from 'vitest';
import { remoteClient, RemoteError } from '../src/cli/remoteClient.js';
describe('remoteClient', () => {
beforeEach(() => {
vi.restoreAllMocks();
globalThis.fetch = vi.fn();
});
it('creates a task remotely', async () => {
const task = { id: 'TSK-0001', title: 'Remote task', status: 'open' };
vi.mocked(fetch).mockResolvedValueOnce({
ok: true,
status: 200,
text: () => Promise.resolve(JSON.stringify(task)),
} as Response);
const result = await remoteClient.createTask('http://localhost:3377', { title: 'Remote task' });
expect(result.id).toBe('TSK-0001');
});
it('throws RemoteError on failure', async () => {
vi.mocked(fetch).mockResolvedValueOnce({
ok: false,
status: 500,
text: () => Promise.resolve('boom'),
} as Response);
await expect(remoteClient.listTasks('http://localhost:3377')).rejects.toThrow(RemoteError);
});
});