fix: repair failing tests and type errors across api and shared packages - #151
Open
stooit wants to merge 1 commit into
Open
fix: repair failing tests and type errors across api and shared packages#151stooit wants to merge 1 commit into
stooit wants to merge 1 commit into
Conversation
- auth middleware: uppercase POST in the public-method allow-list so unauthenticated writes match (c.req.method is uppercase per RFC 7231) - shared types: rename User.userName -> username to match the API and test contract; update the users route call site - users route: import the missing badRequest error helper - pagination: implement paginate() with clamped page/size bounds so out-of-range and non-finite inputs yield an empty window and always produce finite, JSON-serialisable page/total/totalPages fields - tsconfig: wire the already-installed bun-types into the types array to resolve bun:test and process type errors (no new dependency)
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
tsc --noEmiterrors across theapiandsharedpackages. Baseline was 13 pass / 9 fail with 14 type errors; now 22 pass / 0 fail andtsc --noEmitexits 0.Changes (5 files)
packages/api/src/middleware/auth.tsPOSTin the public-method allow-list.c.req.methodis uppercase per RFC 7231, so the lowercase"post"never matched — public writes were wrongly returning 401.packages/shared/src/types.tsUser.userName→usernameto match the API and test contract (field name was inconsistent between packages).packages/api/src/routes/users.tsbadRequesthelper from../lib/errors(was throwing a runtimeReferenceError→ 500 instead of 400).packages/shared/src/utils/pagination.tspaginate()stub, with clamped page/size bounds.tsconfig.json"types": ["bun-types"]sobun:testimports andprocessresolve.Verification
Notes & assumptions
bun-typeswas already an installed devDependency, just unreferenced by the compiler.paginate()hardening (beyond the passing tests): the tests only exercisepage: 99. I clamped the remaining edge cases so the exported public API can't lie about its contract: non-finite / sub-1 / negativepageyields an emptydatawindow;size <= 0/ NaN clamps to a floor of 1 sototalPagesstays a finite non-negative integer (unclamped it producedInfinity/NaNserialising to JSONnull, violatingPaginatedResponse.totalPages: number).POST /usersand/postsnow accept unauthenticated writes. This is the documented, test-mandated contract (auth.test.tsasserts 201 with no token) and correct for this in-memory test corpus. Flagging only so it isn't copied into a real service without revisiting the policy, since those payloads carryusername/email(personal information).paginatecurrently has no call sites in theapipackage, so the hardening changes cannot affect any live endpoint today.