require "rails_helper"

RSpec.describe Billing::Stripe::PriceCatalog do
  before do
    allow(MatchLiveTv).to receive(:stripe_premium_light_yearly_price_id).and_return("price_light_y")
    allow(MatchLiveTv).to receive(:stripe_premium_light_monthly_price_id).and_return("price_light_m")
    allow(MatchLiveTv).to receive(:stripe_premium_full_yearly_price_id).and_return("price_full_y")
    allow(MatchLiveTv).to receive(:stripe_premium_full_monthly_price_id).and_return("price_full_m")
  end

  it "risolve price id per piano e intervallo" do
    expect(described_class.price_id(plan_slug: "premium_light", interval: "yearly")).to eq("price_light_y")
    expect(described_class.price_id(plan_slug: "premium_light", interval: "monthly")).to eq("price_light_m")
    expect(described_class.price_id(plan_slug: "premium_full", interval: "monthly")).to eq("price_full_m")
  end

  it "usa yearly come default" do
    expect(described_class.normalize_interval(nil)).to eq("yearly")
    expect(described_class.price_id(plan_slug: "premium_light", interval: nil)).to eq("price_light_y")
  end

  it "rifiuta intervalli non validi" do
    expect { described_class.normalize_interval("weekly") }.to raise_error(ArgumentError)
  end

  it "elenca intervalli configurati" do
    expect(described_class.available_intervals(plan_slug: "premium_light")).to eq(%w[monthly yearly])
  end
end
