diff options
Diffstat (limited to 'spec/helpers/invite_members_helper_spec.rb')
-rw-r--r-- | spec/helpers/invite_members_helper_spec.rb | 107 |
1 files changed, 9 insertions, 98 deletions
diff --git a/spec/helpers/invite_members_helper_spec.rb b/spec/helpers/invite_members_helper_spec.rb index 109b1fc4441..122f2339b28 100644 --- a/spec/helpers/invite_members_helper_spec.rb +++ b/spec/helpers/invite_members_helper_spec.rb @@ -3,6 +3,8 @@ require "spec_helper" RSpec.describe InviteMembersHelper do + include Devise::Test::ControllerHelpers + let_it_be(:project) { create(:project) } let_it_be(:developer) { create(:user, developer_projects: [project]) } @@ -12,35 +14,21 @@ RSpec.describe InviteMembersHelper do helper.extend(Gitlab::Experimentation::ControllerConcern) end - describe '#show_invite_members_track_event' do - it 'shows values when can directly invite members' do - allow(helper).to receive(:directly_invite_members?).and_return(true) - - expect(helper.show_invite_members_track_event).to eq 'show_invite_members' - end - - it 'shows values when can indirectly invite members' do - allow(helper).to receive(:directly_invite_members?).and_return(false) - allow(helper).to receive(:indirectly_invite_members?).and_return(true) - - expect(helper.show_invite_members_track_event).to eq 'show_invite_members_version_b' - end - end - context 'with project' do before do + allow(helper).to receive(:current_user) { owner } assign(:project, project) end describe "#can_invite_members_for_project?" do - context 'when the user can_import_members' do + context 'when the user can_manage_project_members' do before do - allow(helper).to receive(:can_import_members?).and_return(true) + allow(helper).to receive(:can_manage_project_members?).and_return(true) end it 'returns true' do expect(helper.can_invite_members_for_project?(project)).to eq true - expect(helper).to have_received(:can_import_members?) + expect(helper).to have_received(:can_manage_project_members?) end context 'when feature flag is disabled' do @@ -50,14 +38,14 @@ RSpec.describe InviteMembersHelper do it 'returns false' do expect(helper.can_invite_members_for_project?(project)).to eq false - expect(helper).not_to have_received(:can_import_members?) + expect(helper).not_to have_received(:can_manage_project_members?) end end end - context 'when the user can not invite members' do + context 'when the user can not manage project members' do before do - expect(helper).to receive(:can_import_members?).and_return(false) + expect(helper).to receive(:can_manage_project_members?).and_return(false) end it 'returns false' do @@ -87,88 +75,11 @@ RSpec.describe InviteMembersHelper do end end end - - describe "#indirectly_invite_members?" do - context 'when a user is a developer' do - before do - allow(helper).to receive(:current_user) { developer } - end - - it 'returns false' do - allow(helper).to receive(:experiment_enabled?).with(:invite_members_version_b) { false } - - expect(helper.indirectly_invite_members?).to eq false - end - - it 'returns true' do - allow(helper).to receive(:experiment_enabled?).with(:invite_members_version_b) { true } - - expect(helper.indirectly_invite_members?).to eq true - end - end - - context 'when a user is an owner' do - before do - allow(helper).to receive(:current_user) { owner } - end - - it 'returns false' do - allow(helper).to receive(:experiment_enabled?).with(:invite_members_version_b) { true } - - expect(helper.indirectly_invite_members?).to eq false - end - end - end end context 'with group' do let_it_be(:group) { create(:group) } - describe "#can_invite_members_for_group?" do - include Devise::Test::ControllerHelpers - - let_it_be(:user) { create(:user) } - - before do - sign_in(user) - allow(helper).to receive(:current_user) { user } - end - - context 'when the user can_import_members' do - before do - allow(helper).to receive(:can?).with(user, :admin_group_member, group).and_return(true) - end - - it 'returns true' do - expect(helper.can_invite_members_for_group?(group)).to eq true - expect(helper).to have_received(:can?).with(user, :admin_group_member, group) - end - - context 'when feature flag is disabled' do - before do - stub_feature_flags(invite_members_group_modal: false) - end - - it 'returns false' do - stub_feature_flags(invite_members_group_modal: false) - - expect(helper.can_invite_members_for_group?(group)).to eq false - expect(helper).not_to have_received(:can?) - end - end - end - - context 'when the user can not invite members' do - before do - expect(helper).to receive(:can?).with(user, :admin_group_member, group).and_return(false) - end - - it 'returns false' do - expect(helper.can_invite_members_for_group?(group)).to eq false - end - end - end - describe "#invite_group_members?" do context 'when the user is an owner' do before do |