require "rails_helper"

RSpec.describe Billing::PaymentDescription do
  before { load Rails.root.join("db/seeds/plans.rb") }

  it "etichetta da piano e intervallo Stripe" do
    invoice = double(
      amount_paid: 500,
      metadata: { "plan_slug" => "premium_light", "billing_interval" => "monthly" },
      lines: double(data: [])
    )

    expect(described_class.for_stripe_invoice(invoice)).to eq("Premium Light — €5/mese")
  end

  it "ignora descrizioni di test nel pagamento salvato" do
    payment = Billing::Payment.new(
      description: "Webhook test",
      plan_slug: "premium_light",
      amount_cents: 4000,
      currency: "eur",
      status: "paid",
      club: Club.create!(name: "C", sport: "volleyball", primary_color: "#e53935", secondary_color: "#ffffff")
    )

    expect(payment.display_description).to eq("Premium Light — €40/anno")
  end
end
