Skip to content

fix: resolve failing tests and type errors across api and shared packages - #127

Open
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier2-2337-1786465362
Open

fix: resolve failing tests and type errors across api and shared packages#127
stooit wants to merge 1 commit into
mainfrom
quantcode/e2e-tier2-2337-1786465362

Conversation

@stooit

@stooit stooit commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes all failing tests (was 13 pass / 9 fail → now 22 pass / 0 fail) and all type errors (was 14 → now tsc --noEmit clean) across the api and shared packages.

Changes

  • packages/api/src/middleware/auth.ts — Auth middleware treated the public-method list as ["GET", "post"]; the lowercase "post" never matched the request's POST, so public POST /users returned 401. Fixed to ["GET", "POST"] and normalise the incoming method with .toUpperCase() to prevent case regressions.
  • packages/api/src/routes/users.tsbadRequest was used but not imported, throwing ReferenceError and turning 400 responses into 500. Added it to the existing ../lib/errors import (matching posts.ts).
  • packages/shared/src/types.ts — Renamed User.userNameusername for cross-package consistency and to match the tests (source of truth). Verified zero userName references remain.
  • packages/shared/src/utils/pagination.ts — Implemented the paginate() stub to the test contract: 1-based paging, page/pageSize echoed, Math.ceil for totalPages, partial last page and empty-array handled. Clamped slice start with Math.max(0, ...) so negative/out-of-range pages yield an empty page.
  • tsconfig.json — Added "types": ["bun-types"] so bun:test and process resolve under tsc. bun-types was already a devDependency — no new dependencies added.

Verification

  • bun test → 22 pass / 0 fail (37 assertions, 4 files)
  • bunx tsc --noEmit → exit 0, no errors
  • Only 5 source files changed — no test files, no package.json, no lockfile.

Assumptions

  • Tests are the source of truth for field names, so the shared User type was renamed to username (rather than editing tests).
  • process.env.API_TOKEN left as the token mechanism (tests' beforeEach sets it); resolved typecheck via bun-types, not by switching to Bun.env.

Notes / follow-ups (out of scope, not changed)

  • Auth middleware allows unauthenticated POST writes and uses a non-timing-safe !== against a hardcoded fallback token — current tests mandate this, but it needs revisiting for production (ISM-1546).
  • paginate non-positive size still yields NaN/Infinity totalPages; HEAD/OPTIONS require a token. Both pre-existing and not required by tests.

🤖 Generated with QuantCode Agent

…ages

- auth middleware: correct HTTP method matching (case-sensitive POST bug),
  uppercase incoming method to prevent regression
- users route: add missing badRequest import from ../lib/errors
- shared types: rename User.userName -> username for cross-package consistency
- pagination: implement paginate() to test contract, clamp slice start at 0
  so negative/out-of-range pages yield an empty page
- tsconfig: add bun-types to types so bun:test and process resolve
  (no new dependencies; bun-types already a devDependency)

Fixes 9 failing tests and 14 type errors. bun test: 22/0, tsc --noEmit: clean.
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