2020-10-14 14:08:47 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "spec_helper"
|
|
|
|
|
|
|
|
RSpec.describe InviteMembersHelper do
|
2021-04-29 08:09:58 -04:00
|
|
|
include Devise::Test::ControllerHelpers
|
|
|
|
|
2020-10-14 14:08:47 -04:00
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
let_it_be(:developer) { create(:user, developer_projects: [project]) }
|
2021-04-19 14:09:09 -04:00
|
|
|
|
2020-10-14 14:08:47 -04:00
|
|
|
let(:owner) { project.owner }
|
|
|
|
|
2021-01-20 19:11:07 -05:00
|
|
|
before do
|
|
|
|
helper.extend(Gitlab::Experimentation::ControllerConcern)
|
|
|
|
end
|
|
|
|
|
2020-10-26 11:08:40 -04:00
|
|
|
context 'with project' do
|
|
|
|
before do
|
2021-04-29 08:09:58 -04:00
|
|
|
allow(helper).to receive(:current_user) { owner }
|
2020-10-26 11:08:40 -04:00
|
|
|
assign(:project, project)
|
|
|
|
end
|
2020-10-14 14:08:47 -04:00
|
|
|
|
2021-01-19 13:11:04 -05:00
|
|
|
describe "#can_invite_members_for_project?" do
|
2021-04-29 08:09:58 -04:00
|
|
|
context 'when the user can_manage_project_members' do
|
2021-01-19 13:11:04 -05:00
|
|
|
before do
|
2021-04-29 08:09:58 -04:00
|
|
|
allow(helper).to receive(:can_manage_project_members?).and_return(true)
|
2021-01-19 13:11:04 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
expect(helper.can_invite_members_for_project?(project)).to eq true
|
2021-04-29 08:09:58 -04:00
|
|
|
expect(helper).to have_received(:can_manage_project_members?)
|
2021-01-19 13:11:04 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when feature flag is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(invite_members_group_modal: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(helper.can_invite_members_for_project?(project)).to eq false
|
2021-04-29 08:09:58 -04:00
|
|
|
expect(helper).not_to have_received(:can_manage_project_members?)
|
2021-01-19 13:11:04 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-29 08:09:58 -04:00
|
|
|
context 'when the user can not manage project members' do
|
2021-01-19 13:11:04 -05:00
|
|
|
before do
|
2021-04-29 08:09:58 -04:00
|
|
|
expect(helper).to receive(:can_manage_project_members?).and_return(false)
|
2021-01-19 13:11:04 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(helper.can_invite_members_for_project?(project)).to eq false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-26 11:08:40 -04:00
|
|
|
describe "#directly_invite_members?" do
|
|
|
|
context 'when the user is an owner' do
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:current_user) { owner }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
expect(helper.directly_invite_members?).to eq true
|
|
|
|
end
|
2020-10-14 14:08:47 -04:00
|
|
|
end
|
|
|
|
|
2020-10-26 11:08:40 -04:00
|
|
|
context 'when the user is a developer' do
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:current_user) { developer }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(helper.directly_invite_members?).to eq false
|
|
|
|
end
|
2020-10-14 14:08:47 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-26 11:08:40 -04:00
|
|
|
context 'with group' do
|
|
|
|
let_it_be(:group) { create(:group) }
|
2020-10-14 14:08:47 -04:00
|
|
|
|
2020-10-26 11:08:40 -04:00
|
|
|
describe "#invite_group_members?" do
|
|
|
|
context 'when the user is an owner' do
|
|
|
|
before do
|
|
|
|
group.add_owner(owner)
|
|
|
|
allow(helper).to receive(:current_user) { owner }
|
|
|
|
end
|
2020-10-14 14:08:47 -04:00
|
|
|
|
2020-10-26 11:08:40 -04:00
|
|
|
it 'returns false' do
|
|
|
|
allow(helper).to receive(:experiment_enabled?).with(:invite_members_empty_group_version_a) { false }
|
2020-10-14 14:08:47 -04:00
|
|
|
|
2020-10-26 11:08:40 -04:00
|
|
|
expect(helper.invite_group_members?(group)).to eq false
|
|
|
|
end
|
2020-10-14 14:08:47 -04:00
|
|
|
|
2020-10-26 11:08:40 -04:00
|
|
|
it 'returns true' do
|
|
|
|
allow(helper).to receive(:experiment_enabled?).with(:invite_members_empty_group_version_a) { true }
|
2020-10-14 14:08:47 -04:00
|
|
|
|
2020-10-26 11:08:40 -04:00
|
|
|
expect(helper.invite_group_members?(group)).to eq true
|
|
|
|
end
|
2020-10-14 14:08:47 -04:00
|
|
|
end
|
|
|
|
|
2020-10-26 11:08:40 -04:00
|
|
|
context 'when the user is a developer' do
|
|
|
|
before do
|
|
|
|
group.add_developer(developer)
|
|
|
|
allow(helper).to receive(:current_user) { developer }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
allow(helper).to receive(:experiment_enabled?).with(:invite_members_empty_group_version_a) { true }
|
2020-10-14 14:08:47 -04:00
|
|
|
|
2020-10-26 11:08:40 -04:00
|
|
|
expect(helper.invite_group_members?(group)).to eq false
|
|
|
|
end
|
2020-10-14 14:08:47 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|