-
Notifications
You must be signed in to change notification settings - Fork 453
Expand file tree
/
Copy pathAgentTaskApi.test.ts
More file actions
98 lines (86 loc) · 2.99 KB
/
AgentTaskApi.test.ts
File metadata and controls
98 lines (86 loc) · 2.99 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
import { http, HttpResponse } from 'msw';
import { describe, expect, it } from 'vitest';
import { server, validateHeaders } from '../../mock-server';
import { createBackendApiClient } from '../factory';
describe('AgentTaskAPI', () => {
const apiClient = createBackendApiClient({
apiUrl: 'https://api.clerk.test',
secretKey: 'deadbeef',
});
const mockAgentTaskResponse = {
object: 'agent_task',
agent_id: 'agent_123',
task_id: 'agent_task_456',
agent_task_id: 'agent_task_456',
url: 'https://example.com/agent-task',
};
describe('create', () => {
it('converts nested onBehalfOf.userId to snake_case', async () => {
server.use(
http.post(
'https://api.clerk.test/v1/agents/tasks',
validateHeaders(async ({ request }) => {
const body = await request.json();
expect(body).toEqual({
on_behalf_of: {
user_id: 'user_123',
},
permissions: 'read,write',
agent_name: 'test-agent',
task_description: 'Test task',
redirect_url: 'https://example.com/callback',
session_max_duration_in_seconds: 1800,
});
return HttpResponse.json(mockAgentTaskResponse);
}),
),
);
const response = await apiClient.agentTasks.create({
onBehalfOf: {
userId: 'user_123',
},
permissions: 'read,write',
agentName: 'test-agent',
taskDescription: 'Test task',
redirectUrl: 'https://example.com/callback',
sessionMaxDurationInSeconds: 1800,
});
expect(response.agentId).toBe('agent_123');
expect(response.taskId).toBe('agent_task_456');
expect(response.agentTaskId).toBe('agent_task_456');
expect(response.url).toBe('https://example.com/agent-task');
});
it('converts nested onBehalfOf.identifier to snake_case', async () => {
server.use(
http.post(
'https://api.clerk.test/v1/agents/tasks',
validateHeaders(async ({ request }) => {
const body = await request.json();
expect(body).toEqual({
on_behalf_of: {
identifier: 'user@example.com',
},
permissions: 'read',
agent_name: 'test-agent',
task_description: 'Test task',
redirect_url: 'https://example.com/callback',
});
return HttpResponse.json(mockAgentTaskResponse);
}),
),
);
const response = await apiClient.agentTasks.create({
onBehalfOf: {
identifier: 'user@example.com',
},
permissions: 'read',
agentName: 'test-agent',
taskDescription: 'Test task',
redirectUrl: 'https://example.com/callback',
});
expect(response.agentId).toBe('agent_123');
expect(response.taskId).toBe('agent_task_456');
expect(response.agentTaskId).toBe('agent_task_456');
});
});
});