Conversation
…check Implement paginate() against test contract; rename User.userName to username to match the API and test surface; import missing badRequest helper; fix case-sensitive HTTP method allow-list that forced tokens on POST. Wire existing bun-types into tsconfig to resolve process/bun:test type errors without new dependencies.
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 failing tests (22/22 now pass) and eliminates all
tsc --noEmittype errors across theapiandsharedpackages. No test files were modified and no dependencies were added.Root causes & fixes
packages/shared/src/utils/pagination.ts):paginate<T>()threw"not implemented". Implemented against the test contract — 1-indexed pages,slice((page-1)*size, ...),totalPages = ceil(total/size). Out-of-range page yields empty data; empty array yieldstotal: 0, totalPages: 0. Added defensive clamping onpage/size.packages/shared/src/types.ts):UserdeclareduserName, but the API route handlers and the (unmodifiable) tests useusername. Renamed the shared type field tousernameto match the contract.packages/api/src/routes/users.ts):badRequestwas called but never imported, causing a runtimeReferenceErroron the missing-fields path (crash instead of 400). Added it to the existing../lib/errorsimport.packages/api/src/middleware/auth.ts): the public-method allow-list contained lowercase"post", butc.req.methodis always uppercase, so POST fell through to token validation and returned 401 instead of being public. Replaced with a case-normalisedSetcomparison.tsconfig.json):processandbun:testfailed to resolve (TS2580/TS2307).bun-typeswas already a declared devDependency but never wired into the compiler — added"types": ["bun-types"]. No new dependency added.Verification
bun test→ 22 pass, 0 failbunx tsc --noEmit→ clean (exit 0)Assumptions
Security note (flagged for follow-up)
The tests mandate unauthenticated writes (POST is public) and rely on a static bearer token with a hardcoded
"test-token"fallback. Implemented faithfully to satisfy the tests, but this pattern conflicts with ISM-1536/ISM-0580 and should not reach a real service without an auth review.