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/match-segment-attachments.t...

168 lines
5.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 { buildCcWorkOrderFormValue } from "@/components/CcWorkOrderForm";
import {
extractAttachIdTokens,
matchSegmentAttachments,
} from "@/services/parse/match-segment-attachments";
const MAIL85_FILES = [
"YT2604021091=76件换标走HIA1卡派出库操作指令.xlsx",
"FBA19HW52S0L-76CTN-HIA1-覆盖贴1箱贴2张.pdf",
"X003UHDF7B-304PCS-覆盖贴1箱贴1张.pdf",
];
const MAIL84_FILES = [
"WL103276-SBD1(1).pdf",
"WL103944-WL103940.pdf",
"WL98967-VGT2(1).pdf",
"WL99583-LAX9.pdf",
"WHSU5574991 卡转海.zip",
];
describe("extractAttachIdTokens", () => {
it("picks FBA / YT / FNSKU / WL, not ISO container", () => {
const ids = extractAttachIdTokens(
"柜号 WHSU8127240 原箱号 YT2604021091 FBA19HW52S0L X003UHDF7B WL103276 SBD1",
);
expect(ids).toEqual(
expect.arrayContaining([
"YT2604021091",
"FBA19HW52S0L",
"X003UHDF7B",
"WL103276",
]),
);
expect(ids).not.toContain("WHSU8127240");
});
});
describe("matchSegmentAttachments", () => {
it("mail85: 76件换标段挂 3 个贴标文件;833件历史轮不挂", () => {
const current = matchSegmentAttachments({
segmentText: [
"Dear,",
"原箱号 YT2604021091=FBA199R49LD6-MDW2=76 件操作指令",
"换标后单号: FBA19HW52S0L-2G1MCB6X-HIA1=76 件",
"FNSKU : X003UHDF7B ( 304PCS )",
].join("\n"),
filenames: MAIL85_FILES,
isCurrent: true,
});
expect(current).toEqual(MAIL85_FILES);
const hist = matchSegmentAttachments({
segmentText: [
"Dear,",
"原箱号 YT2604021486=833 件操作指令",
"换标后单号:FBA19DS6CXV4-2G1XD81L-LGB8=87 件",
].join("\n"),
filenames: MAIL85_FILES,
isCurrent: false,
});
expect(hist).toEqual([]);
});
it("mail84: 卡转海/贴标交付段按 WL 唛头挂 PDF + zip;拦截段不挂", () => {
const seaBody = [
"WHSU5574991",
"1.WL104834-2 SCK8 2件",
"2.",
"WL103944-WL103940 2",
"WL99583 LAX9 2",
"WL103276 SBD1 1",
"WL98967 VGT2 2",
"以上货物需要卡转海 麻烦贴标交付,UPS默认一箱贴两张。",
].join("\n");
const sea = matchSegmentAttachments({
segmentText: seaBody,
filenames: MAIL84_FILES,
isCurrent: true,
});
expect(sea).toEqual(
expect.arrayContaining([
"WL103276-SBD1(1).pdf",
"WL103944-WL103940.pdf",
"WL98967-VGT2(1).pdf",
"WL99583-LAX9.pdf",
"WHSU5574991 卡转海.zip",
]),
);
const intercept = matchSegmentAttachments({
segmentText: [
"注意:",
"1.WL103516",
"WL103616",
"以上几票需要拦截 清单中已备注",
"2.",
"WL101167",
"WL92334",
"这2票改自提",
].join("\n"),
filenames: MAIL84_FILES,
isCurrent: false,
});
expect(intercept).toEqual([]);
});
it("skips screenshot and DO; packing xlsx only if named in segment", () => {
const files = [
"3邮箱.pdf",
"WHSU5574991-DO.pdf",
"柜号:MATU2745683卡派资料.xlsx",
"WL103276-SBD1.pdf",
];
const wo = matchSegmentAttachments({
segmentText: "WL103276 SBD1 卡转海 贴标交付",
filenames: files,
isCurrent: true,
});
expect(wo).toEqual(["WL103276-SBD1.pdf"]);
const named = matchSegmentAttachments({
segmentText: "请查收附件 柜号:MATU2745683卡派资料.xlsx",
filenames: files,
isCurrent: true,
});
expect(named).toContain("柜号:MATU2745683卡派资料.xlsx");
expect(named).not.toContain("3邮箱.pdf");
expect(named).not.toContain("WHSU5574991-DO.pdf");
});
it("role-only 卡转海.zip 只挂当前段,不挂历史拦截", () => {
const files = ["WHSU5574991 卡转海.zip"];
const current = matchSegmentAttachments({
segmentText: "以上货物需要卡转海 麻烦贴标交付",
filenames: files,
isCurrent: true,
});
expect(current).toEqual(["WHSU5574991 卡转海.zip"]);
const hist = matchSegmentAttachments({
segmentText: "以上货物需要卡转海 麻烦贴标交付",
filenames: files,
isCurrent: false,
});
expect(hist).toEqual([]);
});
});
describe("buildCcWorkOrderFormValue uses the same rule", () => {
it("mail84 current 卡转海工单 F_AttachFile 含 WL PDF", () => {
const v = buildCcWorkOrderFormValue({
subject: "拆柜清单更新 WHSU5574991",
body: [
"WL103944-WL103940 2",
"WL99583 LAX9 2",
"以上货物需要卡转海 麻烦贴标交付",
].join("\n"),
filenames: MAIL84_FILES,
containerNo: "WHSU5574991",
isCurrent: true,
});
expect(v.F_AttachFile).toContain("WL103944-WL103940.pdf");
expect(v.F_AttachFile).toContain("WL99583-LAX9.pdf");
expect(v.F_AttachFile).toContain("卡转海.zip");
});
});