import { describe, it, expect } from "vitest"; import { ValidationError, mapErrorToResponse } from "@/lib/errors"; import { teacherCreateSchema, normalizeTeacherCreateBody } from "@/lib/validation/schemas"; describe("teacherCreateSchema", () => { it("requires topic", () => { const result = teacherCreateSchema.safeParse({}); expect(result.success).toBe(false); }); it("accepts valid topic", () => { const result = teacherCreateSchema.safeParse({ topic: "Rust ownership" }); expect(result.success).toBe(true); }); it("accepts optional difficulty and length", () => { const result = teacherCreateSchema.safeParse({ topic: "DNS", difficulty: "intermediate", length: "deep", includeLibraryContext: false, }); expect(result.success).toBe(true); if (result.success) { const body = normalizeTeacherCreateBody(result.data); expect(body.difficulty).toBe("intermediate"); expect(body.length).toBe("deep"); expect(body.includeLibraryContext).toBe(false); } }); }); describe("mapErrorToResponse", () => { it("maps ValidationError to 400", () => { const mapped = mapErrorToResponse(new ValidationError("bad input")); expect(mapped.status).toBe(400); expect(mapped.message).toBe("bad input"); }); it("maps Unauthorized to 401", () => { const mapped = mapErrorToResponse(new Error("Unauthorized")); expect(mapped.status).toBe(401); }); });