You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

80 lines
2.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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 <luo@usasinogroup.com>",
"发送时间: 2026年8月12日 09:50",
"主旨: Fw: Fw:回复: 回复: LINK EVER INC + ZIMUSHH32195411+ 柜号:ZCSU6581068+ ETA : 7/7",
"",
"Forwarded message:",
"",
"From:op7 <op7@xinfenginc.com>",
"",
"Date:2026-07-07 01:53:15(美国山区 (GMT-07:00))",
"",
"Subject:回复: 回复: LINK EVER INC + ZIMUSHH32195411+ 柜号:ZCSU6581068+ ETA : 7/7",
"",
"",
"新增转仓,请留意",
"",
" op7@xinfenginc.com",
"",
" &nbsp;",
"发件人:&nbsp;op7",
"发送时间:&nbsp;2026-07-06&nbsp;15:59",
"主题:&nbsp;回复: LINK EVER INC + ZIMUSHH32195411+ 柜号:ZCSU6581068+ ETA : 7/7",
"",
" 新增转仓,请留意",
"",
" op7@xinfenginc.com",
"",
" &nbsp;",
"发件人:&nbsp;op7",
"发送时间:&nbsp;2026-06-27&nbsp;16:55",
"主题:&nbsp;LINK EVER INC + ZIMUSHH32195411+ 柜号:ZCSU6581068+ ETA : 7/7",
"",
" 柜号:ZCSU6581068&nbsp; 派送单,请查收",
"",
" 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",
]);
});
});