import { toPublicProblem } from "../serialize"; import type { CodeCreationProblem, CodeReviewProblem, ArchitectureProblem, DebuggingProblem, } from "../types"; describe("toPublicProblem", () => { it("strips the reference solution and hidden tests from code-creation", () => { const p: CodeCreationProblem = { id: "p1", type: "code-creation", language: "javascript", difficulty: "easy", title: "t", prompt: "p", entryFunction: "add", starterCode: "function add(){}", referenceSolution: "function add(a,b){return a+b}", tests: [ { name: "shown", input: [1, 1], expected: 2, hidden: false }, { name: "secret", input: [9, 9], expected: 18, hidden: true }, ], }; const pub = toPublicProblem(p) as { tests: unknown[] } & Record; expect("referenceSolution" in pub).toBe(false); expect(pub.tests).toHaveLength(1); expect((pub.tests[0] as { name: string }).name).toBe("shown"); expect(pub.starterCode).toBe("function add(){}"); }); it("strips the known issues from code-review", () => { const p: CodeReviewProblem = { id: "r1", type: "code-review", language: "javascript", difficulty: "medium", title: "t", prompt: "p", code: "function f(){}", issues: [{ id: "x", title: "a", description: "b", severity: "minor" }], }; const pub = toPublicProblem(p) as Record; expect("issues" in pub).toBe(false); expect(pub.code).toBe("function f(){}"); }); it("strips the rubric from architecture", () => { const p: ArchitectureProblem = { id: "a1", type: "architecture", language: "go", difficulty: "hard", title: "t", prompt: "p", rubric: [{ id: "x", point: "y", weight: 1 }], }; const pub = toPublicProblem(p) as Record; expect("rubric" in pub).toBe(false); expect(pub.prompt).toBe("p"); }); it("keeps the buggy code for debugging but strips the reference fix", () => { const p: DebuggingProblem = { id: "d1", type: "debugging", language: "javascript", difficulty: "medium", title: "t", prompt: "p", entryFunction: "f", buggyCode: "function f(){return 0}", referenceSolution: "function f(){return 1}", tests: [{ name: "h", input: [], expected: 1, hidden: true }], }; const pub = toPublicProblem(p) as Record; expect("referenceSolution" in pub).toBe(false); expect(pub.buggyCode).toBe("function f(){return 0}"); expect(pub.tests).toHaveLength(0); // all hidden }); });