fix: repair failing tests and type errors across api and shared packages - #128
Open
stooit wants to merge 1 commit into
Open
fix: repair failing tests and type errors across api and shared packages#128stooit wants to merge 1 commit into
stooit wants to merge 1 commit into
Conversation
- Implement stubbed paginate() utility (1-indexed, partial last page, out-of-range/invalid page or size -> empty data, empty input -> totalPages 0) - Fix auth middleware case-sensitivity bug: publicMethods 'post' -> 'POST' (POST /users is public again; DELETE/PUT/PATCH remain token-gated) - Rename shared User field userName -> username to match consumers and tests - Import badRequest from lib/errors in users route (mirrors posts route) - Add "types": ["bun-types"] to tsconfig so bun:test and process resolve No test files or dependencies changed. bun test: 22 pass / 0 fail; tsc 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
Repairs all 9 failing tests and all 14 TypeScript errors in the multi-package repo. Result:
bun test→ 22 pass / 0 fail,bunx tsc --noEmit→ clean (exit 0).No test files were modified and no dependencies were added — fixes are confined to source and tsconfig only.
Fixes (5 files)
packages/shared/src/utils/pagination.tspaginate<T>(). 1-indexed pages; partial last page returned as-is; out-of-range or invalidpage/size→ emptydata; empty input →totalPages: 0.packages/api/src/middleware/auth.tspublicMethodshad"post"—c.req.methodis uppercased, so POST was wrongly token-gated. Changed to"POST".packages/shared/src/types.tsUser.userName→usernameto match the API consumers and the (unmodifiable) tests, which assert the serialised field isusername.packages/api/src/routes/users.tsbadRequesthelper from../lib/errors(mirrorsroutes/posts.ts), fixing aReferenceErroron the missing-fields path.tsconfig.json"types": ["bun-types"]sobun:testandprocessresolve.bun-typeswas already a devDependency — no new dependency.Verification
Assumptions & notes
username. The test files (which the task forbids editing) assert onusernamein request/response bodies, so the shared type was conformed to the tests.GET+POSTare public;PUT/PATCH/DELETEremain token-gated (verified — DELETE without a token still returns 401).paginatehardening beyond the tests: the implementation guardspage < 1andsize < 1to return emptydata(consistent with the out-of-range contract), avoiding a trap for the first real caller. All existing tests pass unchanged.Out of scope (pre-existing, flagged by review — not addressed here)
auth.tsuses a hardcoded"test-token"fallback whenAPI_TOKENis unset, and a non-constant-time token comparison (CWE-798 / timing). Pre-existing; a "fix failing tests" task correctly leaves it untouched. Worth a follow-up before any real deployment.🤖 Generated with QuantCode Agent