import { describe, expect, it } from "vitest"; import { getInstructionExecutionStateMap, listActionableInstructionUnits, markInstructionImported, resolveMailStatusAfterInstructionImport, } from "@/services/parse/instruction-execution-state"; describe("instruction-execution-state", () => { const subject = "ZCSU6581068 转仓通知"; const body = [ "2026-07-07 01:53:15", "新增转仓,请留意", "", "Forwarded message:", "Date: 2026-07-06 15:59", "新增转仓,请留意", ].join("\n"); it("lists multiple actionable transfer units", () => { const units = listActionableInstructionUnits({ subject, body, filenames: ["a.jpg", "b.jpg", "柜号ZCSU6581068 卡派资料.xlsx"], lineage: {}, }); expect(units.filter((u) => u.uiKind === "transfer")).toHaveLength(2); }); it("marks only the imported unit readonly and returns partial status", () => { const units = listActionableInstructionUnits({ subject, body, filenames: ["a.jpg", "b.jpg"], lineage: {}, }); const lineage = markInstructionImported({}, units[0].id, { status: "IMPORTED", importedAt: "2026-08-12T00:00:00.000Z", importedBy: "ops", mode: "mock", externalId: "x1", }); const state = getInstructionExecutionStateMap(lineage); expect(state[units[0].id]?.status).toBe("IMPORTED"); expect(state[units[1].id]).toBeUndefined(); expect( resolveMailStatusAfterInstructionImport({ currentStatus: "IMPORTING", subject, body, filenames: ["a.jpg", "b.jpg"], lineage, }), ).toBe("PARTIAL_SUCCESS"); }); it("returns success when all actionable units are imported", () => { const units = listActionableInstructionUnits({ subject, body, filenames: ["a.jpg", "b.jpg"], lineage: {}, }); let lineage: Record = {}; for (const unit of units) { lineage = markInstructionImported(lineage, unit.id, { status: "IMPORTED", importedAt: "2026-08-12T00:00:00.000Z", mode: "mock", }); } expect( resolveMailStatusAfterInstructionImport({ currentStatus: "IMPORTING", subject, body, filenames: ["a.jpg", "b.jpg"], lineage, }), ).toBe("SUCCESS"); }); });