Files
hose-use/src/domains/approval/status-validation.test.ts
T

21 lines
1.5 KiB
TypeScript

import { afterEach, expect, test } from "bun:test";
import { getDatabase, closeDatabase } from "../../core/db/index.js";
import { ApprovalRepository } from "./repository.js";
import { ApprovalService } from "./service.js";
import { evaluateGatewayPolicy } from "./gateway.js";
afterEach(closeDatabase);
test("rejects unknown status before updates and blocks corrupt persisted findings", () => {
const db = getDatabase(":memory:");
const repo = new ApprovalRepository(db);
const run = repo.createApprovalRun({ documentSn: "SN", corpId: "corp" });
const findings = repo.injectFindings(run.id, [{ clauseText: "invoice", strictness: "硬性", checkStatus: "PENDING" }, { clauseText: "amount", strictness: "硬性", checkStatus: "PENDING" }]);
expect(() => repo.updateFinding(findings[0].id, { checkStatus: "TYPO" as any })).toThrow("核验状态");
expect(() => new ApprovalService(repo).evaluateAuditPoints("SN", [{ index: 1, status: "PASS" }, { index: 2, status: "TYPO" as any }], "corp")).toThrow("核验状态");
expect(repo.getFindingsByRunId(run.id).map(f => f.checkStatus)).toEqual(["PENDING", "PENDING"]);
expect(() => repo.injectFindings(run.id, [{ clauseText: "bad", strictness: "硬性", checkStatus: "TYPO" as any }])).toThrow("核验状态");
expect(repo.getFindingsByRunId(run.id)).toHaveLength(2);
db.run("UPDATE approval_findings SET check_status = 'TYPO' WHERE run_id = ?", [run.id]);
expect(() => evaluateGatewayPolicy({ documentSn: "SN", findings: repo.getFindingsByRunId(run.id) })).toThrow("非法核验状态");
});