@mastra/client-js 0.1.0-alpha.17 → 0.1.0-alpha.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +15 -0
- package/CHANGELOG.md +7 -0
- package/README.md +21 -10
- package/dist/index.d.mts +17 -0
- package/dist/index.mjs +30 -0
- package/eslint.config.js +6 -0
- package/package.json +11 -10
- package/src/client.ts +170 -155
- package/src/example.ts +33 -33
- package/src/index.test.ts +541 -531
- package/src/index.ts +1 -1
- package/src/resources/agent.ts +99 -98
- package/src/resources/base.ts +54 -54
- package/src/resources/index.ts +1 -1
- package/src/resources/memory-thread.ts +50 -48
- package/src/resources/tool.ts +25 -24
- package/src/resources/vector.ts +72 -71
- package/src/resources/workflow.ts +62 -25
- package/src/types.ts +92 -86
- package/tsconfig.json +4 -28
- package/.eslintrc.js +0 -10
- package/.prettierignore +0 -3
- package/.prettierrc.json +0 -26
package/src/index.test.ts
CHANGED
|
@@ -1,587 +1,597 @@
|
|
|
1
|
-
import { describe, expect, beforeEach, it, vi } from 'vitest';
|
|
2
|
-
import { MastraClient } from "./client";
|
|
3
1
|
import type { MessageType } from '@mastra/core';
|
|
2
|
+
import { describe, expect, beforeEach, it, vi } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import { MastraClient } from './client';
|
|
4
5
|
|
|
5
6
|
// Mock fetch globally
|
|
6
7
|
global.fetch = vi.fn();
|
|
7
8
|
|
|
8
9
|
describe('MastraClient Resources', () => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
let client: MastraClient;
|
|
11
|
+
const clientOptions = {
|
|
12
|
+
baseUrl: 'http://localhost:4111',
|
|
13
|
+
headers: {
|
|
14
|
+
Authorization: 'Bearer test-key',
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// Helper to mock successful API responses
|
|
19
|
+
const mockFetchResponse = (data: any, options: { isStream?: boolean } = {}) => {
|
|
20
|
+
if (options.isStream) {
|
|
21
|
+
const stream = new ReadableStream({
|
|
22
|
+
start(controller) {
|
|
23
|
+
controller.enqueue(new TextEncoder().encode(JSON.stringify(data)));
|
|
24
|
+
controller.close();
|
|
25
|
+
},
|
|
26
|
+
});
|
|
27
|
+
(global.fetch as any).mockResolvedValueOnce({
|
|
28
|
+
ok: true,
|
|
29
|
+
headers: {
|
|
30
|
+
get: (name: string) => (name === 'Content-Type' ? 'text/event-stream' : null),
|
|
31
|
+
},
|
|
32
|
+
body: stream,
|
|
33
|
+
});
|
|
34
|
+
} else {
|
|
35
|
+
(global.fetch as any).mockResolvedValueOnce({
|
|
36
|
+
ok: true,
|
|
12
37
|
headers: {
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
headers: {
|
|
29
|
-
get: (name: string) => name === 'Content-Type' ? 'text/event-stream' : null
|
|
30
|
-
},
|
|
31
|
-
body: stream
|
|
32
|
-
});
|
|
33
|
-
} else {
|
|
34
|
-
(global.fetch as any).mockResolvedValueOnce({
|
|
35
|
-
ok: true,
|
|
36
|
-
headers: {
|
|
37
|
-
get: (name: string) => name === 'Content-Type' ? 'application/json' : null
|
|
38
|
-
},
|
|
39
|
-
json: async () => data
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
};
|
|
38
|
+
get: (name: string) => (name === 'Content-Type' ? 'application/json' : null),
|
|
39
|
+
},
|
|
40
|
+
json: async () => data,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
beforeEach(() => {
|
|
46
|
+
vi.clearAllMocks();
|
|
47
|
+
client = new MastraClient(clientOptions);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('Vector Resource', () => {
|
|
51
|
+
const vectorName = 'test-vector';
|
|
52
|
+
let vector: ReturnType<typeof client.getVector>;
|
|
43
53
|
|
|
44
54
|
beforeEach(() => {
|
|
45
|
-
|
|
46
|
-
client = new MastraClient(clientOptions);
|
|
55
|
+
vector = client.getVector(vectorName);
|
|
47
56
|
});
|
|
48
57
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
58
|
+
it('should get vector index details', async () => {
|
|
59
|
+
const mockResponse = {
|
|
60
|
+
dimension: 128,
|
|
61
|
+
metric: 'cosine',
|
|
62
|
+
count: 1000,
|
|
63
|
+
};
|
|
64
|
+
mockFetchResponse(mockResponse);
|
|
65
|
+
|
|
66
|
+
const result = await vector.details('test-index');
|
|
67
|
+
expect(result).toEqual(mockResponse);
|
|
68
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
69
|
+
`${clientOptions.baseUrl}/api/vector/test-vector/indexes/test-index`,
|
|
70
|
+
expect.objectContaining({
|
|
71
|
+
headers: expect.objectContaining(clientOptions.headers),
|
|
72
|
+
}),
|
|
73
|
+
);
|
|
74
|
+
});
|
|
52
75
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
76
|
+
it('should delete vector index', async () => {
|
|
77
|
+
mockFetchResponse({ success: true });
|
|
78
|
+
const result = await vector.delete('test-index');
|
|
79
|
+
expect(result).toEqual({ success: true });
|
|
80
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
81
|
+
`${clientOptions.baseUrl}/api/vector/test-vector/indexes/test-index`,
|
|
82
|
+
expect.objectContaining({
|
|
83
|
+
method: 'DELETE',
|
|
84
|
+
headers: expect.objectContaining(clientOptions.headers),
|
|
85
|
+
}),
|
|
86
|
+
);
|
|
87
|
+
});
|
|
56
88
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
expect.objectContaining({
|
|
70
|
-
headers: expect.objectContaining(clientOptions.headers)
|
|
71
|
-
})
|
|
72
|
-
);
|
|
73
|
-
});
|
|
89
|
+
it('should get all indexes', async () => {
|
|
90
|
+
const mockResponse = { indexes: ['index1', 'index2'] };
|
|
91
|
+
mockFetchResponse(mockResponse);
|
|
92
|
+
const result = await vector.getIndexes();
|
|
93
|
+
expect(result).toEqual(mockResponse);
|
|
94
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
95
|
+
`${clientOptions.baseUrl}/api/vector/test-vector/indexes`,
|
|
96
|
+
expect.objectContaining({
|
|
97
|
+
headers: expect.objectContaining(clientOptions.headers),
|
|
98
|
+
}),
|
|
99
|
+
);
|
|
100
|
+
});
|
|
74
101
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
102
|
+
it('should create vector index with all parameters', async () => {
|
|
103
|
+
mockFetchResponse({ success: true });
|
|
104
|
+
const result = await vector.createIndex({
|
|
105
|
+
indexName: 'test-index',
|
|
106
|
+
dimension: 128,
|
|
107
|
+
metric: 'cosine',
|
|
108
|
+
});
|
|
109
|
+
expect(result).toEqual({ success: true });
|
|
110
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
111
|
+
`${clientOptions.baseUrl}/api/vector/test-vector/create-index`,
|
|
112
|
+
expect.objectContaining({
|
|
113
|
+
method: 'POST',
|
|
114
|
+
headers: expect.objectContaining(clientOptions.headers),
|
|
115
|
+
body: JSON.stringify({
|
|
116
|
+
indexName: 'test-index',
|
|
117
|
+
dimension: 128,
|
|
118
|
+
metric: 'cosine',
|
|
119
|
+
}),
|
|
120
|
+
}),
|
|
121
|
+
);
|
|
122
|
+
});
|
|
87
123
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
124
|
+
it('should upsert vectors with metadata and ids', async () => {
|
|
125
|
+
const mockResponse = ['id1', 'id2'];
|
|
126
|
+
mockFetchResponse(mockResponse);
|
|
127
|
+
const result = await vector.upsert({
|
|
128
|
+
indexName: 'test-index',
|
|
129
|
+
vectors: [
|
|
130
|
+
[1, 2],
|
|
131
|
+
[3, 4],
|
|
132
|
+
],
|
|
133
|
+
metadata: [{ label: 'a' }, { label: 'b' }],
|
|
134
|
+
ids: ['id1', 'id2'],
|
|
135
|
+
});
|
|
136
|
+
expect(result).toEqual(mockResponse);
|
|
137
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
138
|
+
`${clientOptions.baseUrl}/api/vector/test-vector/upsert`,
|
|
139
|
+
expect.objectContaining({
|
|
140
|
+
method: 'POST',
|
|
141
|
+
headers: expect.objectContaining(clientOptions.headers),
|
|
142
|
+
body: JSON.stringify({
|
|
143
|
+
indexName: 'test-index',
|
|
144
|
+
vectors: [
|
|
145
|
+
[1, 2],
|
|
146
|
+
[3, 4],
|
|
147
|
+
],
|
|
148
|
+
metadata: [{ label: 'a' }, { label: 'b' }],
|
|
149
|
+
ids: ['id1', 'id2'],
|
|
150
|
+
}),
|
|
151
|
+
}),
|
|
152
|
+
);
|
|
153
|
+
});
|
|
100
154
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
155
|
+
it('should query vectors with all parameters', async () => {
|
|
156
|
+
const mockResponse = {
|
|
157
|
+
results: [
|
|
158
|
+
{
|
|
159
|
+
id: 'id1',
|
|
160
|
+
score: 0.9,
|
|
161
|
+
metadata: { label: 'a' },
|
|
162
|
+
vector: [1, 2],
|
|
163
|
+
},
|
|
164
|
+
],
|
|
165
|
+
};
|
|
166
|
+
mockFetchResponse(mockResponse);
|
|
167
|
+
const result = await vector.query({
|
|
168
|
+
indexName: 'test-index',
|
|
169
|
+
queryVector: [1, 2],
|
|
170
|
+
topK: 10,
|
|
171
|
+
filter: { label: 'a' },
|
|
172
|
+
includeVector: true,
|
|
173
|
+
});
|
|
174
|
+
expect(result).toEqual(mockResponse);
|
|
175
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
176
|
+
`${clientOptions.baseUrl}/api/vector/test-vector/query`,
|
|
177
|
+
expect.objectContaining({
|
|
178
|
+
method: 'POST',
|
|
179
|
+
headers: expect.objectContaining(clientOptions.headers),
|
|
180
|
+
body: JSON.stringify({
|
|
181
|
+
indexName: 'test-index',
|
|
182
|
+
queryVector: [1, 2],
|
|
183
|
+
topK: 10,
|
|
184
|
+
filter: { label: 'a' },
|
|
185
|
+
includeVector: true,
|
|
186
|
+
}),
|
|
187
|
+
}),
|
|
188
|
+
);
|
|
189
|
+
});
|
|
190
|
+
});
|
|
122
191
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
const result = await vector.upsert({
|
|
127
|
-
indexName: 'test-index',
|
|
128
|
-
vectors: [[1, 2], [3, 4]],
|
|
129
|
-
metadata: [{ label: 'a' }, { label: 'b' }],
|
|
130
|
-
ids: ['id1', 'id2']
|
|
131
|
-
});
|
|
132
|
-
expect(result).toEqual(mockResponse);
|
|
133
|
-
expect(global.fetch).toHaveBeenCalledWith(
|
|
134
|
-
`${clientOptions.baseUrl}/api/vector/test-vector/upsert`,
|
|
135
|
-
expect.objectContaining({
|
|
136
|
-
method: 'POST',
|
|
137
|
-
headers: expect.objectContaining(clientOptions.headers),
|
|
138
|
-
body: JSON.stringify({
|
|
139
|
-
indexName: 'test-index',
|
|
140
|
-
vectors: [[1, 2], [3, 4]],
|
|
141
|
-
metadata: [{ label: 'a' }, { label: 'b' }],
|
|
142
|
-
ids: ['id1', 'id2']
|
|
143
|
-
})
|
|
144
|
-
})
|
|
145
|
-
);
|
|
146
|
-
});
|
|
192
|
+
describe('Agent Resource', () => {
|
|
193
|
+
const agentId = 'test-agent';
|
|
194
|
+
let agent: ReturnType<typeof client.getAgent>;
|
|
147
195
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
results: [{
|
|
151
|
-
id: 'id1',
|
|
152
|
-
score: 0.9,
|
|
153
|
-
metadata: { label: 'a' },
|
|
154
|
-
vector: [1, 2]
|
|
155
|
-
}]
|
|
156
|
-
};
|
|
157
|
-
mockFetchResponse(mockResponse);
|
|
158
|
-
const result = await vector.query({
|
|
159
|
-
indexName: 'test-index',
|
|
160
|
-
queryVector: [1, 2],
|
|
161
|
-
topK: 10,
|
|
162
|
-
filter: { label: 'a' },
|
|
163
|
-
includeVector: true
|
|
164
|
-
});
|
|
165
|
-
expect(result).toEqual(mockResponse);
|
|
166
|
-
expect(global.fetch).toHaveBeenCalledWith(
|
|
167
|
-
`${clientOptions.baseUrl}/api/vector/test-vector/query`,
|
|
168
|
-
expect.objectContaining({
|
|
169
|
-
method: 'POST',
|
|
170
|
-
headers: expect.objectContaining(clientOptions.headers),
|
|
171
|
-
body: JSON.stringify({
|
|
172
|
-
indexName: 'test-index',
|
|
173
|
-
queryVector: [1, 2],
|
|
174
|
-
topK: 10,
|
|
175
|
-
filter: { label: 'a' },
|
|
176
|
-
includeVector: true
|
|
177
|
-
})
|
|
178
|
-
})
|
|
179
|
-
);
|
|
180
|
-
});
|
|
196
|
+
beforeEach(() => {
|
|
197
|
+
agent = client.getAgent(agentId);
|
|
181
198
|
});
|
|
182
199
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
200
|
+
it('should get all agents', async () => {
|
|
201
|
+
const mockResponse = {
|
|
202
|
+
agent1: { name: 'Agent 1', model: 'gpt-4' },
|
|
203
|
+
agent2: { name: 'Agent 2', model: 'gpt-3.5' },
|
|
204
|
+
};
|
|
205
|
+
mockFetchResponse(mockResponse);
|
|
206
|
+
const result = await client.getAgents();
|
|
207
|
+
expect(result).toEqual(mockResponse);
|
|
208
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
209
|
+
`${clientOptions.baseUrl}/api/agents`,
|
|
210
|
+
expect.objectContaining({
|
|
211
|
+
headers: expect.objectContaining(clientOptions.headers),
|
|
212
|
+
}),
|
|
213
|
+
);
|
|
214
|
+
});
|
|
186
215
|
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
216
|
+
it('should get agent details', async () => {
|
|
217
|
+
const mockResponse = {
|
|
218
|
+
name: 'Test Agent',
|
|
219
|
+
model: 'gpt-4',
|
|
220
|
+
instructions: 'Test instructions',
|
|
221
|
+
tools: {},
|
|
222
|
+
};
|
|
223
|
+
mockFetchResponse(mockResponse);
|
|
224
|
+
|
|
225
|
+
const result = await agent.details();
|
|
226
|
+
expect(result).toEqual(mockResponse);
|
|
227
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
228
|
+
`${clientOptions.baseUrl}/api/agents/test-agent`,
|
|
229
|
+
expect.objectContaining({
|
|
230
|
+
headers: expect.objectContaining(clientOptions.headers),
|
|
231
|
+
}),
|
|
232
|
+
);
|
|
233
|
+
});
|
|
190
234
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
}
|
|
235
|
+
it('should generate response', async () => {
|
|
236
|
+
const mockResponse = {
|
|
237
|
+
response: 'Generated response',
|
|
238
|
+
};
|
|
239
|
+
mockFetchResponse(mockResponse);
|
|
240
|
+
|
|
241
|
+
const result = await agent.generate({
|
|
242
|
+
messages: [],
|
|
243
|
+
threadId: 'test-thread',
|
|
244
|
+
resourceid: 'test-resource',
|
|
245
|
+
output: {},
|
|
246
|
+
});
|
|
247
|
+
expect(result).toEqual(mockResponse);
|
|
248
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
249
|
+
`${clientOptions.baseUrl}/api/agents/test-agent/generate`,
|
|
250
|
+
expect.objectContaining({
|
|
251
|
+
method: 'POST',
|
|
252
|
+
headers: expect.objectContaining(clientOptions.headers),
|
|
253
|
+
body: JSON.stringify({
|
|
254
|
+
messages: [],
|
|
255
|
+
threadId: 'test-thread',
|
|
256
|
+
resourceid: 'test-resource',
|
|
257
|
+
output: {},
|
|
258
|
+
}),
|
|
259
|
+
}),
|
|
260
|
+
);
|
|
261
|
+
});
|
|
206
262
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
263
|
+
it('should stream responses', async () => {
|
|
264
|
+
const mockChunk = { content: 'test response' };
|
|
265
|
+
mockFetchResponse(mockChunk, { isStream: true });
|
|
266
|
+
|
|
267
|
+
const response = await agent.stream({
|
|
268
|
+
messages: [
|
|
269
|
+
{
|
|
270
|
+
role: 'user',
|
|
271
|
+
content: 'test',
|
|
272
|
+
},
|
|
273
|
+
],
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
expect(response.body).toBeInstanceOf(ReadableStream);
|
|
277
|
+
const reader = response?.body?.getReader();
|
|
278
|
+
expect(reader).toBeDefined();
|
|
279
|
+
|
|
280
|
+
if (reader) {
|
|
281
|
+
const { value, done } = await reader.read();
|
|
282
|
+
expect(done).toBe(false);
|
|
283
|
+
expect(new TextDecoder().decode(value)).toBe(JSON.stringify(mockChunk));
|
|
284
|
+
}
|
|
285
|
+
});
|
|
225
286
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
expect.objectContaining({
|
|
242
|
-
method: 'POST',
|
|
243
|
-
headers: expect.objectContaining(clientOptions.headers),
|
|
244
|
-
body: JSON.stringify({
|
|
245
|
-
messages: [],
|
|
246
|
-
threadId: 'test-thread',
|
|
247
|
-
resourceid: 'test-resource',
|
|
248
|
-
output: {}
|
|
249
|
-
})
|
|
250
|
-
})
|
|
251
|
-
);
|
|
252
|
-
});
|
|
287
|
+
it('should get agent tool', async () => {
|
|
288
|
+
const mockResponse = {
|
|
289
|
+
id: 'tool1',
|
|
290
|
+
description: 'Test Tool',
|
|
291
|
+
};
|
|
292
|
+
mockFetchResponse(mockResponse);
|
|
293
|
+
const result = await agent.getTool('tool1');
|
|
294
|
+
expect(result).toEqual(mockResponse);
|
|
295
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
296
|
+
`${clientOptions.baseUrl}/api/agents/test-agent/tools/tool1`,
|
|
297
|
+
expect.objectContaining({
|
|
298
|
+
headers: expect.objectContaining(clientOptions.headers),
|
|
299
|
+
}),
|
|
300
|
+
);
|
|
301
|
+
});
|
|
253
302
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
expect(response.body).toBeInstanceOf(ReadableStream);
|
|
270
|
-
const reader = response?.body?.getReader();
|
|
271
|
-
expect(reader).toBeDefined();
|
|
272
|
-
|
|
273
|
-
if (reader) {
|
|
274
|
-
const { value, done } = await reader.read();
|
|
275
|
-
expect(done).toBe(false);
|
|
276
|
-
expect(new TextDecoder().decode(value)).toBe(JSON.stringify(mockChunk));
|
|
277
|
-
}
|
|
278
|
-
});
|
|
303
|
+
it('should get agent evals', async () => {
|
|
304
|
+
const mockResponse = {
|
|
305
|
+
name: 'Test Agent',
|
|
306
|
+
evals: [{ id: 'eval1' }],
|
|
307
|
+
};
|
|
308
|
+
mockFetchResponse(mockResponse);
|
|
309
|
+
const result = await agent.evals();
|
|
310
|
+
expect(result).toEqual(mockResponse);
|
|
311
|
+
expect(global.fetch).toHaveBeenCalledWith(`${clientOptions.baseUrl}/api/agents/test-agent/evals/ci`, {
|
|
312
|
+
headers: {
|
|
313
|
+
Authorization: 'Bearer test-key',
|
|
314
|
+
'Content-Type': 'application/json',
|
|
315
|
+
},
|
|
316
|
+
});
|
|
317
|
+
});
|
|
279
318
|
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
319
|
+
it('should get live evals', async () => {
|
|
320
|
+
const mockResponse = {
|
|
321
|
+
name: 'Test Agent',
|
|
322
|
+
evals: [{ id: 'eval1', live: true }],
|
|
323
|
+
};
|
|
324
|
+
mockFetchResponse(mockResponse);
|
|
325
|
+
const result = await agent.liveEvals();
|
|
326
|
+
expect(result).toEqual(mockResponse);
|
|
327
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
328
|
+
`${clientOptions.baseUrl}/api/agents/test-agent/evals/live`,
|
|
329
|
+
expect.objectContaining({
|
|
330
|
+
headers: expect.objectContaining(clientOptions.headers),
|
|
331
|
+
}),
|
|
332
|
+
);
|
|
333
|
+
});
|
|
334
|
+
});
|
|
295
335
|
|
|
296
|
-
|
|
297
|
-
const mockResponse = {
|
|
298
|
-
name: 'Test Agent',
|
|
299
|
-
evals: [{ id: 'eval1' }]
|
|
300
|
-
};
|
|
301
|
-
mockFetchResponse(mockResponse);
|
|
302
|
-
const result = await agent.evals();
|
|
303
|
-
expect(result).toEqual(mockResponse);
|
|
304
|
-
expect(global.fetch).toHaveBeenCalledWith(
|
|
305
|
-
`${clientOptions.baseUrl}/api/agents/test-agent/evals`,
|
|
306
|
-
expect.objectContaining({
|
|
307
|
-
headers: expect.objectContaining(clientOptions.headers)
|
|
308
|
-
})
|
|
309
|
-
);
|
|
310
|
-
});
|
|
336
|
+
const agentId = 'test-agent';
|
|
311
337
|
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
const result = await agent.liveEvals();
|
|
319
|
-
expect(result).toEqual(mockResponse);
|
|
320
|
-
expect(global.fetch).toHaveBeenCalledWith(
|
|
321
|
-
`${clientOptions.baseUrl}/api/agents/test-agent/evals/live`,
|
|
322
|
-
expect.objectContaining({
|
|
323
|
-
headers: expect.objectContaining(clientOptions.headers)
|
|
324
|
-
})
|
|
325
|
-
);
|
|
326
|
-
});
|
|
338
|
+
describe('Memory Thread Resource', () => {
|
|
339
|
+
const threadId = 'test-thread';
|
|
340
|
+
let memoryThread: ReturnType<typeof client.getMemoryThread>;
|
|
341
|
+
|
|
342
|
+
beforeEach(() => {
|
|
343
|
+
memoryThread = client.getMemoryThread(threadId, agentId);
|
|
327
344
|
});
|
|
328
345
|
|
|
329
|
-
|
|
346
|
+
it('should get thread details', async () => {
|
|
347
|
+
const mockResponse = {
|
|
348
|
+
id: threadId,
|
|
349
|
+
title: 'Test Thread',
|
|
350
|
+
metadata: {},
|
|
351
|
+
};
|
|
352
|
+
mockFetchResponse(mockResponse);
|
|
353
|
+
|
|
354
|
+
const result = await memoryThread.get();
|
|
355
|
+
expect(result).toEqual(mockResponse);
|
|
356
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
357
|
+
`${clientOptions.baseUrl}/api/memory/threads/test-thread?agentId=${agentId}`,
|
|
358
|
+
expect.objectContaining({
|
|
359
|
+
headers: expect.objectContaining(clientOptions.headers),
|
|
360
|
+
}),
|
|
361
|
+
);
|
|
362
|
+
});
|
|
330
363
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
364
|
+
it('should update thread', async () => {
|
|
365
|
+
const mockResponse = {
|
|
366
|
+
id: threadId,
|
|
367
|
+
title: 'Updated Thread',
|
|
368
|
+
metadata: { updated: true },
|
|
369
|
+
};
|
|
370
|
+
mockFetchResponse(mockResponse);
|
|
371
|
+
|
|
372
|
+
const result = await memoryThread.update({
|
|
373
|
+
title: 'Updated Thread',
|
|
374
|
+
metadata: { updated: true },
|
|
375
|
+
resourceid: 'test-resource',
|
|
376
|
+
});
|
|
377
|
+
expect(result).toEqual(mockResponse);
|
|
378
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
379
|
+
`${clientOptions.baseUrl}/api/memory/threads/test-thread?agentId=${agentId}`,
|
|
380
|
+
expect.objectContaining({
|
|
381
|
+
method: 'PATCH',
|
|
382
|
+
headers: expect.objectContaining(clientOptions.headers),
|
|
383
|
+
}),
|
|
384
|
+
);
|
|
385
|
+
});
|
|
334
386
|
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
387
|
+
it('should delete thread', async () => {
|
|
388
|
+
const mockResponse = { result: 'deleted' };
|
|
389
|
+
mockFetchResponse(mockResponse);
|
|
390
|
+
const result = await memoryThread.delete();
|
|
391
|
+
expect(result).toEqual(mockResponse);
|
|
392
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
393
|
+
`${clientOptions.baseUrl}/api/memory/threads/test-thread?agentId=${agentId}`,
|
|
394
|
+
expect.objectContaining({
|
|
395
|
+
method: 'DELETE',
|
|
396
|
+
headers: expect.objectContaining(clientOptions.headers),
|
|
397
|
+
}),
|
|
398
|
+
);
|
|
399
|
+
});
|
|
338
400
|
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
expect.objectContaining({
|
|
352
|
-
headers: expect.objectContaining(clientOptions.headers)
|
|
353
|
-
})
|
|
354
|
-
);
|
|
355
|
-
});
|
|
401
|
+
it('should get memory status', async () => {
|
|
402
|
+
const mockResponse = { result: true };
|
|
403
|
+
mockFetchResponse(mockResponse);
|
|
404
|
+
const result = await client.getMemoryStatus(agentId);
|
|
405
|
+
expect(result).toEqual(mockResponse);
|
|
406
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
407
|
+
`${clientOptions.baseUrl}/api/memory/status?agentId=${agentId}`,
|
|
408
|
+
expect.objectContaining({
|
|
409
|
+
headers: expect.objectContaining(clientOptions.headers),
|
|
410
|
+
}),
|
|
411
|
+
);
|
|
412
|
+
});
|
|
356
413
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
414
|
+
it('should save messages to memory', async () => {
|
|
415
|
+
const messages: MessageType[] = [
|
|
416
|
+
{
|
|
417
|
+
id: '1',
|
|
418
|
+
type: 'text',
|
|
419
|
+
content: 'test',
|
|
420
|
+
role: 'user',
|
|
421
|
+
threadId: 'test-thread',
|
|
422
|
+
createdAt: new Date(),
|
|
423
|
+
},
|
|
424
|
+
];
|
|
425
|
+
mockFetchResponse(messages);
|
|
426
|
+
const result = await client.saveMessageToMemory({ messages, agentId });
|
|
427
|
+
expect(result).toEqual(messages);
|
|
428
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
429
|
+
`${clientOptions.baseUrl}/api/memory/save-messages?agentId=${agentId}`,
|
|
430
|
+
{
|
|
431
|
+
method: 'POST',
|
|
432
|
+
headers: {
|
|
433
|
+
Authorization: 'Bearer test-key',
|
|
434
|
+
'Content-Type': 'application/json',
|
|
435
|
+
},
|
|
436
|
+
body: JSON.stringify({ messages, agentId }),
|
|
437
|
+
},
|
|
438
|
+
);
|
|
439
|
+
});
|
|
440
|
+
});
|
|
379
441
|
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
const result = await memoryThread.delete();
|
|
384
|
-
expect(result).toEqual(mockResponse);
|
|
385
|
-
expect(global.fetch).toHaveBeenCalledWith(
|
|
386
|
-
`${clientOptions.baseUrl}/api/memory/threads/test-thread?agentId=${agentId}`,
|
|
387
|
-
expect.objectContaining({
|
|
388
|
-
method: 'DELETE',
|
|
389
|
-
headers: expect.objectContaining(clientOptions.headers)
|
|
390
|
-
})
|
|
391
|
-
);
|
|
392
|
-
});
|
|
442
|
+
describe('Tool Resource', () => {
|
|
443
|
+
const toolId = 'test-tool';
|
|
444
|
+
let tool: ReturnType<typeof client.getTool>;
|
|
393
445
|
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
const result = await client.getMemoryStatus(agentId);
|
|
398
|
-
expect(result).toEqual(mockResponse);
|
|
399
|
-
expect(global.fetch).toHaveBeenCalledWith(
|
|
400
|
-
`${clientOptions.baseUrl}/api/memory/status?agentId=${agentId}`,
|
|
401
|
-
expect.objectContaining({
|
|
402
|
-
headers: expect.objectContaining(clientOptions.headers)
|
|
403
|
-
})
|
|
404
|
-
);
|
|
405
|
-
});
|
|
446
|
+
beforeEach(() => {
|
|
447
|
+
tool = client.getTool(toolId);
|
|
448
|
+
});
|
|
406
449
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
body: JSON.stringify({ messages })
|
|
425
|
-
})
|
|
426
|
-
);
|
|
427
|
-
});
|
|
450
|
+
it('should get tool details', async () => {
|
|
451
|
+
const mockResponse = {
|
|
452
|
+
id: toolId,
|
|
453
|
+
description: 'Test Tool',
|
|
454
|
+
inputSchema: '{}',
|
|
455
|
+
outputSchema: '{}',
|
|
456
|
+
};
|
|
457
|
+
mockFetchResponse(mockResponse);
|
|
458
|
+
|
|
459
|
+
const result = await tool.details();
|
|
460
|
+
expect(result).toEqual(mockResponse);
|
|
461
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
462
|
+
`${clientOptions.baseUrl}/api/tools/test-tool`,
|
|
463
|
+
expect.objectContaining({
|
|
464
|
+
headers: expect.objectContaining(clientOptions.headers),
|
|
465
|
+
}),
|
|
466
|
+
);
|
|
428
467
|
});
|
|
429
468
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
469
|
+
it('should execute tool', async () => {
|
|
470
|
+
const mockResponse = {
|
|
471
|
+
result: 'Tool execution result',
|
|
472
|
+
};
|
|
473
|
+
mockFetchResponse(mockResponse);
|
|
433
474
|
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
475
|
+
const result = await tool.execute({ data: '' });
|
|
476
|
+
expect(result).toEqual(mockResponse);
|
|
477
|
+
expect(global.fetch).toHaveBeenCalledWith(`${clientOptions.baseUrl}/api/tools/test-tool/execute`, {
|
|
478
|
+
method: 'POST',
|
|
479
|
+
headers: {
|
|
480
|
+
Authorization: 'Bearer test-key',
|
|
481
|
+
'Content-Type': 'application/json',
|
|
482
|
+
},
|
|
483
|
+
body: JSON.stringify({ data: '' }),
|
|
484
|
+
});
|
|
485
|
+
});
|
|
486
|
+
});
|
|
437
487
|
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
description: 'Test Tool',
|
|
442
|
-
inputSchema: '{}',
|
|
443
|
-
outputSchema: '{}'
|
|
444
|
-
};
|
|
445
|
-
mockFetchResponse(mockResponse);
|
|
446
|
-
|
|
447
|
-
const result = await tool.details();
|
|
448
|
-
expect(result).toEqual(mockResponse);
|
|
449
|
-
expect(global.fetch).toHaveBeenCalledWith(
|
|
450
|
-
`${clientOptions.baseUrl}/api/tools/test-tool`,
|
|
451
|
-
expect.objectContaining({
|
|
452
|
-
headers: expect.objectContaining(clientOptions.headers)
|
|
453
|
-
})
|
|
454
|
-
);
|
|
455
|
-
});
|
|
488
|
+
describe('Workflow Resource', () => {
|
|
489
|
+
const workflowId = 'test-workflow';
|
|
490
|
+
let workflow: ReturnType<typeof client.getWorkflow>;
|
|
456
491
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
result: 'Tool execution result'
|
|
460
|
-
};
|
|
461
|
-
mockFetchResponse(mockResponse);
|
|
462
|
-
|
|
463
|
-
const result = await tool.execute({ input: 'test' });
|
|
464
|
-
expect(result).toEqual(mockResponse);
|
|
465
|
-
expect(global.fetch).toHaveBeenCalledWith(
|
|
466
|
-
`${clientOptions.baseUrl}/api/tools/test-tool/execute`,
|
|
467
|
-
expect.objectContaining({
|
|
468
|
-
method: 'POST',
|
|
469
|
-
headers: expect.objectContaining(clientOptions.headers),
|
|
470
|
-
body: JSON.stringify({ input: 'test' })
|
|
471
|
-
})
|
|
472
|
-
);
|
|
473
|
-
});
|
|
492
|
+
beforeEach(() => {
|
|
493
|
+
workflow = client.getWorkflow(workflowId);
|
|
474
494
|
});
|
|
475
495
|
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
}
|
|
496
|
+
it('should get workflow details', async () => {
|
|
497
|
+
const mockResponse = {
|
|
498
|
+
name: 'Test Workflow',
|
|
499
|
+
triggerSchema: '{}',
|
|
500
|
+
steps: {},
|
|
501
|
+
stepGraph: {},
|
|
502
|
+
stepSubscriberGraph: {},
|
|
503
|
+
};
|
|
504
|
+
mockFetchResponse(mockResponse);
|
|
505
|
+
|
|
506
|
+
const result = await workflow.details();
|
|
507
|
+
expect(result).toEqual(mockResponse);
|
|
508
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
509
|
+
`${clientOptions.baseUrl}/api/workflows/test-workflow`,
|
|
510
|
+
expect.objectContaining({
|
|
511
|
+
headers: expect.objectContaining(clientOptions.headers),
|
|
512
|
+
}),
|
|
513
|
+
);
|
|
514
|
+
});
|
|
483
515
|
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
516
|
+
it('should execute workflow', async () => {
|
|
517
|
+
const mockResponse = {
|
|
518
|
+
result: 'Workflow execution result',
|
|
519
|
+
};
|
|
520
|
+
mockFetchResponse(mockResponse);
|
|
521
|
+
|
|
522
|
+
const result = await workflow.execute({ trigger: 'test' });
|
|
523
|
+
expect(result).toEqual(mockResponse);
|
|
524
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
525
|
+
`${clientOptions.baseUrl}/api/workflows/test-workflow/execute`,
|
|
526
|
+
expect.objectContaining({
|
|
527
|
+
method: 'POST',
|
|
528
|
+
headers: expect.objectContaining(clientOptions.headers),
|
|
529
|
+
body: JSON.stringify({ trigger: 'test' }),
|
|
530
|
+
}),
|
|
531
|
+
);
|
|
532
|
+
});
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
describe('Client Error Handling', () => {
|
|
536
|
+
it('should retry failed requests', async () => {
|
|
537
|
+
// Mock first two calls to fail, third to succeed
|
|
538
|
+
(global.fetch as any)
|
|
539
|
+
.mockRejectedValueOnce(new Error('Network error'))
|
|
540
|
+
.mockRejectedValueOnce(new Error('Network error'))
|
|
541
|
+
.mockResolvedValueOnce({
|
|
542
|
+
ok: true,
|
|
543
|
+
headers: {
|
|
544
|
+
get: () => 'application/json',
|
|
545
|
+
},
|
|
546
|
+
json: async () => ({ success: true }),
|
|
502
547
|
});
|
|
503
548
|
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
};
|
|
508
|
-
mockFetchResponse(mockResponse);
|
|
509
|
-
|
|
510
|
-
const result = await workflow.execute({ trigger: 'test' });
|
|
511
|
-
expect(result).toEqual(mockResponse);
|
|
512
|
-
expect(global.fetch).toHaveBeenCalledWith(
|
|
513
|
-
`${clientOptions.baseUrl}/api/workflows/test-workflow/execute`,
|
|
514
|
-
expect.objectContaining({
|
|
515
|
-
method: 'POST',
|
|
516
|
-
headers: expect.objectContaining(clientOptions.headers),
|
|
517
|
-
body: JSON.stringify({ trigger: 'test' })
|
|
518
|
-
})
|
|
519
|
-
);
|
|
520
|
-
});
|
|
549
|
+
const result = await client.request('/test-endpoint');
|
|
550
|
+
expect(result).toEqual({ success: true });
|
|
551
|
+
expect(global.fetch).toHaveBeenCalledTimes(3);
|
|
521
552
|
});
|
|
522
553
|
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
// Mock first two calls to fail, third to succeed
|
|
526
|
-
(global.fetch as any)
|
|
527
|
-
.mockRejectedValueOnce(new Error('Network error'))
|
|
528
|
-
.mockRejectedValueOnce(new Error('Network error'))
|
|
529
|
-
.mockResolvedValueOnce({
|
|
530
|
-
ok: true,
|
|
531
|
-
headers: {
|
|
532
|
-
get: () => 'application/json'
|
|
533
|
-
},
|
|
534
|
-
json: async () => ({ success: true })
|
|
535
|
-
});
|
|
536
|
-
|
|
537
|
-
const result = await client.request('/test-endpoint');
|
|
538
|
-
expect(result).toEqual({ success: true });
|
|
539
|
-
expect(global.fetch).toHaveBeenCalledTimes(3);
|
|
540
|
-
});
|
|
541
|
-
|
|
542
|
-
it('should throw error after max retries', async () => {
|
|
543
|
-
(global.fetch as any).mockRejectedValue(new Error('Network error'));
|
|
554
|
+
it('should throw error after max retries', async () => {
|
|
555
|
+
(global.fetch as any).mockRejectedValue(new Error('Network error'));
|
|
544
556
|
|
|
545
|
-
|
|
546
|
-
.rejects
|
|
547
|
-
.toThrow('Network error');
|
|
557
|
+
await expect(client.request('/test-endpoint')).rejects.toThrow('Network error');
|
|
548
558
|
|
|
549
|
-
|
|
550
|
-
});
|
|
559
|
+
expect(global.fetch).toHaveBeenCalledTimes(4);
|
|
551
560
|
});
|
|
561
|
+
});
|
|
552
562
|
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
});
|
|
573
|
-
|
|
574
|
-
const result = await customClient.request('/test');
|
|
575
|
-
expect(result).toEqual({ success: true });
|
|
576
|
-
expect(global.fetch).toHaveBeenCalledTimes(3);
|
|
577
|
-
expect(global.fetch).toHaveBeenCalledWith(
|
|
578
|
-
'http://localhost:4111/test',
|
|
579
|
-
expect.objectContaining({
|
|
580
|
-
headers: expect.objectContaining({
|
|
581
|
-
'Custom-Header': 'value'
|
|
582
|
-
})
|
|
583
|
-
})
|
|
584
|
-
);
|
|
563
|
+
describe('Client Configuration', () => {
|
|
564
|
+
it('should handle custom retry configuration', async () => {
|
|
565
|
+
const customClient = new MastraClient({
|
|
566
|
+
baseUrl: 'http://localhost:4111',
|
|
567
|
+
retries: 2,
|
|
568
|
+
backoffMs: 100,
|
|
569
|
+
maxBackoffMs: 1000,
|
|
570
|
+
headers: { 'Custom-Header': 'value' },
|
|
571
|
+
});
|
|
572
|
+
|
|
573
|
+
(global.fetch as any)
|
|
574
|
+
.mockRejectedValueOnce(new Error('Network error'))
|
|
575
|
+
.mockRejectedValueOnce(new Error('Network error'))
|
|
576
|
+
.mockResolvedValueOnce({
|
|
577
|
+
ok: true,
|
|
578
|
+
headers: {
|
|
579
|
+
get: () => 'application/json',
|
|
580
|
+
},
|
|
581
|
+
json: async () => ({ success: true }),
|
|
585
582
|
});
|
|
583
|
+
|
|
584
|
+
const result = await customClient.request('/test');
|
|
585
|
+
expect(result).toEqual({ success: true });
|
|
586
|
+
expect(global.fetch).toHaveBeenCalledTimes(3);
|
|
587
|
+
expect(global.fetch).toHaveBeenCalledWith(
|
|
588
|
+
'http://localhost:4111/test',
|
|
589
|
+
expect.objectContaining({
|
|
590
|
+
headers: expect.objectContaining({
|
|
591
|
+
'Custom-Header': 'value',
|
|
592
|
+
}),
|
|
593
|
+
}),
|
|
594
|
+
);
|
|
586
595
|
});
|
|
596
|
+
});
|
|
587
597
|
});
|