Commit Graph

6 Commits

Author SHA1 Message Date
Bas van Rossem
9c99d56f99 test(api): Admin users — fill gaps + lifecycle test
Fill the remaining coverage gaps in src/routes/admin-users.ts and add the
domain lifecycle test, bringing the file to 100% stmts/branch/funcs/lines.

New tests (apps/api/test/admin-users.test.ts):
- password route: 404 unknown id; 400 when better-auth setUserPassword throws
  (driven via a spy so the catch path is deterministic).
- toListItem: a null DB role lists as 'worker' (nullish-coalescing fallback).
- role route: 400 on an invalid role body; 404 on an unknown id.
- reactivate route: 404 on an unknown id.

Lifecycle (apps/api/test/integration/user-lifecycle.test.ts): admin creates a
worker -> worker signs in and the bearer authorizes /api/me -> admin deactivates
(session rows deleted, so the pre-issued token 401s and fresh sign-in is blocked)
-> admin reactivates -> sign-in works again.

The two last-admin guards (role + deactivate routes) are unreachable over HTTP
(the self-demote / self-deactivate guards above already handle caller===target,
so any caller reaching them is a distinct active admin and
activeAdminsExcluding(target) >= 1). Annotated with /* c8 ignore */ + reasons
rather than left as silent gaps; the guard logic is unit-tested via
activeAdminsExcluding.

No production behavior changed; no bugs found.
2026-07-23 13:43:59 +02:00
Bas van Rossem
b9aa24c5ae harden(api): adminGuard rejects banned admins; fix mixed-case create + real last-admin guard coverage 2026-06-24 23:12:40 +02:00
Bas van Rossem
4b80898b0e feat(api): admin reset-password endpoint 2026-06-24 22:57:35 +02:00
Bas van Rossem
40977f8abd feat(api): deactivate/reactivate users (ban + revoke sessions) with guards 2026-06-24 22:54:02 +02:00
Bas van Rossem
88b7773317 feat(api): set user role with self-demote + last-admin guards 2026-06-24 22:50:52 +02:00
Bas van Rossem
2b4b633961 feat(api): admin-users router with enriched roster + user creation 2026-06-24 22:46:59 +02:00