26 lines
1.2 KiB
TypeScript
26 lines
1.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { demoInspection } from "./demo";
|
|
import { isInspectionResult } from "./validation";
|
|
|
|
describe("inspection result runtime validation", () => {
|
|
it("accepts the normalized result contract", () => {
|
|
expect(isInspectionResult(demoInspection)).toBe(true);
|
|
});
|
|
|
|
it.each([
|
|
null,
|
|
{},
|
|
{ ...demoInspection, host: "" },
|
|
{ ...demoInspection, inspectedAt: "not-a-date" },
|
|
{ ...demoInspection, score: { overall: 100, categories: { dns: 100 } } },
|
|
{ ...demoInspection, completeness: { ...demoInspection.completeness, collectors: { dns: "unknown", tls: "ok", http: "ok" } } },
|
|
{ ...demoInspection, completeness: { ...demoInspection.completeness, complete: 4, total: 3 } },
|
|
{ ...demoInspection, findings: [{ id: "missing-fields" }] },
|
|
{ ...demoInspection, findings: [{ ...demoInspection.findings[0], category: "unknown" }] },
|
|
{ ...demoInspection, findings: [{ ...demoInspection.findings[0], evidence: [42] }] },
|
|
{ ...demoInspection, findings: [{ ...demoInspection.findings[0], remediation: { unexpected: true } }] },
|
|
])("rejects malformed payload %#", (payload) => {
|
|
expect(isInspectionResult(payload)).toBe(false);
|
|
});
|
|
});
|