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/packing-fill-rules.test.ts

88 lines
2.2 KiB

import { describe, expect, it } from "vitest";
import {
PACKING_FILL_TIPS,
validatePackingFill,
} from "@/services/parse/packing-fill-rules";
describe("packing-fill-rules", () => {
it("exposes customer tips", () => {
expect(PACKING_FILL_TIPS.length).toBeGreaterThanOrEqual(6);
expect(PACKING_FILL_TIPS.some((t) => /UPS|FEDEX/i.test(t))).toBe(true);
});
it("requires channel / ctns / cbm / weight", () => {
const r = validatePackingFill({
channelRaw: "",
transporter: "",
warehouseId: "",
ctns: 0,
cbm: null,
weight: null,
address: "",
shipmentId: "",
fbaId: "",
referenceId: "",
});
expect(r.invalid_reasons).toEqual(
expect.arrayContaining(["渠道缺失", "件数无效", "总体积缺失", "毛重缺失"]),
);
expect(r.shipmentId).toBe("/");
});
it("strips courier name from warehouse id", () => {
const r = validatePackingFill({
channelRaw: "UPS",
transporter: "UPS",
warehouseId: "ups",
ctns: 2,
cbm: 1,
weight: 10,
address: "",
shipmentId: "/",
fbaId: "",
referenceId: "",
});
expect(r.warehouseId).toBe("");
expect(r.warnings.some((w) => /仓库ID勿填快递名/.test(w))).toBe(true);
expect(r.invalid_reasons).toEqual([]);
});
it("rejects multi FBA id in one cell", () => {
const r = validatePackingFill({
channelRaw: "卡派",
transporter: "TRUCK",
warehouseId: "LAS1",
ctns: 1,
cbm: 0.5,
weight: 10,
address: "",
shipmentId: "/",
fbaId: "FBA111 FBA222",
referenceId: "A1;B2",
});
expect(r.invalid_reasons).toEqual(
expect.arrayContaining([
"FBA ID一格只能写一个",
"Amazon reference ID一格只能写一个",
]),
);
});
it("amazon warehouse optional when empty (客户:没有不用填)", () => {
const r = validatePackingFill({
channelRaw: "存仓",
transporter: "存仓",
warehouseId: "",
ctns: 10,
cbm: 1,
weight: 20,
address: "",
shipmentId: "/",
fbaId: "",
referenceId: "",
});
expect(r.invalid_reasons).not.toContain("仓库ID缺失");
expect(r.invalid_reasons).toEqual([]);
});
});