mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-06 02:34:21 +00:00
refactor(server): plan 4 — U6 gate-level id parsing for todo item ids
Rule 21's carry from 3e Task 8's review: TodoController.update/.remove
passed the raw :id route string all the way to TodoItemsRepository,
relying on SQLite's column-affinity CAST to match it instead of a typed
filter. Parse :id ONCE at the controller (toRowId, matching Task 8a's
TripAccessGuard/removeMember shape), 404 on a non-canonical id, and thread
the number down through TodoService.updateItem/deleteItem into
TodoItemsRepository.findInTrip/existsInTrip/update/deleteById, all
narrowed from number | string to number. todo.rpc.ts's num()-derived
todoId no longer needs its String() wrapper. tripId stays string | number
— a separate, already-accepted carry (23c292f2f). Two new e2e tests pin
the non-numeric-id 404 at the gate.
This commit is contained in:
@@ -195,6 +195,23 @@ describe('To-do e2e (real auth guard + real SQL over temp SQLite)', () => {
|
||||
expect(res.body).toEqual({ error: 'Item not found' });
|
||||
});
|
||||
|
||||
// Plan 4 Task 8b (U6) — :id is now parsed ONCE at the controller gate
|
||||
// (toRowId), so a non-numeric id 404s cleanly through that guard instead
|
||||
// of falling through to the repository and depending on SQLite's
|
||||
// column-affinity CAST to simply not match (the legacy outcome was also a
|
||||
// 404, same status — this pins the gate itself, not just the status).
|
||||
it('404 (not 500) on update with a non-numeric :id', async () => {
|
||||
const res = await request(server).put(`/api/trips/${tripId}/todo/abc`).set('Cookie', sessionCookie(1)).send({ name: 'X' });
|
||||
expect(res.status).toBe(404);
|
||||
expect(res.body).toEqual({ error: 'Item not found' });
|
||||
});
|
||||
|
||||
it('404 (not 500) on delete with a non-numeric :id', async () => {
|
||||
const res = await request(server).delete(`/api/trips/${tripId}/todo/abc`).set('Cookie', sessionCookie(1));
|
||||
expect(res.status).toBe(404);
|
||||
expect(res.body).toEqual({ error: 'Item not found' });
|
||||
});
|
||||
|
||||
it('200 on reorder, persisting the new sort_order', async () => {
|
||||
const a = insertItem(tripId, 'A', { sort_order: 0 });
|
||||
const b = insertItem(tripId, 'B', { sort_order: 1 });
|
||||
|
||||
Reference in New Issue
Block a user