import { describe, expect, it } from "vitest";
import { DUAL_ADDRESS_PATCH_INIT } from "@/workers/rpa/inject/dual-address-patch-init";
import { isDualAddressPatchEnabled } from "@/lib/rpa/env";

describe("dual-address-patch", () => {
  it("init script 包含 vault API 标识", () => {
    expect(DUAL_ADDRESS_PATCH_INIT).toContain("__rpaDualAddressPatchInstalled");
    expect(DUAL_ADDRESS_PATCH_INIT).toContain("__rpaDualAddressApi");
    expect(DUAL_ADDRESS_PATCH_INIT).toContain("preservePickup");
  });

  it("显式 RPA_DUAL_ADDRESS_PATCH=true 时启用 patch", () => {
    const prev = process.env.RPA_DUAL_ADDRESS_PATCH;
    const prevQuote = process.env.RPA_QUOTE_MODE;
    process.env.RPA_DUAL_ADDRESS_PATCH = "true";
    process.env.RPA_QUOTE_MODE = "widget";
    expect(isDualAddressPatchEnabled()).toBe(true);
    process.env.RPA_DUAL_ADDRESS_PATCH = "false";
    expect(isDualAddressPatchEnabled()).toBe(false);
    process.env.RPA_DUAL_ADDRESS_PATCH = prev ?? "";
    process.env.RPA_QUOTE_MODE = prevQuote ?? "";
  });
});
