fix: repair failing tests and type errors across api and shared packages - #145
Open
stooit wants to merge 1 commit into
Open
fix: repair failing tests and type errors across api and shared packages#145stooit wants to merge 1 commit into
stooit wants to merge 1 commit into
Conversation
- auth middleware: fix case-sensitivity bug so POST is treated as a public method - shared types: rename User.userName to username for cross-package consistency - pagination: implement paginate() per test contract (1-indexed, unclamped page) - users route: import missing badRequest error helper - tsconfig: add bun-types to compilerOptions.types for 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 9 failing tests and all 14
tsc --noEmittype errors in the repository. Final state: 22 tests pass, 0 fail;tsc --noEmitexits clean.The bugs spanned both the
api(Hono HTTP server) andshared(types/utilities) packages.Changes
packages/api/src/middleware/auth.ts) — fixed a case-sensitivity bug: the public-methods list contained"post"(lowercase).c.req.methodis always uppercase per RFC 7231, soPOST /userswas incorrectly requiring a token (401). Corrected to["GET", "POST"].packages/shared/src/types.ts) — renamedUser.userName→usernameto match what the tests and route handlers use. This was the single source of 5 cross-package type errors; the tests (which must not change) referenceusernamein 9 places.packages/shared/src/utils/pagination.ts) — implemented the previously-stubbedpaginate()per the test contract:pageis 1-indexed and echoed back unclamped (out-of-range page yields emptydata),totalPagesis0for an empty array.packages/api/src/routes/users.ts) — imported the missingbadRequesthelper from../lib/errors(it was called but never imported, causing aReferenceError/ 500 instead of 400 on invalid POST bodies)."types": ["bun-types"]sobun:testand theprocessglobal resolve.bun-typeswas already a devDependency; no new dependencies added.Verification
bun test→ 22 pass / 0 failnpx tsc --noEmit→ exit 0, zero errorsConstraints honoured
package.jsonchangesNotes / observations (out of scope, not changed)
The auth policy makes
POST /userspublic and compares the bearer token with a hardcoded"test-token"fallback whenAPI_TOKENis unset. The tests encode this behaviour, so it was left as-is — but for a production deployment, consider failing closed whenAPI_TOKENis unset and using a constant-time comparison for the token.