fix: repair failing tests and type errors across api and shared - #132
Open
stooit wants to merge 1 commit into
Open
fix: repair failing tests and type errors across api and shared#132stooit wants to merge 1 commit into
stooit wants to merge 1 commit into
Conversation
- shared/pagination: implement paginate (slice, total, totalPages, edge cases)
- shared/types: reconcile User field name userName -> username
- api/routes/users: import badRequest (fixes ReferenceError -> 400 not 500)
- api/middleware/auth: fix case-sensitivity bug ("post" -> "POST") so public POST /users no longer requires a token
- tsconfig: add bun-types to resolve bun:test/process types (no new deps)
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 and eliminates all type errors in the multi-package TypeScript HTTP API repo. After this change:
bun test→ 22 pass / 0 fail andnpx tsc --noEmit→ exit 0.Scope was kept strictly to what the tests require — no new dependencies, no test files modified.
Root causes fixed
packages/shared/src/utils/pagination.tspaginatewas an unimplemented stub (threw)total,totalPagesviaMath.ceil,page/pageSize; empty-array and out-of-range page fall out naturallypackages/shared/src/types.tsUserfield name inconsistent (userName) vs what api/tests use (username)usernamepackages/api/src/routes/users.tsbadRequestimport →ReferenceError→ 500 instead of 400 on missing fieldsbadRequestto the existing../lib/errorsimportpackages/api/src/middleware/auth.ts"post") meant publicPOST /userswrongly required a token["GET", "post"]→["GET", "POST"]— the only behavioural changetsconfig.jsonbun:test/processtypes unresolved (8 tsc errors)"types": ["bun-types"]— uses the already-present devDependency, no new depsVerification
bun test→ 22 pass, 0 failnpx tsc --noEmit→ exit 0, no outputAssumptions / notes
username(lowercase) chosen as the canonicalUserfield because the (unmodifiable) tests readbody[0].username.auth.tsretains the originalprocess.env.API_TOKEN ?? "test-token"fallback and a non-constant-time!==token comparison. No test covers this and it is pre-existing behaviour, so it was intentionally left untouched here — but it is a genuine security issue (production silently accepts a hardcoded token ifAPI_TOKENis unset) worth addressing in a scoped follow-up rather than smuggling into a "fix failing tests" diff.