Skip to content

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

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier2-2252-1787501282
Open

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

Conversation

@stooit

@stooit stooit commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 9 failing tests and all 14 tsc --noEmit type errors in the repository. Final state: 22 tests pass, 0 fail; tsc --noEmit exits clean.

The bugs spanned both the api (Hono HTTP server) and shared (types/utilities) packages.

Changes

  • Auth middleware (packages/api/src/middleware/auth.ts) — fixed a case-sensitivity bug: the public-methods list contained "post" (lowercase). c.req.method is always uppercase per RFC 7231, so POST /users was incorrectly requiring a token (401). Corrected to ["GET", "POST"].
  • Shared types (packages/shared/src/types.ts) — renamed User.userNameusername to match what the tests and route handlers use. This was the single source of 5 cross-package type errors; the tests (which must not change) reference username in 9 places.
  • Pagination utility (packages/shared/src/utils/pagination.ts) — implemented the previously-stubbed paginate() per the test contract: page is 1-indexed and echoed back unclamped (out-of-range page yields empty data), totalPages is 0 for an empty array.
  • Users route (packages/api/src/routes/users.ts) — imported the missing badRequest helper from ../lib/errors (it was called but never imported, causing a ReferenceError / 500 instead of 400 on invalid POST bodies).
  • tsconfig.json — added "types": ["bun-types"] so bun:test and the process global resolve. bun-types was already a devDependency; no new dependencies added.

Verification

  • bun test → 22 pass / 0 fail
  • npx tsc --noEmit → exit 0, zero errors

Constraints honoured

  • No test files modified
  • No new dependencies added; no package.json changes
  • Only source/config fixes required by the tests

Notes / observations (out of scope, not changed)

The auth policy makes POST /users public and compares the bearer token with a hardcoded "test-token" fallback when API_TOKEN is unset. The tests encode this behaviour, so it was left as-is — but for a production deployment, consider failing closed when API_TOKEN is unset and using a constant-time comparison for the token.

- auth middleware: fix case-sensitivity bug so POST is treated as a public method
- shared types: rename User.userName to username for cross-package consistency
- pagination: implement paginate() per test contract (1-indexed, unclamped page)
- users route: import missing badRequest error helper
- tsconfig: add bun-types to compilerOptions.types 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