Skip to content

Commit 10cbb40

Browse files
committed
log-client: fix tests
1 parent 29fedc0 commit 10cbb40

File tree

2 files changed

+13
-46
lines changed

2 files changed

+13
-46
lines changed

packages/log-client/__mocks__/handlers.ts

Lines changed: 12 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
import type {
2-
Error as ApiErrorResponse,
3-
Response as ApiOkResponse,
4-
Path,
5-
Body as ApiBody,
6-
Method,
7-
PathParams,
8-
} from '@lightmill/log-api';
91
import {
102
HttpHandler,
113
HttpResponse,
@@ -57,23 +49,23 @@ export function getServerHandlers({
5749
return [
5850
get('/sessions/current', () =>
5951
HttpResponse.json({
60-
status: 'ok',
6152
role: 'participant',
6253
runs: runs.map((run) => ({ runStatus: 'running' as const, ...run })),
6354
}),
6455
),
6556
put('/sessions/current', () =>
6657
HttpResponse.json({
67-
status: 'ok',
6858
role: 'participant',
6959
runs: runs.map((run) => ({ runStatus: 'running', ...run })),
7060
}),
7161
),
7262
del('/sessions/current', () => HttpResponse.json({ status: 'ok' })),
7363
post('/runs', async ({ request }) => {
7464
let body = await request.json();
65+
if (typeof body !== 'object') {
66+
throw new Error('Unexpected body type');
67+
}
7568
return HttpResponse.json({
76-
status: 'ok',
7769
runStatus: 'running',
7870
runName: body?.runName ?? 'default-run-id',
7971
experimentName: body?.experimentName ?? 'default-experiment-id',
@@ -82,35 +74,27 @@ export function getServerHandlers({
8274
get('/experiments/:experimentName/runs/:runName', ({ params }) => {
8375
const run = getRun(params);
8476
if (run == null) {
85-
return HttpResponse.json(
86-
{ status: 'error', message: 'Run not found' },
87-
{ status: 404 },
88-
);
77+
return HttpResponse.json({ message: 'Run not found' }, { status: 404 });
8978
}
9079
return HttpResponse.json({
91-
status: 'ok',
92-
run: { runStatus: 'running', logs: [], ...run },
80+
runStatus: 'running',
81+
logs: [],
82+
...run,
9383
});
9484
}),
9585
patch('/experiments/:experimentName/runs/:runName', ({ params }) => {
9686
const run = getRun(params);
9787
if (run == null) {
98-
return HttpResponse.json(
99-
{ status: 'error', message: 'Run not found' },
100-
{ status: 404 },
101-
);
88+
return HttpResponse.json({ message: 'Run not found' }, { status: 404 });
10289
}
103-
return HttpResponse.json({ status: 'ok' });
90+
return HttpResponse.json();
10491
}),
10592
post('/experiments/:experimentName/runs/:runName/logs', ({ params }) => {
10693
const run = getRun(params);
10794
if (run == null) {
108-
return HttpResponse.json(
109-
{ status: 'error', message: 'Run not found' },
110-
{ status: 404 },
111-
);
95+
return HttpResponse.json({ message: 'Run not found' }, { status: 404 });
11296
}
113-
return HttpResponse.json({ status: 'ok' });
97+
return HttpResponse.json();
11498
}),
11599
];
116100
}
@@ -125,22 +109,5 @@ function createMethods(baseUrl: string) {
125109
http[method](`${baseUrl}${path}`, handler);
126110
}
127111

128-
return result as {
129-
[K in Method]: <P extends Path<K>>(
130-
path: P,
131-
handler: HttpResponseResolver<
132-
// PathParams allow stuff like number or booleans, but msw does not.
133-
{
134-
[Key in keyof PathParams<K, P>]: PathParams<
135-
K,
136-
P
137-
>[Key] extends unknown[]
138-
? string[]
139-
: string;
140-
},
141-
ApiBody<K, P>,
142-
ApiOkResponse<K, P> | ApiErrorResponse<K, P>
143-
>,
144-
) => HttpHandler;
145-
};
112+
return result;
146113
}

packages/log-client/__tests__/main.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
33
import { afterAll, afterEach, beforeAll } from 'vitest';
44
import { setupServer } from 'msw/node';
55
import { getServerHandlers } from '../__mocks__/handlers.js';
6-
import { paths } from '../src/api.js';
6+
import { paths } from '../generated/api.js';
77

88
type Method = 'get' | 'post' | 'delete' | 'patch';
99

0 commit comments

Comments
 (0)