Files
CertScope-Public/lib/inspect/score.test.ts
T

44 lines
1.3 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { score } from "./score";
import type { Finding } from "./types";
const finding = (impact: number, category: Finding["category"] = "http"): Finding => ({
id: `${category}-${impact}`,
category,
severity: "warning",
title: "test",
summary: "test",
evidence: [],
scoreImpact: impact,
});
describe("score", () => {
it("uses an equal-weighted aggregate of category scores", () => {
expect(score([finding(-18, "dns"), finding(-20, "tls"), finding(-22, "http")])).toEqual({
overall: 80,
deductions: 20,
categories: { dns: 82, tls: 80, http: 78 },
});
});
it("does not charge category deductions a second time globally", () => {
expect(score([finding(-8), finding(-6, "tls")])).toEqual({
overall: 95,
deductions: 5,
categories: { dns: 100, tls: 94, http: 92 },
});
});
it("rounds and clamps category and overall scores", () => {
expect(score([finding(-200, "dns"), finding(-200, "tls"), finding(-200, "http")])).toEqual({
overall: 0,
deductions: 100,
categories: { dns: 0, tls: 0, http: 0 },
});
});
it("ignores positive or non-finite score impacts", () => {
expect(score([finding(20, "dns"), finding(Number.NaN, "tls")]).overall).toBe(100);
});
});