@testerpaykit/api-client 1.6.0 → 2.0.0
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/CHANGELOG.md +41 -0
- package/dist/index.d.mts +218 -13
- package/dist/index.d.ts +218 -13
- package/dist/index.js +95 -13
- package/dist/index.mjs +95 -13
- package/package.json +1 -1
- package/src/TesterPayKitApiClient.ts +175 -23
- package/src/compensation.ts +59 -0
- package/src/index.ts +1 -0
- package/tests/TesterPayKitApiClient.test.ts +83 -0
|
@@ -72,6 +72,29 @@ describe('TesterPayKitApiClient', () => {
|
|
|
72
72
|
});
|
|
73
73
|
});
|
|
74
74
|
|
|
75
|
+
describe('onTesterGate', () => {
|
|
76
|
+
function rejectWith(status: number, error?: string) {
|
|
77
|
+
const onError = mockAxiosInstance.interceptors.response.use.mock.calls[0][1];
|
|
78
|
+
return onError({ response: { status, data: error ? { error } : {} } });
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
it('reports a 403 phone_required / approval_required and still rejects', async () => {
|
|
82
|
+
const seen: string[] = [];
|
|
83
|
+
client.onTesterGate = (reason) => seen.push(reason);
|
|
84
|
+
await expect(rejectWith(403, 'phone_required')).rejects.toBeTruthy();
|
|
85
|
+
await expect(rejectWith(403, 'approval_required')).rejects.toBeTruthy();
|
|
86
|
+
expect(seen).toEqual(['phone_required', 'approval_required']);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it('ignores other errors', async () => {
|
|
90
|
+
const seen: string[] = [];
|
|
91
|
+
client.onTesterGate = (reason) => seen.push(reason);
|
|
92
|
+
await expect(rejectWith(403, 'forbidden')).rejects.toBeTruthy();
|
|
93
|
+
await expect(rejectWith(500)).rejects.toBeTruthy();
|
|
94
|
+
expect(seen).toEqual([]);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
|
|
75
98
|
describe('login', () => {
|
|
76
99
|
it('should successfully login and store tokens', async () => {
|
|
77
100
|
const loginRequest = {
|
|
@@ -189,6 +212,19 @@ describe('TesterPayKitApiClient', () => {
|
|
|
189
212
|
expect(mockAxiosInstance.post).toHaveBeenCalledWith('/v1/testers/me/live', { project_id: 'p-1' });
|
|
190
213
|
});
|
|
191
214
|
|
|
215
|
+
it('claims a remote AI run with the app version, 204 means none', async () => {
|
|
216
|
+
mockAxiosInstance.post.mockResolvedValue({ status: 200, data: { sessionId: 's-1', wsUrl: 'ws://x' } });
|
|
217
|
+
await expect(client.claimRemoteAiSession('p-1', '1.4.0')).resolves.toMatchObject({ sessionId: 's-1' });
|
|
218
|
+
expect(mockAxiosInstance.post).toHaveBeenCalledWith('/v1/testers/me/ai-sessions/claim', {
|
|
219
|
+
project_id: 'p-1', app_version: '1.4.0',
|
|
220
|
+
});
|
|
221
|
+
mockAxiosInstance.post.mockResolvedValue({ status: 204, data: '' });
|
|
222
|
+
await expect(client.claimRemoteAiSession('p-1')).resolves.toBeNull();
|
|
223
|
+
expect(mockAxiosInstance.post).toHaveBeenLastCalledWith('/v1/testers/me/ai-sessions/claim', {
|
|
224
|
+
project_id: 'p-1',
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
192
228
|
it('rejects when the server sends no wsUrl', async () => {
|
|
193
229
|
mockAxiosInstance.post.mockResolvedValue({ data: {} });
|
|
194
230
|
await expect(client.openLiveLink('p-1')).rejects.toThrow(/wsUrl/);
|
|
@@ -209,6 +245,53 @@ describe('TesterPayKitApiClient', () => {
|
|
|
209
245
|
});
|
|
210
246
|
});
|
|
211
247
|
|
|
248
|
+
describe('checklist', () => {
|
|
249
|
+
it('reads the checklist of a project', async () => {
|
|
250
|
+
const tasks = [{ id: 't1', title: 'Login', steps: ['Open', 'Sign in'], mine: { status: 'passed', steps: [], at: 'x' } }];
|
|
251
|
+
mockAxiosInstance.get.mockResolvedValue({ data: { tasks } });
|
|
252
|
+
await expect(client.getChecklist('p-1')).resolves.toEqual(tasks);
|
|
253
|
+
expect(mockAxiosInstance.get).toHaveBeenCalledWith('/v1/testers/me/checklist', { params: { project_id: 'p-1' } });
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it('treats 404 (not in the project yet) as an empty checklist', async () => {
|
|
257
|
+
mockAxiosInstance.get.mockRejectedValue({ response: { status: 404 } });
|
|
258
|
+
await expect(client.getChecklist('p-1')).resolves.toEqual([]);
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it('rethrows other errors', async () => {
|
|
262
|
+
mockAxiosInstance.get.mockRejectedValue({ response: { status: 500 } });
|
|
263
|
+
await expect(client.getChecklist('p-1')).rejects.toEqual({ response: { status: 500 } });
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it('returns an empty list when the body carries no tasks', async () => {
|
|
267
|
+
mockAxiosInstance.get.mockResolvedValue({ data: {} });
|
|
268
|
+
await expect(client.getChecklist('p-1')).resolves.toEqual([]);
|
|
269
|
+
});
|
|
270
|
+
|
|
271
|
+
it('submits a run with step verdicts, trimmed notes and summary', async () => {
|
|
272
|
+
mockAxiosInstance.post.mockResolvedValue({ data: { status: 'failed' } });
|
|
273
|
+
await expect(
|
|
274
|
+
client.submitChecklistRun({
|
|
275
|
+
projectId: 'p-1',
|
|
276
|
+
taskId: 't1',
|
|
277
|
+
stepResults: [
|
|
278
|
+
{ step: 1, passed: true, note: ' ' },
|
|
279
|
+
{ step: 2, passed: false, note: ' button dead ' },
|
|
280
|
+
],
|
|
281
|
+
summary: ' meh ',
|
|
282
|
+
}),
|
|
283
|
+
).resolves.toBe('failed');
|
|
284
|
+
expect(mockAxiosInstance.post).toHaveBeenCalledWith('/v1/testers/me/checklist/t1/runs', {
|
|
285
|
+
project_id: 'p-1',
|
|
286
|
+
step_results: [
|
|
287
|
+
{ step: 1, passed: true },
|
|
288
|
+
{ step: 2, passed: false, note: 'button dead' },
|
|
289
|
+
],
|
|
290
|
+
summary: 'meh',
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
|
|
212
295
|
describe('tester sessions', () => {
|
|
213
296
|
it('should start a tester session with server contract field names', async () => {
|
|
214
297
|
const response = {
|