import { describe, expect, it } from "vitest";
import { RpaError } from "@/modules/rpa/errors";
import {
  formatQuoteErrorMessage,
  resolveQuoteFailureCode,
  resolveQuoteFailureMessage,
} from "@/modules/quote/quote-error-messages";

describe("quote-error-messages", () => {
  it("RpaError 保留细分 error_code", () => {
    expect(
      resolveQuoteFailureCode(
        new RpaError("ADDRESS_SUGGESTION_NOT_FOUND", "未找到地址"),
      ),
    ).toBe("ADDRESS_SUGGESTION_NOT_FOUND");
  });

  it("RpaError 使用原始 message 作为用户文案", () => {
    const msg = resolveQuoteFailureMessage(
      new RpaError("STRUCT_CHANGE", "login 页且无 Mothership 凭据"),
      "QUOTE_ENTRY_UNAVAILABLE",
    );
    expect(msg).toBe("login 页且无 Mothership 凭据");
  });

  it("formatQuoteErrorMessage 优先 storedMessage", () => {
    expect(
      formatQuoteErrorMessage("QUOTE_UNAVAILABLE", "自定义原因"),
    ).toBe("自定义原因");
  });

  it("formatQuoteErrorMessage 按 code 回退", () => {
    expect(formatQuoteErrorMessage("QUOTE_TIMEOUT")).toContain("420 秒");
  });
});
