Files
TREK/client/tests/helpers/msw/handlers/todo.ts
T
Maurice 83d807781e ci(client): hold strict null check errors per file to a baseline that only shrinks
The client compiles with strict: false, so nullable contract fields arrive as
if always present and implicit anys stay invisible. tsconfig.strict.json is the
same program with strictNullChecks and noImplicitAny, and lint:strict
(scripts/strict-lint.mjs) counts its errors per file against
scripts/strict-baseline.json: a file may not gain one, a new file has to be
clean, and an entry above its count fails until --update lowers it. Nothing is
converted here; today's 534 errors in 165 files are frozen. allowJs stays: the
tests import the .mjs scripts and read their JSDoc types through it.
The todo MSW handler maps a cleared priority to its default so the test
helper written in this branch starts at zero. The check runs after the
typecheck in client-quality.
2026-10-10 21:32:59 +02:00

43 lines
1.4 KiB
TypeScript

import { todoCreateItemRequestSchema, todoUpdateItemRequestSchema } from '@trek/shared';
import { HttpResponse } from 'msw';
import { buildTodoItem } from '../../factories';
import { contractHandler } from '../contract';
// @trek/shared holds the todo requests but no todo item schema yet, so only
// the request side is checked here.
/**
* The row as the server stores it: checked as 0/1 whichever form the request
* used, and a cleared priority as its default, 0.
*/
const asStored = <T extends { checked?: boolean | number; priority?: number | null }>({
checked,
priority,
...rest
}: T) => ({
...rest,
...(checked === undefined ? {} : { checked: Number(checked) }),
...(priority === undefined ? {} : { priority: priority ?? 0 }),
});
export const todoHandlers = [
contractHandler('get', '/api/trips/:id/todo', {}, ({ params }) => ({
items: [buildTodoItem({ trip_id: Number(params.id) })],
})),
contractHandler('post', '/api/trips/:id/todo', { request: todoCreateItemRequestSchema }, ({ params, body }) => ({
item: buildTodoItem({ trip_id: Number(params.id), ...body }),
})),
contractHandler(
'put',
'/api/trips/:id/todo/:itemId',
{ request: todoUpdateItemRequestSchema },
({ params, body }) => ({
item: buildTodoItem({ id: Number(params.itemId), trip_id: Number(params.id), ...asStored(body) }),
})
),
contractHandler('delete', '/api/trips/:id/todo/:itemId', {}, () => HttpResponse.json({ success: true })),
];