fix: repair failing tests and type errors across api and shared packages - #119
Open
stooit wants to merge 1 commit into
Open
fix: repair failing tests and type errors across api and shared packages#119stooit wants to merge 1 commit into
stooit wants to merge 1 commit into
Conversation
- auth middleware: fix case-sensitivity bug in public-method allow-list
("post" -> "POST") so POST routes are correctly treated as public;
normalise method comparison to uppercase to prevent recurrence
- shared types: rename User.userName -> username to match the API/test
contract (test files are the source of truth and were not modified)
- routes/users: add missing badRequest import (was a runtime ReferenceError
on the invalid-POST path)
- shared pagination: implement paginate() stub against the full test
contract; guard against non-finite page/size (Number.isFinite) so
user-supplied paging params can't corrupt the response
- tsconfig: reference already-installed bun-types so process/bun:test
resolve (no new dependencies)
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 failing tests and eliminates all type errors.
bun test→ 22 pass / 0 fail;bunx tsc --noEmit→ clean (exit 0).The bugs spanned both packages and matched the areas called out in the task brief.
Changes
packages/api/src/middleware/auth.ts) — Fixed a case-sensitivity bug in the public-method allow-list ("post"→"POST") soPOSTroutes are correctly treated as public. Method comparison is now normalised to uppercase to prevent this class of access-control bug from recurring.packages/shared/src/types.ts) — RenamedUser.userName→username. The unmodifiable test files (users.test.ts,auth.test.ts) useusernameand are the contract, so the type was wrong, not the call sites. The rename is complete across both packages.packages/api/src/routes/users.ts) — Added the missingbadRequestimport (already exported from../lib/errors). This was a genuine runtimeReferenceErroron the invalid-POST path, which is why "returns 400 for missing fields" failed.packages/shared/src/utils/pagination.ts) — Implemented the previously-stubbedpaginate()against the full test contract (page slicing,total/totalPages,page/pageSize, out-of-range → empty data, empty-array handling). Also guarded against non-finitepage/sizeviaNumber.isFiniteso user-supplied query params can't corrupt the response (Infinitypreviously producedpageSize: nulland zero items).tsconfig.json— Referenced the already-installedbun-types("types": ["bun-types"]) so theprocessglobal andbun:testmodule resolve. No new dependencies added —bun-typeswas already a declared devDependency.Constraints honoured
Assumptions
username(notuserName) is the canonical field name, inferred from the unmodifiable test files being the source of truth.Follow-ups (out of scope)
packages/api/src/middleware/validate.tsexports an unusedrequireFields()middleware duplicating inline route validation — could be consolidated.POSTunauthenticated (anonymous record creation). Pre-existing, deliberate, and asserted by the tests — flagged only for a future access-control decision.bun-typesis pinned to"latest"inpackage.json(pre-existing); worth pinning for reproducible builds.