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/scripts/patch-packing-note-tests.ts

58 lines
1.9 KiB

import fs from "fs";
// packing-list test
{
const path = "tests/unit/packing-list.test.ts";
let src = fs.readFileSync(path, "utf8");
if (!src.includes("skips \u6ce8\u610f instruction footer")) {
const insert = `
it("skips \u6ce8\u610f instruction footer in \u667a\u9e3f gold xlsx", async () => {
const fs = await import("fs/promises");
const path = await import("path");
const file = path.join(
process.cwd(),
"docx",
"\u90ae\u4ef6",
"\u6a21\u677f",
"\u9644\u4ef6\u4e0b\u8f7d_\u90ae\u4ef6\u8bc6\u522b",
"\u667a\u9e3f2+WHLC027G597465+WHSU8127240+\u6d1b\u6749\u77f6+40HQ+EDT2026.04-25 ETA2026.05-15\u8239\u540d\u822a\u6b21HMM EMERALD 013E+\u63d0\u62c6\u6d3e.xlsx",
);
const buf = await fs.readFile(file);
const parsed = await parsePackingListBuffer(buf, { enableIsoCheck: false });
expect(parsed.errorCode).toBeUndefined();
expect(parsed.shipments.length).toBe(1);
expect(parsed.shipments[0].row_status).toBe("VALID");
expect(parsed.shipments[0].F_Transporter).toBe("\u5b58\u4ed3");
expect(parsed.shipments[0].F_CTNS).toBe(1041);
expect(
parsed.shipments.every((s) => !String(s.F_FBACode || "").includes("\u6ce8\u610f")),
).toBe(true);
});
`;
src = src.replace(/\n\}\);\s*$/, `${insert}\n});\n`);
fs.writeFileSync(path, src);
console.log("packing test added");
}
}
// channel-map test
{
const path = "tests/unit/channel-map.test.ts";
let src = fs.readFileSync(path, "utf8");
if (!src.includes("ignores Truck inside instruction note")) {
src = src.replace(
/\n\}\);\s*$/,
`
it("ignores Truck inside instruction note", () => {
const note =
"\u6ce8\u610f\uff1a1.ups\u548cfedex\u7684\u4ef6... \u5982UPS/FEDEX/USPS/Truck \u6216 \u5361\u6d3e";
expect(mapChannel(note).transporter).toBe("");
});
});
`,
);
fs.writeFileSync(path, src);
console.log("channel test added");
}
}