Skip to content

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

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier2-2220-1787242331
Open

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

Conversation

@stooit

@stooit stooit commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all failing tests and type errors in the repository. Final state: 22/22 tests pass, tsc --noEmit clean (0 errors).

Bugs fixed

  • Auth middleware case-sensitivity (packages/api/src/middleware/auth.ts): the public-method allow-list used lowercase "post", so POST requests (always uppercase per RFC 7231) were never matched and incorrectly required a token. Changed to "POST" and added .toUpperCase() normalisation.
  • Missing import (packages/api/src/routes/users.ts): badRequest was called but never imported, throwing a ReferenceError and returning 500 instead of 400 on invalid input. Added it to the existing import from ../lib/errors.
  • Inconsistent shared type (packages/shared/src/types.ts): User.userName did not match the username field used by the route handlers and tests. Renamed the type field to username.
  • Unimplemented pagination utility (packages/shared/src/utils/pagination.ts): implemented paginate<T>() to satisfy the full test contract — correct page slice, second/partial pages, total/totalPages, page/pageSize, out-of-range returns empty data, and empty-array handling.
  • Ambient types (tsconfig.json): registered the already-installed bun-types so process and bun:test resolve under tsc.

Verification

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

Assumptions & notes

  • The username/userName mismatch was resolved by changing the shared type (not the tests), since tests and route code both use username and test files must not be modified.
  • No new dependencies were added; bun-types was already present in node_modules.
  • No test files were modified.
  • Changes are minimal and confined to the four flagged source files plus the tsconfig types entry.

- auth middleware: fix case-sensitivity bug (lowercase 'post' -> 'POST')
  so POST routes are correctly treated as public; normalise method case
- routes/users: add missing badRequest import (was throwing ReferenceError
  -> 500 instead of 400 on invalid input)
- shared types: rename User.userName -> username for consistency with
  route handlers and tests
- shared pagination: implement paginate() to satisfy the full test contract
- tsconfig: register already-installed bun-types for ambient process/bun:test

All 22 tests pass and tsc --noEmit is clean. No test files or dependencies changed.
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