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.
mail-yubao/tests/unit/extract-container-header.te...

85 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 {
extractContainerHeaderFromText,
matchShippingLineId,
} from "@/services/parse/extract-container-header";
import {
AIRLINE_ALIASES,
EXPRESS_ALIASES,
SHIPPING_LINE_ALIASES,
} from "@/services/parse/carrier-aliases";
describe("matchShippingLineId", () => {
it.each([
["COSCO", "中国远洋海运集团有限公司", "cosco-cn"],
["OOCL", "东方海外货柜航运公司", "oocl-cn"],
["WAN HAI", "万海航运股份有限公司", "whl-cn"],
["HMM", "韩新海运", "hmm-cn"],
["MSC", "地中海航运", "msc-cn"],
["EMC", "长荣海运", "emc-cn"],
["EGLV", "长荣海运", "emc-cn"],
["CMA CGM", "达飞轮船", "cma-cn"],
["ZIM", "以星综合航运", "zim-cn"],
["ZIMU", "以星综合航运", "zim-cn"],
["ONE", "海洋网联船务", "one-cn"],
["ONEY", "海洋网联船务", "one-cn"],
["MATSON", "美森轮船", "matson-cn"],
])("matches alias %s to shipping line %s", (hint, fullName, expectedId) => {
const id = matchShippingLineId(hint, [
{ F_Id: expectedId, F_FullName: fullName },
{ F_Id: "other", F_FullName: "其他船司", F_EnCode: "OTHER" },
]);
expect(id).toBe(expectedId);
});
it("infers sea mode and evergreen from EGLV master BL", () => {
const h = extractContainerHeaderFromText(
"柜号:TRHU8524770 提单号:EGLV143661466958 整柜直送",
);
expect(h.F_BLCopyCode).toBe("EGLV143661466958");
expect(h.shipping_line_hint).toBe("EGLV");
expect(h.F_TransMode).toBe(0);
const id = matchShippingLineId(h.shipping_line_hint, [
{ F_Id: "eglv", F_FullName: "长荣海运", F_EnCode: "EMC", F_Prefix: "EGLV" },
]);
expect(id).toBe("eglv");
});
it("puts 封号 into memo, not other header fields", () => {
const h = extractContainerHeaderFromText(
"柜号:TRHU8524770 提单号:EGLV143661466958 封号:EMCEJJ0635 整柜直送",
);
expect(h.F_BLCopyCode).toBe("EGLV143661466958");
expect(h.F_MemoRemark).toBe("封号:EMCEJJ0635");
expect(h.F_OperationType).toBe(2);
});
});
describe("carrier-aliases catalog", () => {
it("includes common express and airline aliases", () => {
expect(EXPRESS_ALIASES.TNT).toContain("TNT EXPRESS");
expect(EXPRESS_ALIASES["4PX"]).toContain("递四方");
expect(AIRLINE_ALIASES.CA).toContain("中国国际航空");
expect(AIRLINE_ALIASES.FDX).toContain("联邦快递");
expect(SHIPPING_LINE_ALIASES.MAERSK).toContain("马士基");
expect(SHIPPING_LINE_ALIASES.PIL).toContain("太平船务");
});
it("infers air trans mode from airline aliases", () => {
const h = extractContainerHeaderFromText(
"航司 Air China 提单号 999-12345678 空运操作",
);
expect(h.F_TransMode).toBe(1);
});
it("parses loose ETA and bare COSCO from forecast body", () => {
const h = extractContainerHeaderFromText(
"FCIU7089474 提柜 COSCO 40HQ ETA:7.10 卡派拆柜派送",
);
expect(h.F_CabinetType).toBe("40HQ");
expect(h.F_ETA).toMatch(/^\d{4}-07-10$/);
expect(h.shipping_line_hint).toBe("COSCO");
expect(h.F_Dock).toBeUndefined();
});
});