|
|
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("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");
|
|
|
});
|
|
|
});
|