test(frontend): pin the generated assessment response contract
This commit is contained in:
1 parent
a7d5781f2d
commit
391c8a6cec
1 file changed
+127
@@ -0,0 +1,127 @@
|
||||
import { describe, expect, expectTypeOf, it } from "vitest";
|
||||
import { AssessmentAttempt, AssessmentResult } from "./schemas";
|
||||
|
||||
// These tests pin the generated response contract of the assessment client:
|
||||
// a response that drops calibration_status or reports an unknown attempt state
|
||||
// must fail the check, and the types must let the UI show an unfinished
|
||||
// practice and a missing calibration without inventing numbers. The fixtures
|
||||
// follow the AssessmentDemoBasicResult and AssessmentAttemptResumed examples
|
||||
// of the source contract.
|
||||
|
||||
const demoResult = {
|
||||
attempt_id: "01928f7a-3c4d-7e5f-8a9b-0c1d2e3f4a5b",
|
||||
specialization: "backend",
|
||||
target_grade: "junior",
|
||||
task_language: "go",
|
||||
mode: "demo_basic",
|
||||
versions: {
|
||||
policy_version: 1,
|
||||
bank_version: "backend-demo.2026-10.1",
|
||||
algorithm_version: "basic-raw-score.1",
|
||||
},
|
||||
outcome: "confirmed",
|
||||
not_determined_reason: null,
|
||||
confirmed_grade: "junior",
|
||||
previous_confirmed_grade: null,
|
||||
strength: null,
|
||||
calibration_status: "uncalibrated",
|
||||
limitations: ["uncalibrated_thresholds", "demo_bank", "practice_not_included", "unproctored"],
|
||||
uncertainty: null,
|
||||
basic_score: { points: 9, max_points: 12, pass_points: 8 },
|
||||
practices: [],
|
||||
gaps: [],
|
||||
durations: { items_seconds: 1260, practice_seconds: null },
|
||||
next_steps: [{ action: "take_higher_grade", grade: "middle", available_at: null }],
|
||||
decided_at: "2026-10-08T10:24:00Z",
|
||||
};
|
||||
|
||||
const pendingPracticeAttempt = {
|
||||
id: "01928f7b-1111-7a2b-8c3d-4e5f6a7b8c9d",
|
||||
version: 7,
|
||||
specialization: "backend",
|
||||
target_grade: "middle",
|
||||
task_language: "python",
|
||||
mode: "adaptive",
|
||||
state: "practice_pending",
|
||||
versions: {
|
||||
policy_version: 2,
|
||||
bank_version: "backend.2026-11.3",
|
||||
algorithm_version: "irt-1pl-eap.1",
|
||||
},
|
||||
started_at: "2026-11-20T09:00:00Z",
|
||||
expires_at: "2026-11-23T09:00:00Z",
|
||||
sessions: { used: 1, max: 2, idle_timeout_seconds: 1800 },
|
||||
finished_at: null,
|
||||
progress: { answered_items: 25, max_items: 25 },
|
||||
current_item: null,
|
||||
practices: [
|
||||
{
|
||||
kind: "main",
|
||||
item_id: "01928f7b-2222-7a2b-8c3d-4e5f6a7b8c99",
|
||||
status: "pending",
|
||||
submitted_at: "2026-11-20T10:00:00Z",
|
||||
verdict: null,
|
||||
failure_reason: null,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
describe("generated AssessmentResult", () => {
|
||||
it("accepts a demo result without uncertainty or strength numbers", () => {
|
||||
const parsed = AssessmentResult.parse(demoResult);
|
||||
|
||||
expect(parsed.calibration_status).toBe("uncalibrated");
|
||||
expect(parsed.uncertainty).toBeNull();
|
||||
expect(parsed.strength).toBeNull();
|
||||
});
|
||||
|
||||
it("rejects a result without calibration_status", () => {
|
||||
const result: Record<string, unknown> = { ...demoResult };
|
||||
delete result.calibration_status;
|
||||
|
||||
const parsed = AssessmentResult.safeParse(result);
|
||||
|
||||
expect(parsed.success).toBe(false);
|
||||
expect(parsed.error?.issues).toEqual([
|
||||
expect.objectContaining({ path: ["calibration_status"] }),
|
||||
]);
|
||||
});
|
||||
|
||||
it("rejects an unknown calibration status", () => {
|
||||
const parsed = AssessmentResult.safeParse({ ...demoResult, calibration_status: "estimated" });
|
||||
|
||||
expect(parsed.success).toBe(false);
|
||||
expect(parsed.error?.issues).toEqual([
|
||||
expect.objectContaining({ code: "invalid_value", path: ["calibration_status"] }),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("generated AssessmentAttempt", () => {
|
||||
it("accepts an unfinished practice without a verdict", () => {
|
||||
const parsed = AssessmentAttempt.parse(pendingPracticeAttempt);
|
||||
|
||||
expect(parsed.practices[0]?.status).toBe("pending");
|
||||
expect(parsed.practices[0]?.verdict).toBeNull();
|
||||
});
|
||||
|
||||
it("rejects an unknown attempt state", () => {
|
||||
const parsed = AssessmentAttempt.safeParse({ ...pendingPracticeAttempt, state: "paused" });
|
||||
|
||||
expect(parsed.success).toBe(false);
|
||||
expect(parsed.error?.issues).toEqual([
|
||||
expect.objectContaining({ code: "invalid_value", path: ["state"] }),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
it("types allow null instead of fabricated numbers", () => {
|
||||
type Practice = AssessmentAttempt["practices"][number];
|
||||
|
||||
expectTypeOf<null>().toExtend<AssessmentResult["uncertainty"]>();
|
||||
expectTypeOf<null>().toExtend<AssessmentResult["basic_score"]>();
|
||||
expectTypeOf<null>().toExtend<AssessmentResult["strength"]>();
|
||||
expectTypeOf<null>().toExtend<Practice["verdict"]>();
|
||||
expectTypeOf<"uncalibrated">().toExtend<AssessmentResult["calibration_status"]>();
|
||||
expectTypeOf<"pending">().toExtend<Practice["status"]>();
|
||||
});
|
||||
Reference in new issue
Block a user