import { describe, expect, it } from "vitest"; import { buildMailRecord, collectWorkOrderActions, extractContainerFromFirstLines, hasWorkOrderSignal, } from "@/services/parse/work-order-record"; describe("work-order-record", () => { it("extracts container from first two lines", () => { const body = "柜号 WHSU8127240 请处理\n后续说明很长\nMATU2745683 不该取"; expect(extractContainerFromFirstLines(body)).toBe("WHSU8127240"); }); it("collects work order keywords", () => { expect( collectWorkOrderActions("转仓通知", "请贴标并拍照,快递单号:SF1234567890", []), ).toEqual(expect.arrayContaining(["转仓", "贴标", "拍照", "快递单号"])); }); it("excludes 不转仓", () => { expect(hasWorkOrderSignal("通知", "本票不转仓", [])).toBe(false); }); it("builds WORK_ORDER table", () => { const r = buildMailRecord({ mailType: "WORK_ORDER", subject: "MATU2745683 转仓通知", body: "新增转仓,请留意\n快递单号:YT998877", filenames: [], containerNo: "MATU2745683", shipments: [ { row_index: 1, row_status: "VALID", F_FBACode: "ABQ2", F_Remark: "转POC2", F_CTNS: 1, }, ], }); expect(r.kind).toBe("WORK_ORDER"); expect(r.work_order_actions).toContain("转仓"); expect(r.table.columns).toContain("原仓"); expect(r.table.rows.length).toBeGreaterThan(0); expect(r.table.rows[0]["目标仓"]).toBe("POC2"); }); it("prefers body 改地址派送 over subject 派拆柜 template", () => { const r = buildMailRecord({ mailType: "WORK_ORDER", subject: "Fw: ZJYC COSU6504130784 FCIU7089474 7.10 派拆柜派送", body: "FCIU7089474 MR03002964 改地址派送到 7400 E. Slauson Ave commerce. CA 90040", opsSubject: { modules: { customer_name: "ZJYC", bl_no: "COSU6504130784", container_no: "FCIU7089474", eta: "2026-07-10", service: "派拆柜派送", ops_hints: ["拆柜", "派送"], }, channels: [], }, }); expect(r.kind).toBe("WORK_ORDER"); expect(r.work_order_actions).toContain("改地址派送"); expect(r.summary).toMatch(/改地址派送/); expect(r.summary).not.toMatch(/拆柜、派送/); expect(r.lineage.subject_only).toBe(false); }); it("builds BL_FORECAST from modules", () => { const r = buildMailRecord({ mailType: "NEW_CONTAINER", subject: "新增预报", body: "", blModules: { customer_name: "新辰泽", bl_no: "WHLC027G597465", container_no: "WHSU8127240", port: "洛杉矶", cabinet_type: "40HQ", }, shipments: [], }); expect(r.kind).toBe("BL_FORECAST"); expect(r.modules.bl_no).toBe("WHLC027G597465"); }); it("DO_UPLOAD keeps bl-plus customer_name", () => { const r = buildMailRecord({ mailType: "DO_UPLOAD", subject: "智鸿2+WHLC027G597465+WHSU8127240+洛杉矶+40HQ", body: "请查收新增预报", blModules: { customer_name: "智鸿2", bl_no: "WHLC027G597465", container_no: "WHSU8127240", port: "洛杉矶", cabinet_type: "40HQ", }, shipments: [], }); expect(r.modules.customer_name).toBe("智鸿2"); expect(r.kind).toBe("BL_FORECAST"); expect(r.summary).toMatch(/上传DO|智鸿2/); }); });