require "rails_helper"

describe BroadcastPolicy do
  subject { described_class }

  let(:user_context) { build(:user_context, user: user, account: user.primary_account) }

  context "for an associate" do
    let(:user) { create(:user, :associate, admin: false) }

    permissions :index? do
      it { is_expected.to permit(user_context, subject) }
    end

    permissions :create? do
      it { is_expected.not_to permit(user_context, subject) }
    end

    permissions :show? do
      it { is_expected.to permit(user_context, subject) }
    end

    permissions :destroy? do
      it { is_expected.not_to permit(user_context, subject) }
    end
  end

  context "for a project manager" do
    let(:user) { create(:user, :manager, admin: false) }

    permissions :index? do
      it { is_expected.to permit(user_context, subject) }
    end

    permissions :create? do
      it { is_expected.to permit(user_context, subject) }
    end

    permissions :show? do
      it { is_expected.to permit(user_context, subject) }
    end
    
    permissions :destroy? do
      it { is_expected.to permit(user_context, subject) }
    end
  end
  
  context "for account managers" do
    let(:user) { create(:user, :account_manager, admin: false) }

    permissions :index? do
      it { is_expected.to permit(user_context, subject) }
    end

    permissions :create? do
      it { is_expected.to permit(user_context, subject) }
    end
    
    permissions :show? do
      it { is_expected.to permit(user_context, subject) }
    end
    
    permissions :destroy? do
      it { is_expected.to permit(user_context, subject) }
    end
  end
end
