2020-10-14 18:08:47 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "spec_helper"
|
|
|
|
|
|
|
|
RSpec.describe InviteMembersHelper do
|
2021-04-29 12:09:58 +00:00
|
|
|
include Devise::Test::ControllerHelpers
|
|
|
|
|
2020-10-14 18:08:47 +00:00
|
|
|
let_it_be(:project) { create(:project) }
|
|
|
|
let_it_be(:developer) { create(:user, developer_projects: [project]) }
|
2021-04-19 18:09:09 +00:00
|
|
|
|
2020-10-14 18:08:47 +00:00
|
|
|
let(:owner) { project.owner }
|
|
|
|
|
2021-01-21 00:11:07 +00:00
|
|
|
before do
|
|
|
|
helper.extend(Gitlab::Experimentation::ControllerConcern)
|
|
|
|
end
|
|
|
|
|
2021-08-02 15:08:56 +00:00
|
|
|
describe '#common_invite_modal_dataset' do
|
|
|
|
context 'when member_areas_of_focus is enabled', :experiment do
|
|
|
|
context 'with control experience' do
|
|
|
|
before do
|
|
|
|
stub_experiments(member_areas_of_focus: :control)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has expected attributes' do
|
|
|
|
attributes = {
|
|
|
|
areas_of_focus_options: [],
|
|
|
|
no_selection_areas_of_focus: []
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(helper.common_invite_modal_dataset(project)).to include(attributes)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with candidate experience' do
|
|
|
|
before do
|
|
|
|
stub_experiments(member_areas_of_focus: :candidate)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has expected attributes', :aggregate_failures do
|
|
|
|
output = helper.common_invite_modal_dataset(project)
|
|
|
|
|
|
|
|
expect(output[:no_selection_areas_of_focus]).to eq ['no_selection']
|
|
|
|
expect(Gitlab::Json.parse(output[:areas_of_focus_options]).first['value']).to eq 'Contribute to the codebase'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when member_areas_of_focus is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(member_areas_of_focus: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has expected attributes' do
|
|
|
|
attributes = {
|
|
|
|
id: project.id,
|
|
|
|
name: project.name,
|
|
|
|
default_access_level: Gitlab::Access::GUEST,
|
|
|
|
areas_of_focus_options: [],
|
|
|
|
no_selection_areas_of_focus: []
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(helper.common_invite_modal_dataset(project)).to match(attributes)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-26 15:08:40 +00:00
|
|
|
context 'with project' do
|
|
|
|
before do
|
2021-04-29 12:09:58 +00:00
|
|
|
allow(helper).to receive(:current_user) { owner }
|
2020-10-26 15:08:40 +00:00
|
|
|
assign(:project, project)
|
|
|
|
end
|
2020-10-14 18:08:47 +00:00
|
|
|
|
2021-01-19 18:11:04 +00:00
|
|
|
describe "#can_invite_members_for_project?" do
|
2021-08-19 00:11:16 +00:00
|
|
|
context 'when the user can_admin_project_member' do
|
2021-01-19 18:11:04 +00:00
|
|
|
before do
|
2021-08-19 00:11:16 +00:00
|
|
|
allow(helper).to receive(:can?).with(owner, :admin_project_member, project).and_return(true)
|
2021-01-19 18:11:04 +00:00
|
|
|
end
|
|
|
|
|
2021-08-19 00:11:16 +00:00
|
|
|
it 'returns true', :aggregate_failures do
|
2021-01-19 18:11:04 +00:00
|
|
|
expect(helper.can_invite_members_for_project?(project)).to eq true
|
2021-08-19 00:11:16 +00:00
|
|
|
expect(helper).to have_received(:can?).with(owner, :admin_project_member, project)
|
2021-01-19 18:11:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when feature flag is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(invite_members_group_modal: false)
|
|
|
|
end
|
|
|
|
|
2021-08-19 00:11:16 +00:00
|
|
|
it 'returns false', :aggregate_failures do
|
2021-01-19 18:11:04 +00:00
|
|
|
expect(helper.can_invite_members_for_project?(project)).to eq false
|
2021-08-19 00:11:16 +00:00
|
|
|
expect(helper).not_to have_received(:can?).with(owner, :admin_project_member, project)
|
2021-01-19 18:11:04 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-04-29 12:09:58 +00:00
|
|
|
context 'when the user can not manage project members' do
|
2021-01-19 18:11:04 +00:00
|
|
|
before do
|
2021-08-19 00:11:16 +00:00
|
|
|
expect(helper).to receive(:can?).with(owner, :admin_project_member, project).and_return(false)
|
2021-01-19 18:11:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
expect(helper.can_invite_members_for_project?(project)).to eq false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-10-14 18:08:47 +00:00
|
|
|
end
|
|
|
|
end
|