fix: repair failing tests and type errors across api and shared packages - #138
Open
stooit wants to merge 1 commit into
Open
fix: repair failing tests and type errors across api and shared packages#138stooit wants to merge 1 commit into
stooit wants to merge 1 commit into
Conversation
- fix: import badRequest in users route (was ReferenceError -> 500 instead of 400) - fix: correct auth middleware public-method literal POST (case bug rejected public POST) - fix: rename shared User field userName -> username to match consumers and wire shape - feat: implement paginate utility (was an unimplemented throw stub) - fix: add bun-types to tsconfig types so bun:test and process resolve
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 all 14
tsc --noEmittype errors.bun test && tsc --noEmitnow passes cleanly (22/22 tests, 0 type errors).The failures spanned both the
apiandsharedpackages. Root causes and fixes:packages/api/src/routes/users.ts—badRequestwas used but never imported, so the missing-fields path threw aReferenceErrorand returned 500 instead of 400. Added it to the../lib/errorsimport.packages/api/src/middleware/auth.ts— the public-method allow-list contained the literal"post"(lowercase), butc.req.methodis always uppercase, so publicPOST /usersfell through to token validation and returned 401. Corrected to"POST".packages/shared/src/types.ts— theUsertype declareduserName, while every consumer (route, db, all test files) and the JSON wire shape useusername. Renamed the field tousername; tests are authoritative and could not be changed.packages/shared/src/utils/pagination.ts— thepaginateutility was an unimplementedthrowstub. Implemented per the test contract: 1-indexedpage,total = items.length,totalPages = Math.ceil(total / size)(empty array → 0 pages), slice(page-1)*size … page*size, returning allPaginatedResponsefields (sizeechoed aspageSize).tsconfig.json— added"types": ["bun-types"]sobun:testimports and theprocessglobal resolve.bun-types(and its transitive@types/node) were already installed; no new dependencies were added.Testing
bun test→ 22 pass, 0 failnpx tsc --noEmit→ exit 0, no errorsAssumptions & constraints honoured
typesentry uses the already-installedbun-types.Out-of-scope notes (not changed)
Flagged during implementation but intentionally left as-is because the tests assert the current behaviour:
auth.tstreatsPOST /usersas a public (unauthenticated) write path — matches the middleware docstring andauth.test.ts. If this middleware is destined for production, the public allow-list should be GET-only.auth.tsfalls back to a hardcoded"test-token"whenAPI_TOKENis unset. Convenient for the suite, but a real deploy should fail closed on a missing token.