import { describe, expect, it } from "vitest"; import { extractMailInstructions } from "@/services/parse/split-instructions"; import { extractBlPlusFromMail } from "@/services/parse/bl-plus-template"; const SUBJECT = "Fw: Fw:回复: 回复: LINK EVER INC + ZIMUSHH32195411+ 柜号:ZCSU6581068+ ETA : 7/7"; const BODY = [ "发自我的iPhone", "", "------------------ 原始邮件 ------------------", "寄件人: luo ", "发送时间: 2026年8月12日 09:50", "主旨: Fw: Fw:回复: 回复: LINK EVER INC + ZIMUSHH32195411+ 柜号:ZCSU6581068+ ETA : 7/7", "", "Forwarded message:", "", "From:op7 ", "", "Date:2026-07-07 01:53:15(美国山区 (GMT-07:00))", "", "Subject:回复: 回复: LINK EVER INC + ZIMUSHH32195411+ 柜号:ZCSU6581068+ ETA : 7/7", "", "", "新增转仓,请留意", "", " op7@xinfenginc.com", "", "  ", "发件人: op7", "发送时间: 2026-07-06 15:59", "主题: 回复: LINK EVER INC + ZIMUSHH32195411+ 柜号:ZCSU6581068+ ETA : 7/7", "", " 新增转仓,请留意", "", " op7@xinfenginc.com", "", "  ", "发件人: op7", "发送时间: 2026-06-27 16:55", "主题: LINK EVER INC + ZIMUSHH32195411+ 柜号:ZCSU6581068+ ETA : 7/7", "", " 柜号:ZCSU6581068  派送单,请查收", "", " op7@xinfenginc.com", ].join("\n"); describe("ZCSU6581068 LINK EVER thread", () => { it("parses bl-plus header from subject", () => { const bl = extractBlPlusFromMail(SUBJECT, BODY, { defaultYear: 2026 }); expect(bl?.modules.customer_name).toBe("LINK EVER INC"); expect(bl?.modules.container_no).toBe("ZCSU6581068"); expect(bl?.modules.bl_no).toBe("ZIMUSHH32195411"); expect(bl?.modules.eta).toBe("2026-07-07"); expect(bl?.modules.port).toBeUndefined(); }); it("keeps two transfer rounds and first forecast delivery note", () => { const units = extractMailInstructions({ subject: SUBJECT, body: BODY, filenames: ["柜号:ZCSU6581068卡派资料.xlsx"], }); const transfers = units.filter((u) => u.uiKind === "transfer"); const forecasts = units.filter((u) => u.uiKind === "forecast"); expect(transfers).toHaveLength(2); expect(transfers[0].roundAt).not.toEqual(transfers[1].roundAt); expect(transfers[0].label).not.toEqual(transfers[1].label); expect(forecasts).toHaveLength(1); expect(transfers[0].isCurrent).toBe(true); expect(forecasts[0].isCurrent).toBe(false); expect(forecasts[0].segmentText).toMatch(/派送单,请查收/); expect(units.map((u) => u.uiKind)).toEqual([ "transfer", "transfer", "forecast", ]); }); });