initial 2
Some checks failed
CI / test (push) Has been cancelled

This commit is contained in:
2026-06-26 09:26:50 +01:00
parent 194330fb47
commit 3b37368e7d
213 changed files with 14688 additions and 1 deletions

View File

@@ -0,0 +1,39 @@
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 null explorationId", () => {
const result = teacherCreateSchema.safeParse({
topic: "Rust ownership",
explorationId: null,
});
expect(result.success).toBe(true);
if (result.success) {
expect(normalizeTeacherCreateBody(result.data).explorationId).toBeUndefined();
}
});
});
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);
});
});