From e8ee58dc2b5c374605ee2410950deaf731313cfa Mon Sep 17 00:00:00 2001 From: QuantCode Agent Date: Tue, 10 Nov 2026 04:38:02 +0000 Subject: [PATCH] fix: resolve failing tests and type errors across api and shared packages --- packages/api/src/middleware/auth.ts | 13 +------------ packages/api/src/routes/users.ts | 2 +- packages/shared/src/types.ts | 2 +- packages/shared/src/utils/pagination.ts | 10 +++++++++- tsconfig.json | 1 + 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/packages/api/src/middleware/auth.ts b/packages/api/src/middleware/auth.ts index dde32d9..172ff76 100644 --- a/packages/api/src/middleware/auth.ts +++ b/packages/api/src/middleware/auth.ts @@ -2,20 +2,9 @@ import type { MiddlewareHandler } from "hono" /** * Simple token-based auth middleware. - * - * Policy: - * GET, POST → public (no token required) - * PUT, DELETE, PATCH → require Bearer token - * - * BUG: The allow-list check uses `'post'` (lowercase) instead of `'POST'`. - * HTTP methods are always uppercase per RFC 7231, so POST is never matched - * as a public method — POST requests incorrectly require a token. - * - * Fix: change `'post'` to `'POST'` in the public methods array. */ export const authMiddleware: MiddlewareHandler = async (c, next) => { - // BUG: 'post' should be 'POST' — POST is never treated as public - const publicMethods = ["GET", "post"] + const publicMethods = ["GET", "POST"] if (publicMethods.includes(c.req.method)) { return next() diff --git a/packages/api/src/routes/users.ts b/packages/api/src/routes/users.ts index 53e605a..2ab3111 100644 --- a/packages/api/src/routes/users.ts +++ b/packages/api/src/routes/users.ts @@ -1,6 +1,6 @@ import { Hono } from "hono" import { db } from "../lib/db" -import { notFound } from "../lib/errors" +import { notFound, badRequest } from "../lib/errors" // BUG: missing import — `badRequest` is used below but not imported here. // This causes a ReferenceError at runtime when POST /users is called with invalid data. // Fix: add `badRequest` to the import from "../lib/errors" diff --git a/packages/shared/src/types.ts b/packages/shared/src/types.ts index a2a1377..d522b01 100644 --- a/packages/shared/src/types.ts +++ b/packages/shared/src/types.ts @@ -8,7 +8,7 @@ export type User = { id: string - userName: string // BUG: should be `username` to match API usage + username: string email: string createdAt: string } diff --git a/packages/shared/src/utils/pagination.ts b/packages/shared/src/utils/pagination.ts index 12f8062..396df97 100644 --- a/packages/shared/src/utils/pagination.ts +++ b/packages/shared/src/utils/pagination.ts @@ -11,5 +11,13 @@ import type { PaginatedResponse } from "../types" * The test in packages/shared/test/pagination.test.ts exercises the full contract. */ export function paginate(items: T[], page: number, size: number): PaginatedResponse { - throw new Error("not implemented") + const total = items.length + const start = (page - 1) * size + return { + data: items.slice(start, start + size), + page, + pageSize: size, + total, + totalPages: Math.ceil(total / size), + } } diff --git a/tsconfig.json b/tsconfig.json index 53de6fd..aacda15 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,6 +4,7 @@ "module": "ESNext", "moduleResolution": "bundler", "strict": true, + "types": ["bun-types"], "skipLibCheck": true, "paths": { "@e2e/shared": ["./packages/shared/src/index.ts"]