Skip to content

fix: repair failing tests and type errors across api and shared packages - #126

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier2-2358-1786378976
Open

fix: repair failing tests and type errors across api and shared packages#126
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier2-2358-1786378976

Conversation

@stooit

@stooit stooit commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 9 failing tests and 14 type errors in the monorepo. Baseline was 13 pass / 9 fail with 14 tsc errors; now 22 pass / 0 fail and tsc --noEmit exits clean. No test files were modified and no dependencies were added.

Changes

  • packages/shared/src/utils/pagination.ts — Implemented the paginate<T>() stub (was throwing not implemented). Returns data/page/pageSize/total/totalPages, with guards for out-of-range pages, empty arrays, and divide-by-zero on pageSize.
  • packages/shared/src/types.ts — Renamed User.userNameusername to match the field name the tests use. This single change resolved the derived-type errors in the users route and three test files. Repo-wide grep confirms no userName references remain.
  • packages/api/src/routes/users.ts — Added the missing badRequest import from ../lib/errors (POST with invalid data was throwing a ReferenceError instead of returning 400).
  • packages/api/src/middleware/auth.ts — Fixed a case-sensitivity bug in the public-methods check ("post""POST" plus .toUpperCase() normalisation), so unauthenticated POST /users correctly returns 201 instead of 401. The process type error resolved via the tsconfig change below.
  • tsconfig.json — Added "types": ["bun-types"] (already installed at the root) to resolve bun:test module and the process global across source and test files.

Verification

  • bun test → 22 pass / 0 fail
  • bunx tsc --noEmit → exit 0

Assumptions

  • Tests are authoritative for field naming, so the username spelling was propagated to source rather than changing tests.
  • POST /users being a public (unauthenticated) route is asserted by an existing test, so that behaviour was preserved as intentional.

Reviewer notes (out of scope — flagged, not changed)

  • paginate() does not sanitise NaN/Infinity for page/size, which would serialise as null and violate the number return type. It has no production callers today; worth a guard when wired to query-string input.
  • Auth allows unauthenticated POST /users (state-changing) and the endpoint collects an email address — an ISM-1546 / APP 3 & 5 concern for a real deployment. Preserved because a test asserts it.
  • Token comparison uses !== (timing-variable) with a hardcoded "test-token" default — prefer constant-time comparison and no default secret in production.

… config

Implement paginate() contract, rename User.userName to username across
shared and api packages, import badRequest in users route, fix
case-sensitive method check in auth middleware, and wire bun-types into
tsconfig for bun:test and process globals.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant