import { describe, expect, it } from "vitest";
import { DEFAULT_PRIORITY1_DEMO } from "@/workers/rpa/priority1/demo-input";
import { hashPriority1Input } from "@/modules/priority1/hash";
import { priority1LinesToQuoteItems } from "@/modules/priority1/quote-mapper";
import { validatePriority1QuoteInput } from "@/modules/priority1/validation";

describe("priority1 validation", () => {
  it("校验合法 LTL 提交", () => {
    const parsed = validatePriority1QuoteInput({
      request_id: "req-1",
      customer_id: "CUST_001",
      priority1_input: DEFAULT_PRIORITY1_DEMO,
    });
    expect(parsed.originZip).toBe("10118");
    expect(parsed.phone).toHaveLength(10);
  });

  it("相同输入生成相同哈希", () => {
    const a = hashPriority1Input(DEFAULT_PRIORITY1_DEMO);
    const b = hashPriority1Input({ ...DEFAULT_PRIORITY1_DEMO });
    expect(a).toBe(b);
    expect(a).toHaveLength(32);
  });

  it("承运商列表映射为报价项", () => {
    const items = priority1LinesToQuoteItems([
      {
        rank: 1,
        carrier: "XPO",
        carrierCode: "XPO",
        totalUsd: 400,
        transitDays: 3,
        deliveryDate: null,
        expirationDate: null,
        serviceLevel: "Standard",
        quoteId: 1,
        caboUrl: null,
        source: "api-all",
      },
    ]);
    expect(items[0]?.carrier).toBe("XPO");
    expect(items[0]?.rawTotal).toBe(400);
  });
});
