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.
chajia/__tests__/lib/frontend/mothership-logged-in-quote-...

283 lines
7.0 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 {
buildQuoteRequestBodyFromLoggedIn,
resolveLoggedInPalletCount,
} from "@/lib/frontend/mothership-logged-in-quote-body";
import type { MothershipLoggedInShipmentPayload } from "@/components/mothership/mothership-logged-in-shipment-form";
import type { MothershipAddressCandidate } from "@/lib/frontend/types";
const pickup: MothershipAddressCandidate = {
option_id: "p1",
display_label: "A, Fairhope, AL",
formatted_address: "A, Fairhope, AL",
street: "A",
city: "Fairhope",
state: "AL",
zip: "36532",
};
const delivery: MothershipAddressCandidate = {
option_id: "d1",
display_label: "B, Brea, CA",
formatted_address: "B, Brea, CA",
street: "B",
city: "Brea",
state: "CA",
zip: "92821",
};
function payload(
cargo: MothershipLoggedInShipmentPayload["cargo"],
): MothershipLoggedInShipmentPayload {
return {
pickupQuery: pickup.display_label,
deliveryQuery: delivery.display_label,
pickupConfirmed: pickup,
deliveryConfirmed: delivery,
pickupAccessorials: [],
deliveryAccessorials: [],
readyDate: "2026-07-16",
readyTime: "12:00 PM",
timezone: "GMT+8",
cargo,
};
}
describe("mothership-logged-in-quote-body", () => {
it("多行托盘 quantity 合计", () => {
expect(
resolveLoggedInPalletCount(
payload([
{
cargoType: "pallet",
quantity: 2,
weightLb: 250,
lengthIn: 48,
widthIn: 48,
heightIn: 48,
},
{
cargoType: "pallet",
quantity: 3,
weightLb: 100,
lengthIn: 40,
widthIn: 40,
heightIn: 40,
},
]),
),
).toBe(5);
});
it("混装:纸箱不计入 pallet_count(仅托盘行)", () => {
// 对齐用户样例:托盘 2+5+6+3=16,纸箱另计
expect(
resolveLoggedInPalletCount(
payload([
{
cargoType: "carton",
quantity: 4,
weightLb: 12,
lengthIn: 2,
widthIn: 2,
heightIn: 3,
},
{
cargoType: "pallet",
quantity: 2,
weightLb: 6,
lengthIn: 12,
widthIn: 12,
heightIn: 12,
},
{
cargoType: "pallet",
quantity: 5,
weightLb: 31,
lengthIn: 31,
widthIn: 31,
heightIn: 31,
},
{
cargoType: "carton",
quantity: 22,
weightLb: 24,
lengthIn: 23,
widthIn: 23,
heightIn: 23,
},
{
cargoType: "carton",
quantity: 33,
weightLb: 33,
lengthIn: 33,
widthIn: 33,
heightIn: 33,
},
{
cargoType: "pallet",
quantity: 6,
weightLb: 56,
lengthIn: 55,
widthIn: 55,
heightIn: 55,
},
{
cargoType: "pallet",
quantity: 3,
weightLb: 66,
lengthIn: 66,
widthIn: 66,
heightIn: 66,
},
{
cargoType: "carton",
quantity: 32,
weightLb: 69,
lengthIn: 21,
widthIn: 12,
heightIn: 55,
},
]),
),
).toBe(16);
});
it("询价体重取首行单件重量", () => {
const body = buildQuoteRequestBodyFromLoggedIn(
payload([
{
cargoType: "pallet",
quantity: 2,
weightLb: 250,
lengthIn: 48,
widthIn: 48,
heightIn: 48,
},
]),
"CUST_001",
);
expect(body.weight.value).toBe(250);
expect(body.pallet_count).toBe(2);
});
it("透传附加服务与可提货时间", () => {
const base = payload([
{
cargoType: "pallet",
quantity: 1,
weightLb: 100,
lengthIn: 48,
widthIn: 40,
heightIn: 48,
},
]);
const body = buildQuoteRequestBodyFromLoggedIn(
{
...base,
pickupAccessorials: ["liftgate", "residential"],
deliveryAccessorials: ["appointment"],
readyDate: "2026-07-16",
readyTime: "3:00 PM",
},
"CUST_001",
);
expect(body.pickup_accessorials).toEqual(["liftgate", "residential"]);
expect(body.delivery_accessorials).toEqual(["appointment"]);
expect(body.ready_date).toBe("2026-07-16");
expect(body.ready_time).toBe("3:00 PM");
});
it("透传多行 cargo_lines", () => {
const body = buildQuoteRequestBodyFromLoggedIn(
payload([
{
cargoType: "pallet",
quantity: 2,
weightLb: 250,
lengthIn: 48,
widthIn: 40,
heightIn: 48,
},
{
cargoType: "box",
quantity: 2,
weightLb: 250,
lengthIn: 50,
widthIn: 40,
heightIn: 50,
},
]),
"CUST_001",
);
expect(body.cargo_lines).toHaveLength(2);
expect(body.cargo_lines?.[1]?.cargo_type).toBe("box");
// 仅合计托盘行:pallet×2,box 不计入
expect(body.pallet_count).toBe(2);
});
it("透传二级 details 字段", () => {
const body = buildQuoteRequestBodyFromLoggedIn(
payload([
{
cargoType: "pallet",
quantity: 1,
weightLb: 100,
lengthIn: 48,
widthIn: 40,
heightIn: 48,
},
]),
"CUST_001",
{
pickup: {
companyName: "Pickup Co",
suite: "Ste 100",
contactFirst: "A",
contactLast: "B",
contactEmail: "pickup@example.com",
contactPhone: "5551112222",
reference: "REF-1",
notes: "note",
opensAt: "8:00 AM",
closesAt: "5:00 PM",
accessorials: [],
},
delivery: {
companyName: "Delivery Co",
suite: "",
contactFirst: "C",
contactLast: "D",
contactEmail: "delivery@example.com",
contactPhone: "5553334444",
reference: "",
notes: "",
opensAt: "9:00 AM",
closesAt: "6:00 PM",
accessorials: [],
},
requestDeliveryAppointment: true,
fbaNumber: "FBA-123",
fbaPoNumber: "PO-456",
cargo: [
{
pieceCountType: "Pieces",
pieceCountQty: 10,
description: "General freight",
nmfc: "",
hazmat: false,
alcohol: false,
tobacco: false,
},
],
},
);
expect(body.mothership_details?.pickup.company_name).toBe("Pickup Co");
expect(body.mothership_details?.delivery.contact_email).toBe(
"delivery@example.com",
);
expect(body.mothership_details?.request_delivery_appointment).toBe(true);
expect(body.mothership_details?.cargo?.[0]?.piece_count_type).toBe("Pieces");
});
});