import { describe, expect, it } from "vitest";

import {
  getPaymentUrl,
  getStripeClientSecret,
  isEzpayPayment,
} from "../payment_launch";

describe("payment launch helpers", () => {
  it("extracts supported redirect urls from payment params", () => {
    expect(getPaymentUrl({ cashier_url: "https://pay.example/cashier" })).toBe(
      "https://pay.example/cashier",
    );
    expect(getPaymentUrl({ checkoutUrl: "https://pay.example/checkout" })).toBe(
      "https://pay.example/checkout",
    );
    expect(getPaymentUrl({ url: "" })).toBeNull();
  });

  it("detects ezpay provider case-insensitively", () => {
    expect(isEzpayPayment({ provider: "ezpay" })).toBe(true);
    expect(isEzpayPayment({ provider: "EZPAY" })).toBe(true);
    expect(isEzpayPayment({ provider: "stripe" })).toBe(false);
  });

  it("extracts stripe client secrets only for stripe-like providers", () => {
    expect(
      getStripeClientSecret({
        provider: "stripe",
        clientSecret: "pi_secret",
      }),
    ).toBe("pi_secret");
    expect(getStripeClientSecret({ client_secret: "pi_secret_snake" })).toBe(
      "pi_secret_snake",
    );
    expect(
      getStripeClientSecret({
        provider: "ezpay",
        clientSecret: "pi_secret",
      }),
    ).toBeNull();
  });
});
