forked from Lilly-Protocol/lily-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent-client.test.ts
More file actions
112 lines (95 loc) · 2.84 KB
/
Copy pathagent-client.test.ts
File metadata and controls
112 lines (95 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { describe, expect, it, vi } from 'vitest';
import { AgentClient } from '../src/clients/agent-client';
import type { Agent, CreateAgentRequest, UpdateAgentRequest } from '../src/models';
import { createMockHttpClient } from './helpers/mock-http-client';
describe('AgentClient', () => {
const mockAgent: Agent = {
id: 'agent_123',
name: 'Research Agent',
status: 'active',
capabilities: ['search', 'analyze'],
createdAt: '2026-09-01T00:00:00.000Z',
updatedAt: '2026-09-01T00:00:00.000Z',
};
it('lists agents with query parameters', async () => {
const requestSpy = vi.fn(() =>
Promise.resolve({
status: 200,
headers: new Headers(),
data: [mockAgent],
}),
);
const client = new AgentClient(createMockHttpClient(requestSpy));
const agents = await client.list({ limit: 10, status: 'active' });
expect(requestSpy).toHaveBeenCalledWith({
method: 'GET',
path: '/v1/agents',
query: {
limit: 10,
status: 'active',
},
});
expect(agents).toEqual([mockAgent]);
});
it('gets an agent by id', async () => {
const requestSpy = vi.fn(() =>
Promise.resolve({
status: 200,
headers: new Headers(),
data: mockAgent,
}),
);
const client = new AgentClient(createMockHttpClient(requestSpy));
const agent = await client.get('agent_123');
expect(requestSpy).toHaveBeenCalledWith({
method: 'GET',
path: '/v1/agents/agent_123',
});
expect(agent).toEqual(mockAgent);
});
it('creates an agent with payload', async () => {
const requestSpy = vi.fn(() =>
Promise.resolve({
status: 201,
headers: new Headers(),
data: mockAgent,
}),
);
const createPayload: CreateAgentRequest = {
name: 'Research Agent',
capabilities: ['search', 'analyze'],
};
const client = new AgentClient(createMockHttpClient(requestSpy));
const agent = await client.create(createPayload);
expect(requestSpy).toHaveBeenCalledWith({
method: 'POST',
path: '/v1/agents',
body: createPayload,
});
expect(agent).toEqual(mockAgent);
});
it('updates an agent by id', async () => {
const updatedAgent: Agent = {
...mockAgent,
status: 'paused',
};
const requestSpy = vi.fn(() =>
Promise.resolve({
status: 200,
headers: new Headers(),
data: updatedAgent,
}),
);
const updatePayload: UpdateAgentRequest = {
status: 'paused',
};
const client = new AgentClient(createMockHttpClient(requestSpy));
const agent = await client.update('agent_123', updatePayload);
expect(requestSpy).toHaveBeenCalledWith({
method: 'PATCH',
path: '/v1/agents/agent_123',
body: updatePayload,
});
expect(agent.status).toBe('paused');
});
});