Files
Jyotisha/frontend/tests/rectification-candidate-result.test.ts
T
Jesse_Chen c8af18e90a
Independent Staging Quality Gate / validate (push) Failing after 9m39s
Independent Staging Quality Gate / publish (push) Has been skipped
fix(rectification): show the house table and hide the activity fold
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-19 20:11:51 +08:00

112 lines
3.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 representative receives a recommendation badge", () => {
const result = parseRectificationCandidateResult({
...camelCaseSnapshot,
overallConfidence: "medium",
confirmationAllowed: false,
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);
});
test("reads the representative house table from the decision receipt", () => {
const result = parseRectificationCandidateResult({
...camelCaseSnapshot,
representativeTime: "05:07",
decisionReceipt: {
house_table: {
time: "05:07",
lagna: "金牛座",
houses: Array.from({ length: 12 }, (_, index) => ({
house: index + 1,
sign: "金牛座",
occupants: index === 0 ? ["太阳"] : [],
})),
},
},
});
assert.equal(result?.houseTable?.time, "05:07");
assert.equal(result?.houseTable?.lagna, "金牛座");
assert.equal(result?.houseTable?.houses[0]?.occupants[0], "太阳");
});
test("drops a house table that still carries longitudes", () => {
const result = parseRectificationCandidateResult({
...camelCaseSnapshot,
house_table: {
time: "05:07",
lagna: "金牛座",
houses: Array.from({ length: 12 }, (_, index) => ({
house: index + 1,
sign: "金牛座",
occupants: index === 0 ? ["太阳 123.4 lon"] : [],
})),
},
});
assert.equal(result?.houseTable, null);
});