fix: repair failing tests and type errors across api and shared packages - #154
Open
stooit wants to merge 1 commit into
Open
fix: repair failing tests and type errors across api and shared packages#154stooit wants to merge 1 commit into
stooit wants to merge 1 commit into
Conversation
- Implement paginate<T> in shared (was a throwing stub) with input normalisation - Import badRequest in users route (ReferenceError caused 500 instead of 400) - Rename User.userName -> username for cross-package consistency with tests - Fix auth middleware public-method allow-list casing (POST was 401) - Reference bun-types in tsconfig to resolve bun:test and process type errors
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 failing tests (was 13 pass / 9 fail → now 22 pass / 0 fail) and eliminates all
tsc --noEmittype errors (now 0 errors) across theapiandsharedpackages.Changes (5 files — no test files modified, no new dependencies)
packages/shared/src/utils/pagination.ts— Implementedpaginate<T>(was a throwing stub). Returns{ data, page, pageSize, total, totalPages }; out-of-range pages yield empty data, empty arrays yieldtotal: 0, totalPages: 0. Added minimalpage/sizenormalisation to prevent negativesliceoffsets silently returning tail items.packages/api/src/routes/users.ts— Added missingbadRequestimport from../lib/errors(the unresolved reference was throwing aReferenceError, turning intended 400s into 500s).packages/shared/src/types.ts— RenamedUser.userName→usernamefor consistency with the route code and tests. Audited both packages; this was the only mismatched field.packages/api/src/middleware/auth.ts— Fixed public-method allow-list casing ("post"→"POST", hoisted to aPUBLIC_METHODSconst, compared againstmethod.toUpperCase()), so public POST routes no longer return 401.tsconfig.json— Added"types": ["bun-types"], which transitively references@types/node. Both packages were already installed in the Bun store but not auto-included; this one line resolves allbun:testandprocesstype errors (including those in test files, without editing them).Verification
bun test→ 22 pass / 0 failnpx tsc --noEmit→ 0 errorsAssumptions / notes
username(notuserName) is the canonical field name."POST /users is public (no token required)"asserts this as intended behaviour, so it was implemented as specified — but a method-keyed allow-list is a weak authorisation model and warrants a dedicated security review before any real deployment.