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.

86 lines
2.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 {
buildMailRecord,
collectWorkOrderActions,
extractContainerFromFirstLines,
hasWorkOrderSignal,
} from "@/services/parse/work-order-record";
describe("work-order-record", () => {
it("extracts container from first two lines", () => {
const body = "柜号 WHSU8127240 请处理\n后续说明很长\nMATU2745683 不该取";
expect(extractContainerFromFirstLines(body)).toBe("WHSU8127240");
});
it("collects work order keywords", () => {
expect(
collectWorkOrderActions("转仓通知", "请贴标并拍照,快递单号:SF1234567890", []),
).toEqual(expect.arrayContaining(["转仓", "贴标", "拍照", "快递单号"]));
});
it("excludes 不转仓", () => {
expect(hasWorkOrderSignal("通知", "本票不转仓", [])).toBe(false);
});
it("builds WORK_ORDER table", () => {
const r = buildMailRecord({
mailType: "WORK_ORDER",
subject: "MATU2745683 转仓通知",
body: "新增转仓,请留意\n快递单号:YT998877",
filenames: [],
containerNo: "MATU2745683",
shipments: [
{
row_index: 1,
row_status: "VALID",
F_FBACode: "ABQ2",
F_Remark: "转POC2",
F_CTNS: 1,
},
],
});
expect(r.kind).toBe("WORK_ORDER");
expect(r.work_order_actions).toContain("转仓");
expect(r.table.columns).toContain("原仓");
expect(r.table.rows.length).toBeGreaterThan(0);
expect(r.table.rows[0]["目标仓"]).toBe("POC2");
});
it("builds BL_FORECAST from modules", () => {
const r = buildMailRecord({
mailType: "NEW_CONTAINER",
subject: "新增预报",
body: "",
blModules: {
customer_name: "新辰泽",
bl_no: "WHLC027G597465",
container_no: "WHSU8127240",
port: "洛杉矶",
cabinet_type: "40HQ",
},
shipments: [],
});
expect(r.kind).toBe("BL_FORECAST");
expect(r.modules.bl_no).toBe("WHLC027G597465");
});
it("DO_UPLOAD keeps bl-plus customer_name", () => {
const r = buildMailRecord({
mailType: "DO_UPLOAD",
subject: "智鸿2+WHLC027G597465+WHSU8127240+洛杉矶+40HQ",
body: "请查收新增预报",
blModules: {
customer_name: "智鸿2",
bl_no: "WHLC027G597465",
container_no: "WHSU8127240",
port: "洛杉矶",
cabinet_type: "40HQ",
},
shipments: [],
});
expect(r.modules.customer_name).toBe("智鸿2");
expect(r.kind).toBe("BL_FORECAST");
expect(r.summary).toMatch(/上传DO|智鸿2/);
});
});