CI / lint + typecheck + test + build (push) Canceled after 0s
- Auth: middleware.ts guards /protected via better-auth session cookie; protected page reads session server-side (auth.api.getSession) - Demo wiring (app/demo + components/demo): react-markdown + remark-gfm + shiki CodeBlock, RHF+zod form with react-query mutation + sonner toast, react-table items list (legacy API, table v9), /api/items GET+POST (zod v4 coercion, schema in lib/items.ts shared with unit tests) - Error UX: app/error.tsx (retry + digest), not-found.tsx (404), loading.tsx - Env: lib/env.ts zod-validated (no import-time throw), .env.example sync (NEXT_PUBLIC_BETTER_AUTH_URL), auth-client uses env - Tooling: @vitest/coverage-v8 (test:coverage works), tsconfig cleanup (drop .next/dev/dev/types artifact), README rewrite, demo e2e specs
31 lines
1.0 KiB
TypeScript
31 lines
1.0 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { createItemSchema } from "@/lib/items";
|
|
|
|
describe("items API schema", () => {
|
|
it("accepts valid input (coerces numeric strings)", () => {
|
|
const result = createItemSchema.safeParse({ name: "Chair", quantity: "4" });
|
|
expect(result.success).toBe(true);
|
|
if (result.success) {
|
|
expect(result.data).toEqual({ name: "Chair", quantity: 4 });
|
|
}
|
|
});
|
|
|
|
it("rejects empty name", () => {
|
|
const result = createItemSchema.safeParse({ name: "", quantity: 1 });
|
|
expect(result.success).toBe(false);
|
|
if (!result.success) {
|
|
expect(result.error.flatten().fieldErrors.name).toBeTruthy();
|
|
}
|
|
});
|
|
|
|
it("rejects non-numeric quantity", () => {
|
|
const result = createItemSchema.safeParse({ name: "Chair", quantity: "abc" });
|
|
expect(result.success).toBe(false);
|
|
});
|
|
|
|
it("rejects negative quantity", () => {
|
|
const result = createItemSchema.safeParse({ name: "Chair", quantity: -5 });
|
|
expect(result.success).toBe(false);
|
|
});
|
|
});
|