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.

97 lines
3.1 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 { classifyMail } from "@/services/parse/classify";
import {
extractContainerHeaderFromText,
matchShippingLineId,
mergeContainerHeader,
shippingLineHintFromBl,
} from "@/services/parse/extract-container-header";
describe("extractContainerHeaderFromText", () => {
it("extracts ETA/柜型/船司/港口/提单 from mail body", () => {
const text = `新增预报 MATU2745683 卡派资料
柜型:40HQ
ETA:2026-08-15
ETD:2026-07-20
船司:MSC
装货港:上海
目的港:洛杉矶
提单:BLMATU2745683
`;
const h = extractContainerHeaderFromText(text);
expect(h.F_CabinetType).toBe("40HQ");
expect(h.F_ETA).toBe("2026-08-15");
expect(h.F_ETD).toBe("2026-07-20");
expect(h.shipping_line_hint).toBe("MSC");
expect(h.F_LoadPort).toBe("上海");
expect(h.F_Dock).toBe("洛杉矶");
expect(h.F_BLCopyCode).toBe("BLMATU2745683");
});
it("直送 → OperationType 2", () => {
const h = extractContainerHeaderFromText("本票直送仓库,请安排");
expect(h.F_OperationType).toBe(2);
});
it("提拆派 → OperationType 0(优先于直送)", () => {
const h = extractContainerHeaderFromText("提拆派组合柜-不带托架");
expect(h.F_OperationType).toBe(0);
expect(h.F_Classis).toBe(0);
});
it("拆柜清单 → OperationType 0(对齐 AI 助手 header_extract)", () => {
const h = extractContainerHeaderFromText(
"WHSU5574991+WHL063G550810+船名航次:OOCL SINGAPORE / 065W+ETA:6/28+FedEx-29件+UPS-102件+亚马逊卡派-289件+私人地址-166件+拦截-209件+拆柜清单",
);
expect(h.F_OperationType).toBe(0);
});
it("shippingLineHintFromBl extracts WHLC", () => {
expect(shippingLineHintFromBl("WHLC027G597465")).toBe("WHLC");
});
it("merge prefers attachment container no, fills empty ETA", () => {
const merged = mergeContainerHeader(
{
F_ContainerNo: "MATU2745683",
container_no_valid: true,
F_ETA: null,
},
{ F_ETA: "2026-08-15", F_CabinetType: "40HQ" },
);
expect(merged.F_ContainerNo).toBe("MATU2745683");
expect(merged.F_ETA).toBe("2026-08-15");
expect(merged.F_CabinetType).toBe("40HQ");
});
it("matchShippingLineId fuzzy", () => {
const id = matchShippingLineId("MSC", [
{ F_Id: "line-1", F_FullName: "Mediterranean Shipping", F_EnCode: "MSC" },
]);
expect(id).toBe("line-1");
});
it("matchShippingLineId by F_Prefix on BL (WHLC)", () => {
const id = matchShippingLineId(
"WHLC",
[
{ F_Id: "whl", F_EnCode: "WHL", F_Prefix: "WHL" },
{ F_Id: "whlc", F_EnCode: "WHLC", F_Prefix: "WHLC" },
],
{ blNo: "WHLC027G597465" },
);
expect(id).toBe("whlc");
});
});
describe("M5 gate classify", () => {
it("新增预报+卡派 → NEW_CONTAINER(无需改类型)", () => {
const r = classifyMail({
subject: "新增预报 MATU2745683 卡派资料",
body: "柜型:40HQ ETA:2026-08-15",
filenames: ["卡派资料.xlsx"],
});
expect(r.mail_type).toBe("NEW_CONTAINER");
});
});