fix: repair failing tests and type errors across api and shared packages - #147
Open
stooit wants to merge 1 commit into
Open
fix: repair failing tests and type errors across api and shared packages#147stooit wants to merge 1 commit into
stooit wants to merge 1 commit into
Conversation
…pagination - auth middleware: fix case-sensitivity in public-methods allow-list so POST is correctly treated as public (was "post", never matched "POST") - shared types: rename User.userName -> username to match handlers and tests - users route: import badRequest (missing import caused 500 instead of 400) - shared pagination: implement the utility stub with bounds/empty guards - tsconfig: declare bun-types so tsc resolves bun:test and process (existing devDep)
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 (now 22/22 passing) and clears all
tsc --noEmittype errors. Bugs spanned both theapiandsharedpackages.Changes
packages/api/src/middleware/auth.ts) — Case-sensitivity bug: the public-methods allow-list contained"post"(lowercase), but Hono reportsc.req.methodin uppercase per RFC 7231, soPOST /usersnever matched and fell through to the token check (401 instead of 201). Fixed to"POST", hoisted the list to a module-level const, and normalised the comparison with.toUpperCase().packages/shared/src/types.ts) — Field-name inconsistency:User.userNamerenamed tousernameto match the route handlers and tests.packages/api/src/routes/users.ts) — Missing import:badRequestwas used but not imported from../lib/errors, causing aReferenceErrorthat surfaced as a 500 instead of the expected 400. Added to the existing import.packages/shared/src/utils/pagination.ts) — Implemented the stub: correct slice via(page - 1) * size,totalPages = ceil(total / pageSize), with guards for empty arrays and non-positive/non-finite page sizes.tsconfig.json) — Added"types": ["bun-types"]so TypeScript resolvesbun:testandprocess.bun-typesis already a root devDependency; no new dependency was added.Verification
bun test-> 22 pass / 0 failbunx tsc --noEmit-> exit 0, no errorsConstraints honoured
Assumptions / notes for reviewers
process.env.API_TOKENin the auth middleware uses a?? "test-token"fallback. The tests set this env var, so it's exercised as intended — but the fallback default means an unsetAPI_TOKENwould silently accepttest-tokenin production. Failing closed there would be safer; left as-is since it's outside what the tests specify. The token comparison also uses!==rather than a constant-time compare. Worth a follow-up security review.