43 lines
2.6 KiB
TypeScript
43 lines
2.6 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
import { builtMessageState } from "../src/features/campaigns/review/builtMessageState.ts";
|
|
|
|
const noReviews = new Set<string>();
|
|
const row = (validation_status: string, fields: Record<string, unknown> = {}) => ({
|
|
id: "job-1", review_key: "recipient-key", build_status: "built", validation_status, ...fields
|
|
});
|
|
|
|
test("single display state distinguishes automatic and explicitly accepted readiness", () => {
|
|
assert.deepEqual(builtMessageState(row("ready"), 0, noReviews), { state: "ready", explanationLabel: "i18n:govoplan-campaign.message_state_automatic" });
|
|
assert.deepEqual(builtMessageState(row("needs_review"), 0, noReviews), { state: "needs_review", explanationLabel: "i18n:govoplan-campaign.message_state_individual_pending" });
|
|
assert.deepEqual(builtMessageState(row("needs_review"), 0, new Set(["recipient-key"])), { state: "ready", explanationLabel: "i18n:govoplan-campaign.message_state_individually_accepted" });
|
|
assert.equal(builtMessageState(row("needs_review", { reviewed: true }), 0, noReviews).state, "ready");
|
|
});
|
|
|
|
test("warnings need the final acknowledgement, not a legacy view marker", () => {
|
|
assert.deepEqual(builtMessageState(row("warning", { reviewed: true }), 0, new Set(["recipient-key"])), {
|
|
state: "needs_review", explanationLabel: "i18n:govoplan-campaign.message_state_warning_pending"
|
|
});
|
|
assert.deepEqual(builtMessageState(row("warning"), 0, noReviews, true), {
|
|
state: "ready", explanationLabel: "i18n:govoplan-campaign.message_state_warning_accepted"
|
|
});
|
|
});
|
|
|
|
test("hard blockers and failed builds never become ready through a review marker", () => {
|
|
for (const message of [row("blocked", { reviewed: true }), row("needs_review", { reviewed: true, issues: [{ behavior: "block" }] }),
|
|
row("ready", { build_status: "failed" }), row("ready", { build_status: "pending" }), row("unknown")]) {
|
|
assert.equal(builtMessageState(message, 0, new Set(["recipient-key"]), true).state, "blocked");
|
|
}
|
|
});
|
|
|
|
test("intentionally excluded or inactive messages remain excluded, including unbuilt ones", () => {
|
|
for (const status of ["excluded", "inactive"]) {
|
|
assert.equal(builtMessageState(row(status, { build_status: "failed", reviewed: true }), 0, noReviews, true).state, "excluded");
|
|
}
|
|
});
|
|
|
|
test("complete review does not invent a missing individual decision", () => {
|
|
assert.equal(builtMessageState(row("needs_review"), 0, noReviews, true).state, "needs_review");
|
|
assert.equal(builtMessageState(row("needs_review", { entry_id: "legacy-entry", review_key: undefined }), 0, new Set(["legacy-entry"])).state, "ready");
|
|
});
|