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.

156 lines
4.6 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,
isBusinessRelevantMail,
} from "@/services/parse/classify";
describe("classifyMail — 四类业务", () => {
it("M1 container-only -> WORK_ORDER", () => {
const r = classifyMail({
subject: "TIIU8073522-90022 资料",
body: "请查收",
filenames: [],
});
expect(r.mail_type).toBe("WORK_ORDER");
});
it("M2 TRANSFER(转仓候选,不强制工单)", () => {
const r = classifyMail({
subject: "MATU2745683 转仓通知",
body: "本票转仓",
filenames: ["卡派资料.xlsx"],
});
expect(r.mail_type).toBe("TRANSFER");
});
it("M3 拆柜清单 → WORK_ORDER(渠道「拦截-N件」不算硬拦截)", () => {
const r = classifyMail({
subject: "WHSU5574991 拆柜清单 拦截-209件",
body: "拆柜清单 卡转海 留仓",
filenames: [],
});
expect(r.mail_type).toBe("WORK_ORDER");
expect(r.signals.some((s) => s.matched === "拦截" || s.signal === "工单")).toBe(
false,
);
expect(r.signals.some((s) => s.signal === "拆柜清单")).toBe(true);
});
it("M4 WORK_ORDER(贴标/拍照)", () => {
const r = classifyMail({
subject: "Re: 新增预报 MATU2745683 换标指令",
body: "请换标并贴好拍照",
filenames: ["贴标指令.pdf"],
});
// 主题含新增预报优先;若仅测贴标正文用无预报主题
expect(["WORK_ORDER", "NEW_CONTAINER"]).toContain(r.mail_type);
});
it("贴标正文无预报主题 → WORK_ORDER", () => {
const r = classifyMail({
subject: "操作指令 YT2604021091",
body: "请换标并贴好拍照",
filenames: ["贴标指令.pdf"],
});
expect(r.mail_type).toBe("WORK_ORDER");
});
it("多轮:主题新增预报 + 最新换标 + 历史DO文案 + 数据模版 → WORK_ORDER", () => {
const r = classifyMail({
subject:
"Fw: 转发:新增预报136:新辰泽+WHLC027G597465+WHSU8127240+提拆派",
body: [
"Dear,",
"原箱号YT2604021091=FBA199R49LD6-MDW2=76件操作指令",
"换标后单号:FBA19HW52S0L-HIA1=76件",
"1:覆盖贴FBA标签",
"3:贴好拍照回传",
"------------------ 原始电子邮件 ------------------",
"请查收新增预报:新辰泽+WHSU8127240+提拆派 DO也同步上传至附件",
].join("\n"),
filenames: ["数据模版-新辰泽-WHSU8127240.xlsx"],
});
expect(r.mail_type).toBe("WORK_ORDER");
});
it("不转仓 negative", () => {
const r = classifyMail({
subject: "通知",
body: "本票不转仓,保持原计划",
filenames: [],
});
expect(r.mail_type).not.toBe("TRANSFER");
expect(r.mail_type).not.toBe("WORK_ORDER");
});
it("新增预报优先于贴标工单", () => {
const r = classifyMail({
subject:
"新增预报136:新辰泽+WHLC027G597465+WHSU8127240+洛杉矶+40HQ",
body: "请查收新增预报;另请贴标",
filenames: ["清单.xlsx"],
});
expect(r.mail_type).toBe("NEW_CONTAINER");
});
it("DO 附件 → DO_UPLOAD", () => {
const r = classifyMail({
subject: "WHSU5574991 DO请查收",
body: "",
filenames: ["WHSU5574991-DO.pdf"],
});
expect(r.mail_type).toBe("DO_UPLOAD");
});
it("DO 优先于新增预报(同分冲突取 DO)", () => {
const r = classifyMail({
subject: "新增预报 DO请查收 WHSU8127240",
body: "DO请查收",
filenames: ["柜DO.pdf"],
});
expect(r.mail_type).toBe("DO_UPLOAD");
});
it("正文请查收新增预报(无主题词)→ NEW_CONTAINER", () => {
const r = classifyMail({
subject: "WHSU8127240 资料",
body: "请查收新增预报",
filenames: [],
});
expect(r.mail_type).toBe("NEW_CONTAINER");
expect(r.scores.NEW_CONTAINER).toBeGreaterThanOrEqual(50);
});
});
describe("isBusinessRelevantMail", () => {
it("rejects GitHub / Google noise", () => {
expect(
isBusinessRelevantMail({
subject: "[GitHub] You have used 100% of the included...",
body: "Actions minutes",
filenames: [],
}),
).toBe(false);
});
it("accepts M1 container + 资料", () => {
expect(
isBusinessRelevantMail({
subject: "TIIU8073522-90022 资料",
body: "请查收",
filenames: [],
}),
).toBe(true);
});
it("accepts classified TRANSFER", () => {
expect(
isBusinessRelevantMail({
subject: "MATU2745683 转仓通知",
body: "本票转仓",
filenames: ["卡派资料.xlsx"],
}),
).toBe(true);
});
});