fix: resolve all failing tests and type errors - #150
Open
stooit wants to merge 1 commit into
Open
Conversation
…ages - Import missing badRequest helper in users route (was throwing ReferenceError → 500 instead of 400) - Rename User.userName → username in shared types to match test contract and route handlers - Fix auth middleware public-method check to use uppercase HTTP method names (POST /users is public) - Implement paginate utility in shared package (was an unimplemented stub) - Add bun-types to tsconfig types so bun:test and process resolve (already a devDependency)
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 TypeScript errors across the
apiandsharedpackages. After the change: 22/22 tests pass andtsc --noEmitexits 0.Root causes & fixes
packages/api/src/routes/users.ts) —badRequestwas called but never imported, throwing aReferenceErrorand returning 500 instead of 400 for invalid bodies. Added the import (matching the existing pattern inposts.ts).packages/shared/src/types.ts) — the sharedUsertype declareduserName, but tests and route handlers useusername. Tests are the contract (and were not modified), so the shared type was renamed tousername.db.tsconsumes the type structurally viaOmit<User, ...>, so no other changes were needed.packages/api/src/middleware/auth.ts) — the public-method allowlist compared against a lowercase"post", but Hono reports HTTP methods uppercase, soPOST /usersincorrectly required a token (401). Fixed to uppercasePOST.DELETEetc. remain protected.packages/shared/src/utils/pagination.ts) — implementedpaginateto satisfy all 7 test assertions, including edge cases (out-of-range page → empty slice, empty array →totalPages0).tsconfig.json) — addedbun-typestocompilerOptions.typessobun:testandprocessresolve.bun-typeswas already a declared devDependency and present innode_modules— no new dependency was added.Constraints respected
package.json/ lockfile untouched).BUG:/TODO:comments made obsolete by the fixes).Verification
bun test→ 22 pass / 0 failbunx tsc --noEmit→ exit 0Assumptions / notes (out of scope, latent, pre-existing)
POST /usersandPOST /postsnow succeed — this is the documented policy (auth.ts) and explicitly test-mandated. If the API later handles non-public data, unauthenticated writes should be revisited.paginatedoes not clamp negative/zeropage/size(would yieldInfinity/negative slices), but it has no production callers and no test exercises it — left out per "fix only what the tests require"."test-token"fallback secret and a non-constant-time comparison — pre-existing, left untouched.