57 lines
2.0 KiB
TypeScript
57 lines
2.0 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import {
|
|
isRecommendedRectificationCandidate,
|
|
parseRectificationCandidateResult,
|
|
} from "../src/lib/rectification-candidate-result.ts";
|
|
|
|
const camelCaseSnapshot = {
|
|
resultId: "11111111-1111-4111-8111-111111111111",
|
|
candidates: [
|
|
{ rank: 1, time: "05:07", relative_support: 34, tied_minute_count: 1 },
|
|
{ rank: 2, time: "05:08", relative_support: 33, tied_minute_count: 1 },
|
|
{ rank: 3, time: "05:09", relative_support: 33, tied_minute_count: 1 },
|
|
],
|
|
overallConfidence: "low",
|
|
selectionAllowed: true,
|
|
confirmationAllowed: false,
|
|
representativeTime: null,
|
|
selectedTime: null,
|
|
selectionKind: null,
|
|
};
|
|
|
|
test("parses the camelCase Candidate Snapshot returned by the Case API", () => {
|
|
const result = parseRectificationCandidateResult(camelCaseSnapshot);
|
|
|
|
assert.ok(result);
|
|
assert.equal(result.resultId, camelCaseSnapshot.resultId);
|
|
assert.equal(result.candidates[0]?.time, "05:07");
|
|
assert.equal(result.candidates[0]?.relativeSupport, 34);
|
|
assert.equal(result.selectionAllowed, true);
|
|
assert.equal(result.confirmationAllowed, false);
|
|
});
|
|
|
|
test("low-confidence near ties never receive a recommendation badge", () => {
|
|
const result = parseRectificationCandidateResult(camelCaseSnapshot);
|
|
|
|
assert.ok(result);
|
|
assert.equal(isRecommendedRectificationCandidate(result, result.candidates[0]!), false);
|
|
});
|
|
|
|
test("only an unselected confirmation-ready representative receives a recommendation badge", () => {
|
|
const result = parseRectificationCandidateResult({
|
|
...camelCaseSnapshot,
|
|
overallConfidence: "high",
|
|
confirmationAllowed: true,
|
|
representativeTime: "05:07",
|
|
});
|
|
|
|
assert.ok(result);
|
|
assert.equal(isRecommendedRectificationCandidate(result, result.candidates[0]!), true);
|
|
assert.equal(isRecommendedRectificationCandidate(result, result.candidates[1]!), false);
|
|
|
|
const adopted = { ...result, selectedTime: "05:07" };
|
|
assert.equal(isRecommendedRectificationCandidate(adopted, adopted.candidates[0]!), false);
|
|
});
|