75 lines
2.7 KiB
TypeScript
75 lines
2.7 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import {
|
|
isRecommendedRectificationCandidate,
|
|
parseRectificationCandidateResult,
|
|
} from "../src/lib/rectification-candidate-result.ts";
|
|
|
|
const CANDIDATE_ID = "88888888-8888-4888-8888-888888888881";
|
|
const SECOND_CANDIDATE_ID = "88888888-8888-4888-8888-888888888882";
|
|
const THIRD_CANDIDATE_ID = "88888888-8888-4888-8888-888888888883";
|
|
|
|
const camelCaseSnapshot = {
|
|
resultId: "11111111-1111-4111-8111-111111111111",
|
|
candidates: [
|
|
{ candidateId: CANDIDATE_ID, rank: 1, time: "05:07", relativeSupport: 34, tiedMinuteCount: 1 },
|
|
{ candidateId: SECOND_CANDIDATE_ID, rank: 2, time: "05:08", relativeSupport: 33, tiedMinuteCount: 1 },
|
|
{ candidateId: THIRD_CANDIDATE_ID, rank: 3, time: "05:09", relativeSupport: 33, tiedMinuteCount: 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]?.candidateId, CANDIDATE_ID);
|
|
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);
|
|
});
|
|
|
|
|
|
test("fails closed instead of treating an HH:MM display value as a candidate id", () => {
|
|
const result = parseRectificationCandidateResult({
|
|
...camelCaseSnapshot,
|
|
candidates: [{
|
|
...camelCaseSnapshot.candidates[0],
|
|
candidateId: "05:07",
|
|
}],
|
|
});
|
|
|
|
assert.equal(result, null);
|
|
});
|