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.

49 lines
2.0 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 {
isKnownUsDestinationPort,
matchUsDestinationPort,
} from "@/services/parse/us-ports";
import {
isPlausibleDestinationPort,
normalizeDestinationPort,
parseBlPlusTemplate,
} from "@/services/parse/bl-plus-template";
describe("us destination ports whitelist", () => {
it("accepts known US ports and normalizes aliases", () => {
expect(matchUsDestinationPort("洛杉矶")).toBe("洛杉矶");
expect(matchUsDestinationPort("Los Angeles")).toBe("洛杉矶");
expect(matchUsDestinationPort("LA")).toBe("洛杉矶");
expect(matchUsDestinationPort("Long Beach")).toBe("长滩");
expect(matchUsDestinationPort("纽约")).toBe("纽约");
expect(matchUsDestinationPort("Savannah")).toBe("萨凡纳");
});
it("rejects non-port fragments", () => {
expect(matchUsDestinationPort("UPS-6件")).toBeNull();
expect(matchUsDestinationPort("ETA : 7/7 | Fw: 回复")).toBeNull();
expect(matchUsDestinationPort("拆柜清单")).toBeNull();
expect(matchUsDestinationPort("贴标操作")).toBeNull();
expect(matchUsDestinationPort("提拆派")).toBeNull();
expect(isKnownUsDestinationPort("随便中文")).toBe(false);
expect(isPlausibleDestinationPort("随便中文")).toBe(false);
expect(normalizeDestinationPort("UPS-6件")).toBe("");
});
it("keeps 洛杉矶 from bl-plus template and ignores channel as port", () => {
const ok = parseBlPlusTemplate(
"新辰泽+WHLC027G597465+WHSU8127240+洛杉矶+40HQ+EDT2026.04-25 ETA2026.05-15船名航次HMM EMERALD 013E+提拆派组合柜-不带托架",
{ defaultYear: 2026 },
);
expect(ok?.port).toBe("洛杉矶");
const bad = parseBlPlusTemplate(
"LINK EVER INC+ZIMUSHH32195411+柜号:ZCSU6581068+ETA : 7/7+UPS-6件+拆柜清单",
{ defaultYear: 2026 },
);
// 即使误解析,目的港也不得是渠道件数
expect(bad?.port == null || bad?.port === "洛杉矶").toBe(true);
expect(bad?.port).not.toBe("UPS-6件");
});
});