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

import {
  getDefaultPaymentAnalyticsContext,
  parsePaymentAnalyticsContext,
} from "../payment_analytics_context";

describe("payment analytics context", () => {
  it("keeps supported payment entry and reason values", () => {
    expect(
      parsePaymentAnalyticsContext({
        entryPoint: "chat_unlock",
        triggerReason: "ad_landing",
        subscriptionType: "topup",
      }),
    ).toEqual({
      entryPoint: "chat_unlock",
      triggerReason: "ad_landing",
    });

    expect(
      parsePaymentAnalyticsContext({
        entryPoint: "chat_offer_banner",
        triggerReason: "commercial_offer",
        subscriptionType: "vip",
      }),
    ).toEqual({
      entryPoint: "chat_offer_banner",
      triggerReason: "commercial_offer",
    });
  });

  it("falls back independently for invalid query values", () => {
    expect(
      parsePaymentAnalyticsContext({
        entryPoint: "unsafe-entry",
        triggerReason: "unsafe-reason",
        subscriptionType: "topup",
      }),
    ).toEqual(getDefaultPaymentAnalyticsContext("topup"));

    expect(
      parsePaymentAnalyticsContext({
        entryPoint: "profile",
        triggerReason: null,
        subscriptionType: "vip",
      }),
    ).toEqual({ entryPoint: "profile", triggerReason: "vip_cta" });
  });
});
