-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapi-client.test.ts
More file actions
78 lines (71 loc) · 2.1 KB
/
Copy pathapi-client.test.ts
File metadata and controls
78 lines (71 loc) · 2.1 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
import { callAssetPackExecutionsAPI } from '../networking/api-client';
describe('callAssetPackExecutionsAPI', () => {
beforeEach(() => {
global.fetch = jest.fn();
});
it('sends the AssetPack execution payload with canonical read and pipeline fields', async () => {
const mockResponse = { ok: true, body: 'STREAM_BODY' };
(global.fetch as jest.Mock).mockResolvedValue(mockResponse);
const stream = await callAssetPackExecutionsAPI(
123,
'owner',
'repo',
'main',
'abcd',
null,
'do work',
'UTC',
'mcp',
'model-id',
[{ id: 'source-1', type: 'source', content: 'context' }],
2,
undefined,
'agentic-execution:asset-pack'
);
const [, request] = (global.fetch as jest.Mock).mock.calls[0];
expect(request).toEqual(expect.objectContaining({
method: 'POST',
headers: expect.objectContaining({
'Content-Type': 'application/json',
'X-User-Timezone': 'UTC'
})
}));
expect(JSON.parse(String(request.body))).toEqual(expect.objectContaining({
connectionId: 123,
repoOwner: 'owner',
repoName: 'repo',
repoBranch: 'main',
repoCommit: 'abcd',
issueNumber: null,
definition_of_read: 'do work',
modelProvider: 'mcp',
modelId: 'model-id',
iterationCount: 2,
pipeline_type: 'agentic-execution:asset-pack'
}));
expect(stream).toBe('STREAM_BODY');
});
it('sends multipart form data when files are present', async () => {
const mockResponse = { ok: true, body: 'STREAM_BODY' };
const file = new File(['content'], 'read.txt', { type: 'text/plain' });
(global.fetch as jest.Mock).mockResolvedValue(mockResponse);
await callAssetPackExecutionsAPI(
123,
'owner',
'repo',
'main',
'abcd',
'1',
'do work',
'UTC',
'mcp',
'model-id',
[],
3,
[file]
);
const request = (global.fetch as jest.Mock).mock.calls[0][1];
expect(request.headers).toEqual({ 'X-User-Timezone': 'UTC' });
expect(request.body).toBeInstanceOf(FormData);
});
});