fix: repair failing tests across api and shared packages - #130
Open
stooit wants to merge 1 commit into
Open
Conversation
- implement paginate() stub in shared utils (data slice + total/totalPages)
- rename User.userName -> username to match api usage and tests
- import badRequest in users route (was ReferenceError -> 500 on validation)
- correct auth middleware public-method casing ("post" -> "POST")
- wire bun-types via tsconfig compilerOptions.types (bun:test, process)
No test files modified, no dependencies added. bun test: 22 pass / 0 fail; tsc --noEmit clean.
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 and type errors in the Bun + Hono TypeScript API. The suite now passes 22/22 with 0
tsc --noEmiterrors (baseline: 13 pass / 9 fail, 14 type errors).Bugs spanned both the
apiandsharedpackages:packages/shared/src/utils/pagination.ts) — implemented thepaginate()stub that previously threwnot implemented. Returns the correctdataslice pluspage,pageSize,total, andtotalPages(Math.ceil, so an empty array yieldstotalPages: 0).packages/shared/src/types.ts) — renamedUser.userName→usernameto match the API route handlers and the (immutable) tests.db.tsinherits the change via itsOmit<User, ...>spread.packages/api/src/routes/users.ts) —badRequestwas used but not imported, causing aReferenceErrorthat surfaced as a 500 on validation instead of the expected 400. Added it to the existing../lib/errorsimport.packages/api/src/middleware/auth.ts) — the public-methods allow-list had"post"(lowercase); Hono surfaces HTTP methods uppercase per RFC 9110, soPOST /userswas incorrectly requiring a token. Changed to"POST".tsconfig.json) — addedcompilerOptions.types: ["bun-types"]to resolvebun:testandprocesstype errors.bun-typeswas already a devDependency, so no new dependency was added.Testing
bun test→ 22 pass / 0 failbunx tsc --noEmit→ clean (exit 0), verified the checker is still engaged (a deliberate temporary type error was correctly flagged, then reverted)Constraints honoured
Assumptions & out-of-scope notes
paginate()was implemented with no clamping ofpage/size, matching the contract exercised by the tests. It has no production caller today (only re-exported + tested). A latent edge case exists if it is ever wired directly to unvalidated?page=/?size=query params (e.g.size: 0→totalPages: Infinity); recommend a route-boundary clamp when that happens. Left unchanged to keep this fix minimal.POSTis the explicitly intended policy perauth.tscomments andauth.test.ts("POST is intentionally public"). The pre-existing hardcoded"test-token"fallback in the auth middleware was not introduced here and is out of scope; worth hardening before any real deployment.README.mdstill describes the four seeded bugs under "Known issues" — left as-is since it appears to be intentional test-harness scaffolding.🤖 Generated with QuantCode Agent