Skip to content

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

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier2-2560-1788106607
Open

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

Conversation

@stooit

@stooit stooit commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all 9 failing tests and all 14 type errors in the repo. Both gates are now green: bun test22 pass / 0 fail, bunx tsc --noEmitexit 0.

Changes (5 files)

  • packages/shared/src/utils/pagination.ts — implemented the paginate() stub that previously threw "not implemented". Slices items by page/size, computes total/totalPages, and handles empty arrays and out-of-range pages per the test contract.
  • packages/api/src/routes/users.ts — added the missing badRequest import from ../lib/errors. The missing import caused a ReferenceError → HTTP 500 instead of the expected 400 on invalid input.
  • packages/api/src/middleware/auth.ts — fixed the case-sensitivity bug in the public-method allow-list ("post" never matched Hono's uppercase POST), so POST /users is now correctly public. Incoming method is normalised with .toUpperCase() before comparison.
  • packages/shared/src/types.ts — renamed User.userNameusername so the shared type matches its consumers (routes/users.ts, lib/db.ts) and the (unchangeable) tests. No remaining userName references in code.
  • tsconfig.json — added "types": ["bun-types"] to resolve bun:test and process. bun-types@1.4.0 was already a root devDependency; no new dependencies added.

Constraints honoured

  • No test files modified.
  • No dependencies added; no lockfile/package.json changes.
  • Only the code the tests required was changed.

Reviewer notes (non-blocking, out of scope for the failing tests)

A review pass flagged a few pre-existing / edge-case items that the tests do not require and were intentionally left as-is:

  • paginate() produces NaN fields for non-finite page/size input; harmless today (no callers) but worth sanitising on first real use.
  • auth.ts uses a non-constant-time token comparison with a hardcoded fallback secret (pre-existing).
  • POST endpoints being public means unauthenticated writes — this is deliberate and asserted by auth.test.ts ("POST /users is public").

🤖 Generated with autonomous agent

- implement paginate() stub in shared/utils (was throwing not-implemented)
- import missing badRequest helper in users route (was 500 instead of 400)
- fix case-sensitivity bug in auth middleware public-method allow-list
  (POST /users is now correctly public)
- rename shared User.userName -> username to match consumers and tests
- add bun-types to tsconfig so bun:test and process resolve

All tests pass (22/22) 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