Skip to content

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

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier2-2216-1787761935
Open

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

Conversation

@stooit

@stooit stooit commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 9 failing tests (now 22/22 passing) and clears all tsc --noEmit type errors. Bugs spanned both the api and shared packages.

Changes

  • Auth middleware (packages/api/src/middleware/auth.ts) — Case-sensitivity bug: the public-methods allow-list contained "post" (lowercase), but Hono reports c.req.method in uppercase per RFC 7231, so POST /users never matched and fell through to the token check (401 instead of 201). Fixed to "POST", hoisted the list to a module-level const, and normalised the comparison with .toUpperCase().
  • Shared types (packages/shared/src/types.ts) — Field-name inconsistency: User.userName renamed to username to match the route handlers and tests.
  • Users route (packages/api/src/routes/users.ts) — Missing import: badRequest was used but not imported from ../lib/errors, causing a ReferenceError that surfaced as a 500 instead of the expected 400. Added to the existing import.
  • Pagination utility (packages/shared/src/utils/pagination.ts) — Implemented the stub: correct slice via (page - 1) * size, totalPages = ceil(total / pageSize), with guards for empty arrays and non-positive/non-finite page sizes.
  • tsconfig (tsconfig.json) — Added "types": ["bun-types"] so TypeScript resolves bun:test and process. bun-types is already a root devDependency; no new dependency was added.

Verification

  • bun test -> 22 pass / 0 fail
  • bunx tsc --noEmit -> exit 0, no errors

Constraints honoured

  • No test files modified.
  • No new dependencies added.
  • Only changed what the tests required.

Assumptions / notes for reviewers

  • process.env.API_TOKEN in the auth middleware uses a ?? "test-token" fallback. The tests set this env var, so it's exercised as intended — but the fallback default means an unset API_TOKEN would silently accept test-token in production. Failing closed there would be safer; left as-is since it's outside what the tests specify. The token comparison also uses !== rather than a constant-time compare. Worth a follow-up security review.

…pagination

- auth middleware: fix case-sensitivity in public-methods allow-list so
  POST is correctly treated as public (was "post", never matched "POST")
- shared types: rename User.userName -> username to match handlers and tests
- users route: import badRequest (missing import caused 500 instead of 400)
- shared pagination: implement the utility stub with bounds/empty guards
- tsconfig: declare bun-types so tsc resolves bun:test and process (existing devDep)
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