|
|
import { describe, expect, it } from "vitest";
|
|
|
import { classifyMail } from "@/services/parse/classify";
|
|
|
import { extractMailInstructions } from "@/services/parse/split-instructions";
|
|
|
|
|
|
/** 金样:docx/邮件/模板/附件下载_邮件识别 */
|
|
|
const GOLD_SUBJECT =
|
|
|
"\u667a\u9e3f2+WHLC027G597465+WHSU8127240+\u6d1b\u6749\u77f6+40HQ+EDT2026.04-25 ETA2026.05-15\u8239\u540d\u822a\u6b21HMM EMERALD 013E+\u63d0\u62c6\u6d3e";
|
|
|
|
|
|
const GOLD_BODY = [
|
|
|
"\u8bf7\u67e5\u6536\u65b0\u589e\u9884\u62a5\uff1a\u667a\u9e3f2+WHLC027G597465+WHSU8127240+\u6d1b\u6749\u77f6+40HQ",
|
|
|
"DO\u4e5f\u540c\u6b65\u4e0a\u4f20\u81f3\u9644\u4ef6\u8bf7\u6ce8\u610f\u67e5\u6536\uff01",
|
|
|
].join("\n");
|
|
|
|
|
|
const GOLD_FILES = [
|
|
|
"\u6570\u636e\u6a21\u7248.xlsx",
|
|
|
"WHSU8127240-DO.pdf",
|
|
|
"\u667a\u9e3f2+WHLC027G597465+WHSU8127240+\u6d1b\u6749\u77f6+40HQ+EDT2026.04-25 ETA2026.05-15\u8239\u540d\u822a\u6b21HMM EMERALD 013E+\u63d0\u62c6\u6d3e.xlsx",
|
|
|
];
|
|
|
|
|
|
describe("recognize gold — \u9644\u4ef6\u4e0b\u8f7d_\u90ae\u4ef6\u8bc6\u522b", () => {
|
|
|
it("classify: DO primary + NEW_CONTAINER signals", () => {
|
|
|
const r = classifyMail({
|
|
|
subject: GOLD_SUBJECT,
|
|
|
body: GOLD_BODY,
|
|
|
filenames: GOLD_FILES,
|
|
|
});
|
|
|
expect(r.mail_type).toBe("DO_UPLOAD");
|
|
|
expect(r.scores.DO_UPLOAD).toBeGreaterThanOrEqual(40);
|
|
|
expect(r.scores.NEW_CONTAINER).toBeGreaterThanOrEqual(40);
|
|
|
expect(r.signals.some((s) => s.signal === "\u65b0\u589e\u9884\u62a5")).toBe(
|
|
|
true,
|
|
|
);
|
|
|
expect(r.signals.some((s) => /DO/.test(s.signal))).toBe(true);
|
|
|
});
|
|
|
|
|
|
it("body-only \u65b0\u589e\u9884\u62a5 still scores forecast", () => {
|
|
|
const r = classifyMail({
|
|
|
subject: "WHSU8127240",
|
|
|
body: "\u8bf7\u67e5\u6536\u65b0\u589e\u9884\u62a5",
|
|
|
filenames: ["\u6570\u636e\u6a21\u7248.xlsx"],
|
|
|
});
|
|
|
expect(r.scores.NEW_CONTAINER).toBeGreaterThanOrEqual(40);
|
|
|
expect(r.mail_type).toBe("NEW_CONTAINER");
|
|
|
});
|
|
|
|
|
|
it("\u6570\u636e\u6a21\u7248.xlsx alone can lift forecast", () => {
|
|
|
const r = classifyMail({
|
|
|
subject: "WHSU8127240+40HQ+ETA",
|
|
|
body: "\u8bf7\u67e5\u6536",
|
|
|
filenames: ["\u6570\u636e\u6a21\u7248.xlsx"],
|
|
|
});
|
|
|
expect(r.scores.NEW_CONTAINER).toBeGreaterThanOrEqual(40);
|
|
|
expect(r.mail_type).toBe("NEW_CONTAINER");
|
|
|
});
|
|
|
|
|
|
it("split: forecast + do_upload both current", () => {
|
|
|
const units = extractMailInstructions({
|
|
|
subject: GOLD_SUBJECT,
|
|
|
body: GOLD_BODY,
|
|
|
filenames: GOLD_FILES,
|
|
|
});
|
|
|
const kinds = units.map((u) => u.uiKind);
|
|
|
expect(kinds).toContain("forecast");
|
|
|
expect(kinds).toContain("do_upload");
|
|
|
expect(units.filter((u) => u.uiKind === "forecast")[0]?.isCurrent).toBe(
|
|
|
true,
|
|
|
);
|
|
|
expect(units.filter((u) => u.uiKind === "do_upload")[0]?.isCurrent).toBe(
|
|
|
true,
|
|
|
);
|
|
|
});
|
|
|
});
|