|
|
import { describe, expect, it, vi } from "vitest";
|
|
|
|
|
|
vi.mock("@/lib/prisma", () => ({ prisma: {} }));
|
|
|
import {
|
|
|
buildQueryLogCargoCopy,
|
|
|
buildQueryLogDeliveryCopy,
|
|
|
buildQueryLogFullCopy,
|
|
|
buildQueryLogPickupCopy,
|
|
|
buildQueryLogQuotesCopy,
|
|
|
formatQueryLogQuoteLine,
|
|
|
preferredAdminAddress,
|
|
|
} from "@/lib/frontend/query-log-copy";
|
|
|
import { extractQuotedList } from "@/modules/quote/query-log";
|
|
|
|
|
|
const sample = {
|
|
|
quote_id: "QTE_001",
|
|
|
customer_id: "CUST_001",
|
|
|
pickup_selected: "50 South West Temple, Salt Lake City, UT 84101, USA",
|
|
|
pickup_customer: "50 S W Temple",
|
|
|
delivery_selected: "555 Market St, San Francisco, CA 94105, USA",
|
|
|
delivery_customer: "555 Market",
|
|
|
cargo_summary: "3 托 · 707.00 lb · 48×40×48 in · 普通货物",
|
|
|
quoted_carrier: "XPO",
|
|
|
quoted_total: 128.5,
|
|
|
quotes: [
|
|
|
{
|
|
|
carrier: "XPO",
|
|
|
service_level: "standard",
|
|
|
rate_option: "lowest",
|
|
|
final_total: 128.5,
|
|
|
},
|
|
|
{
|
|
|
carrier: "ABF",
|
|
|
service_level: "standard",
|
|
|
rate_option: "fastest",
|
|
|
final_total: 210,
|
|
|
},
|
|
|
],
|
|
|
};
|
|
|
|
|
|
describe("query-log-copy", () => {
|
|
|
it("优先使用联想确认地址", () => {
|
|
|
expect(preferredAdminAddress("联想地址", "客户地址")).toBe("联想地址");
|
|
|
expect(preferredAdminAddress("—", "客户地址")).toBe("客户地址");
|
|
|
expect(preferredAdminAddress("", "")).toBe("");
|
|
|
});
|
|
|
|
|
|
it("分别生成提货/派送/货物复制文本", () => {
|
|
|
expect(buildQueryLogPickupCopy(sample)).toBe(sample.pickup_selected);
|
|
|
expect(buildQueryLogDeliveryCopy(sample)).toBe(sample.delivery_selected);
|
|
|
expect(buildQueryLogCargoCopy(sample)).toBe(sample.cargo_summary);
|
|
|
});
|
|
|
|
|
|
it("整单复制包含地址与货物参数", () => {
|
|
|
const text = buildQueryLogFullCopy(sample);
|
|
|
expect(text).toContain("报价单号:QTE_001");
|
|
|
expect(text).toContain(`提货地址:${sample.pickup_selected}`);
|
|
|
expect(text).toContain(`派送地址:${sample.delivery_selected}`);
|
|
|
expect(text).toContain(`货物参数:${sample.cargo_summary}`);
|
|
|
expect(text).toContain("报价列表(2 档)");
|
|
|
expect(text).toContain("XPO");
|
|
|
expect(text).toContain("ABF");
|
|
|
expect(text).toContain("USD 128.50");
|
|
|
expect(text).toContain("USD 210.00");
|
|
|
});
|
|
|
|
|
|
it("报价行包含承运商、档位与金额", () => {
|
|
|
expect(formatQueryLogQuoteLine(sample.quotes[0]!)).toMatch(
|
|
|
/XPO · 标准\/最低价格 · USD 128.50/,
|
|
|
);
|
|
|
expect(buildQueryLogQuotesCopy(sample.quotes).split("\n")).toHaveLength(2);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe("extractQuotedList", () => {
|
|
|
it("返回全部承运商档位,不只第一档", () => {
|
|
|
const list = extractQuotedList([
|
|
|
{
|
|
|
service_level: "standard",
|
|
|
rate_option: "lowest",
|
|
|
carrier: "XPO",
|
|
|
final_total: 128.5,
|
|
|
},
|
|
|
{
|
|
|
service_level: "standard",
|
|
|
rate_option: "fastest",
|
|
|
carrier: "ABF",
|
|
|
final_total: 210,
|
|
|
},
|
|
|
]);
|
|
|
expect(list).toHaveLength(2);
|
|
|
expect(list.map((q) => q.carrier).sort()).toEqual(["ABF", "XPO"]);
|
|
|
});
|
|
|
});
|