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.
89 lines
2.6 KiB
89 lines
2.6 KiB
import { describe, expect, it } from "vitest";
|
|
import { pickBestSearchCandidate } from "@/lib/axel/pick-candidate";
|
|
import { buildAxelShipmentPayload } from "@/lib/axel/shipment";
|
|
import { parseQuoteCliArgs } from "@/lib/axel/parse-cli-args";
|
|
|
|
describe("parseQuoteCliArgs", () => {
|
|
it("解析必填参数", () => {
|
|
const args = parseQuoteCliArgs([
|
|
"--origin",
|
|
"3131 Western Ave, Seattle, WA",
|
|
"--dest",
|
|
"123 Main St, Los Angeles, CA",
|
|
"--pallets",
|
|
"2",
|
|
"--weight",
|
|
"500",
|
|
]);
|
|
expect(args.origin).toContain("Seattle");
|
|
expect(args.pallets).toBe(2);
|
|
expect(args.weightLb).toBe(500);
|
|
});
|
|
|
|
it("缺少 origin 时抛错", () => {
|
|
expect(() =>
|
|
parseQuoteCliArgs(["--dest", "x", "--pallets", "1", "--weight", "100"]),
|
|
).toThrow(/--origin/);
|
|
});
|
|
});
|
|
|
|
describe("pickBestSearchCandidate", () => {
|
|
it("优先匹配门牌号", () => {
|
|
const picked = pickBestSearchCandidate("3131 Western Ave, Seattle, WA", [
|
|
{
|
|
placeId: "ChIJ-other",
|
|
description: "Western Avenue, Seattle, WA, USA",
|
|
mainText: "Western Avenue",
|
|
},
|
|
{
|
|
placeId: "ChIJ-good",
|
|
description: "3131 Western Avenue, Seattle, WA, USA",
|
|
mainText: "3131 Western Avenue",
|
|
},
|
|
]);
|
|
expect(picked?.placeId).toBe("ChIJ-good");
|
|
});
|
|
|
|
it("门牌号查询不选泛化 route", () => {
|
|
const picked = pickBestSearchCandidate(
|
|
"123 Main St, Los Angeles, CA 90001",
|
|
[
|
|
{
|
|
placeId: "ChIJ-good",
|
|
description: "123 Main Street, Los Angeles, CA, USA",
|
|
mainText: "123 Main Street",
|
|
},
|
|
{
|
|
placeId: "Eh1-route",
|
|
description: "Main St, Los Angeles, CA, USA",
|
|
mainText: "Main St",
|
|
types: ["geocode", "route"],
|
|
},
|
|
],
|
|
);
|
|
expect(picked?.placeId).toBe("ChIJ-good");
|
|
});
|
|
});
|
|
|
|
describe("buildAxelShipmentPayload", () => {
|
|
it("生成 shipment 含 cargo 与 autocompleteResult", () => {
|
|
const shipment = buildAxelShipmentPayload({
|
|
pickup: { placeId: "ChIJ-pickup", street: "1 Main" },
|
|
delivery: { placeId: "ChIJ-delivery", street: "2 Oak" },
|
|
pickupDescription: "1 Main St, Seattle, WA",
|
|
deliveryDescription: "2 Oak Ave, Miami, FL",
|
|
cargo: {
|
|
palletCount: 2,
|
|
weightLb: 500,
|
|
lengthIn: 48,
|
|
widthIn: 40,
|
|
heightIn: 45,
|
|
},
|
|
});
|
|
expect(shipment.pickupDate).toMatch(/T19:00:00\.000Z$/);
|
|
const pickup = shipment.pickupLocation as Record<string, unknown>;
|
|
expect(pickup.autocompleteResult).toBeTruthy();
|
|
expect(Object.keys(shipment.cargo as object)).toHaveLength(1);
|
|
});
|
|
});
|