require "rails_helper"

RSpec.describe Billing::AdminCompedSubscription do
  let(:admin) { AdminAccount.create!(username: "ops", password: "secret123") }
  let(:club) { Club.create!(name: "Sponsor FC", sport: "volleyball", primary_color: "#e53935", secondary_color: "#ffffff") }

  before do
    load Rails.root.join("db/seeds/plans.rb")
    Billing::AssignPlan.call(club: club, plan_slug: "free")
  end

  it "concede premium full senza stripe" do
    described_class.grant(
      club: club,
      plan_slug: "premium_full",
      reason: "Sponsor stagione 2026",
      admin: admin
    )

    sub = club.reload.subscription
    expect(sub.plan.slug).to eq("premium_full")
    expect(sub.admin_comped?).to be true
    expect(sub.admin_comped_reason).to eq("Sponsor stagione 2026")
    expect(sub.admin_comped_by).to eq(admin)
  end

  it "revoca omaggio e torna a free" do
    described_class.grant(club: club, plan_slug: "premium_light", reason: "Promo", admin: admin)

    described_class.revoke(club: club, admin: admin)

    sub = club.reload.subscription
    expect(sub.plan.slug).to eq("free")
    expect(sub.admin_comped?).to be false
  end
end
