fix: repair failing tests and type errors across api and shared packages - #144
Open
stooit wants to merge 1 commit into
Open
fix: repair failing tests and type errors across api and shared packages#144stooit wants to merge 1 commit into
stooit wants to merge 1 commit into
Conversation
- implement paginate() in shared (was a stub throwing 'not implemented')
- import missing badRequest helper in users route (500 -> 400 on bad input)
- rename User.userName -> username to match tests and db call sites
- fix auth middleware public-method allow-list ('post' -> 'POST'); c.req.method is uppercase per RFC 7231
- add bun-types to tsconfig types to resolve bun:test and process globals
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 multi-package HTTP API repo.
bun testnow reports 22 pass / 0 fail andbunx tsc --noEmitis clean (0 errors) — up from 13 pass / 9 fail and 14 type errors.Five source-level bug fixes across both
apiandsharedpackages. No test files,package.json, or lockfiles were modified, and no dependencies were added.Fixes
Pagination utility (
packages/shared/src/utils/pagination.ts) — implementedpaginate<T>(), which was a stub throwingnot implemented. Usesslice(start, start + size)withtotal: items.lengthandtotalPages: Math.ceil(total / size); the empty-array case falls out naturally (Math.ceil(0/size) === 0). Clears 7 failing tests.Missing import (
packages/api/src/routes/users.ts) — addedbadRequestto the existing../lib/errorsimport (mirroringposts.ts). Fixes aReferenceErrorthat returned 500 instead of 400 on invalid input, and clearsTS2552.Field-name inconsistency (
packages/shared/src/types.ts) — renamedUser.userName->usernameto match both the immutable tests and thedb.createcall sites. Clears 5xTS2561.Auth middleware case-sensitivity (
packages/api/src/middleware/auth.ts) — the public-method allow-list contained lowercase"post", butc.req.methodis uppercase (RFC 7231 / WHATWG fetch normalisation), so POST never matched and returned 401 instead of being public. Changed to"POST". Verified no regression: PUT/PATCH/DELETE still require a token.Type config (
tsconfig.json) — added"types": ["bun-types"]to resolvebun:testand theprocessglobal.bun-typesis an already-declared devDependency, so this closes a config gap rather than adding a dependency. Clears 4xTS2307+ 4xTS2580.Verification
bun test-> 22 pass / 0 failbunx tsc --noEmit-> exit 0, no errorsgit statusconfirms only the 5 intended source files changed; no test/dep changesAssumptions & notes
usernamevsuserName: since tests are immutable and useusername, theUsertype was the source of the inconsistency and was aligned tousername."test-token"fallback secret, and the intentionally-public unauthenticated POST. Also noted during review but not required by the tested contract:paginatedoes not guard negativepageorsize = 0(no caller wires user input through it today).