require "rails_helper"

RSpec.describe Teams::Entitlements do
  let!(:club) { Club.create!(name: "Club", sport: "volleyball", primary_color: "#e53935", secondary_color: "#ffffff") }
  let!(:team) { club.teams.create!(name: "Team", sport: "volleyball") }

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

  it "limits transmission invites on free plan" do
    user = User.create!(email: "t1@test.com", name: "T1", password: "password123", role: "coach")
    UserTeam.create!(user: user, team: team, role: "member", staff_kind: "transmission")
    ent = described_class.new(team)
    expect { ent.assert_can_invite! }.to raise_error(Teams::EntitlementError, /trasmissione/)
  end
end
