fix: repair failing tests and type errors across api and shared packages - #118
Open
stooit wants to merge 1 commit into
Open
fix: repair failing tests and type errors across api and shared packages#118stooit wants to merge 1 commit into
stooit wants to merge 1 commit into
Conversation
… names, repair imports and tsconfig
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 (was 9 fail / 13 pass) and type errors across the
apiandsharedpackages. Final state: 22 pass / 0 fail /tsc --noEmitexit 0. No test files were modified and no dependencies were added.Fixes
shared/src/utils/pagination.ts) — implemented thepaginatestub (was throwingnot implemented): page slicing,total/totalPages,page/pageSizeecho, out-of-range page → empty data, empty-array handling. Also guarded against non-finite/negativepage/sizeso the returnedpage: number/pageSize: numbercontract can't serialise tonull(page→min 1, size→min 0, floored to integers).api/src/middleware/auth.ts) — fixed a case-sensitivity bug in the public-methods allow-list (["GET", "post"]) that causedPOST /usersto return 401 instead of being treated as public. Now usesPUBLIC_METHODS = ["GET", "POST"]compared against a normalisedc.req.method.toUpperCase().shared/src/types.ts) — renamed the plantedUser.userNamefield tousernameto match API usage and the test contract (tests useusernamethroughout and are the immutable contract).api/src/routes/users.ts) — added the missingbadRequestimport from../lib/errors(was a runtimeReferenceErroron invalid POST bodies, failing the "returns 400 for missing fields" test).tsconfig.json— addedtypes: ["bun-types"]to resolvebun:testandprocessin test files and middleware. Keptlibat["ES2022"]only (verifiedDOMwas unnecessary and would let browser-only globals compile clean inside the Bun/Hono server package).Assumptions & decisions
users.tsuseuserName; that was inverted. The tests useusernameand cannot be modified, sotypes.ts(whose own comment flagged it as the bug) was the correct fix site. Changing the route instead would have introduced four new type errors at test call sites.POSTbeing public applies globally (all routes, not just/users), matching the documented middleware policy and an explicit test assertion ("POST is intentionally public"). Preserved as-is.Reviewer notes (non-blocking, out of scope — no test requires them)
POSTmeans unauthenticated writes are accepted on/poststoo; a per-route allow-list would be safer (ISM-1552) if that wasn't the intent.auth.tsuses!==(non-constant-time);crypto.timingSafeEqualwould be the ISM-aligned hardening.Verification
bun test && npx tsc --noEmit→ 22 pass, 0 fail, exit 0.