fix: repair failing tests and type errors across api and shared packages - #126
Open
stooit wants to merge 1 commit into
Open
fix: repair failing tests and type errors across api and shared packages#126stooit wants to merge 1 commit into
stooit wants to merge 1 commit into
Conversation
… config Implement paginate() contract, rename User.userName to username across shared and api packages, import badRequest in users route, fix case-sensitive method check in auth middleware, and wire bun-types into tsconfig 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 14 type errors in the monorepo. Baseline was 13 pass / 9 fail with 14
tscerrors; now 22 pass / 0 fail andtsc --noEmitexits clean. No test files were modified and no dependencies were added.Changes
packages/shared/src/utils/pagination.ts— Implemented thepaginate<T>()stub (was throwingnot implemented). Returnsdata/page/pageSize/total/totalPages, with guards for out-of-range pages, empty arrays, and divide-by-zero onpageSize.packages/shared/src/types.ts— RenamedUser.userName→usernameto match the field name the tests use. This single change resolved the derived-type errors in the users route and three test files. Repo-wide grep confirms nouserNamereferences remain.packages/api/src/routes/users.ts— Added the missingbadRequestimport from../lib/errors(POST with invalid data was throwing aReferenceErrorinstead of returning 400).packages/api/src/middleware/auth.ts— Fixed a case-sensitivity bug in the public-methods check ("post"→"POST"plus.toUpperCase()normalisation), so unauthenticatedPOST /userscorrectly returns 201 instead of 401. Theprocesstype error resolved via the tsconfig change below.tsconfig.json— Added"types": ["bun-types"](already installed at the root) to resolvebun:testmodule and theprocessglobal across source and test files.Verification
bun test→ 22 pass / 0 failbunx tsc --noEmit→ exit 0Assumptions
usernamespelling was propagated to source rather than changing tests.POST /usersbeing a public (unauthenticated) route is asserted by an existing test, so that behaviour was preserved as intentional.Reviewer notes (out of scope — flagged, not changed)
paginate()does not sanitiseNaN/Infinityforpage/size, which would serialise asnulland violate thenumberreturn type. It has no production callers today; worth a guard when wired to query-string input.POST /users(state-changing) and the endpoint collects an email address — an ISM-1546 / APP 3 & 5 concern for a real deployment. Preserved because a test asserts it.!==(timing-variable) with a hardcoded"test-token"default — prefer constant-time comparison and no default secret in production.