fix: repair all failing tests and type errors across api and shared packages - #122
Open
stooit wants to merge 1 commit into
Open
fix: repair all failing tests and type errors across api and shared packages#122stooit wants to merge 1 commit into
stooit wants to merge 1 commit into
Conversation
- Implement paginate() in shared (was a throwing stub): correct 1-indexed page slicing, total/totalPages math, empty-array and out-of-range handling - Rename User.userName -> username in shared types for cross-package consistency - Import missing badRequest helper in users route (fixed runtime ReferenceError) - Fix auth middleware to treat POST /users as public and normalise HTTP method case; fail closed when API_TOKEN is unset instead of using a default token - Point tsconfig types at already-present bun-types to clear type errors No test files or dependencies were modified.
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
tsc --noEmittype errors across theapiandsharedpackages. Final state: 22/22 tests pass,bunx tsc --noEmitclean.Fixes
packages/shared/src/utils/pagination.ts) — implementedpaginate(), which was a throwing stub. Correct 1-indexed page slicing,total/totalPagesmath (Math.ceil), and edge cases (empty array → 0 pages, out-of-range page → empty data).packages/shared/src/types.ts) — renamedUser.userName→usernameso the type matches the route handler and the test contract across both packages.packages/api/src/routes/users.ts) — imported thebadRequesthelper from../lib/errors, fixing a runtimeReferenceErroronPOST /userswith missing fields.packages/api/src/middleware/auth.ts) — normalised HTTP method case soPOST /usersis correctly treated as a public route (no token required). Also hardened token handling to fail closed whenAPI_TOKENis unset rather than falling back to a hardcoded default (verified this cannot affect the public GET/POST paths, which short-circuit before the check).typesat the already-presentbun-typesdependency to clear theCannot find name 'process'/Cannot find module 'bun:test'errors. No new dependency added.Verification
bun test→ 22 pass / 0 failbunx tsc --noEmit→ clean (exit 0)Constraints honoured
package.jsonand lockfile untouched; tsconfig references an already-installed dep).Assumptions
username(rather than changing tests) to resolve the field mismatch.