fix: repair failing tests and type errors across api and shared packages - #143
Open
stooit wants to merge 1 commit into
Open
fix: repair failing tests and type errors across api and shared packages#143stooit wants to merge 1 commit into
stooit wants to merge 1 commit into
Conversation
- auth middleware: normalise HTTP method casing so POST is correctly public - shared User type: rename userName -> username to match callers and tests - users route: import missing badRequest helper (was throwing ReferenceError) - shared pagination: implement paginate stub per test contract - tsconfig: add bun-types to types array to resolve ambient globals
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes all 9 failing tests and 14
tscerrors.bun test→ 22 pass / 0 fail;bunx tsc --noEmit→ exit 0. No test files modified, no dependencies added.Root causes & fixes
packages/api/src/middleware/auth.ts— Public-method allow-list held"post"(lowercase). Hono reportsc.req.methoduppercase, so POST fell through to the token check and returned 401. Fixed to"POST"and normalised the incoming method with.toUpperCase()to prevent casing regressions.packages/shared/src/types.ts— RenamedUser.userName→usernameto match the field the (unmodifiable) tests and route code use. Cleared the fourTS2561errors.packages/api/src/routes/users.ts— Added missingbadRequestimport from../lib/errors; it was referenced but never imported, throwingReferenceError(500 instead of the expected 400).packages/shared/src/utils/pagination.ts— Implemented thepaginatestub per the test contract: 1-indexed page, returns{ data, page, pageSize, total, totalPages }, empty/out-of-range inputs yield empty data withtotal/totalPagesof 0.tsconfig.json— Added"types": ["bun-types"](already an installed root devDependency) so TypeScript picks upbun:testandprocessambient globals. Resolves the 8 remainingtscerrors without adding dependencies.Assumptions
usernamefield name and the pagination return shape were derived from the assertions in the test files.auth.test.tsand was preserved.Notes (out of scope, flagged not changed)
POST /users/POST /postsaccept unauthenticated writes — pinned by the tests, but a real exposure if it reaches production."test-token"fallback and non-constant-time comparison (timing-attack exposure). Pre-existing; left unchanged.README.md"Known issues" section is now stale but left untouched (not part of pass criteria).