debian-mirror-gitlab/spec/helpers/invite_members_helper_spec.rb

108 lines
3.2 KiB
Ruby
Raw Normal View History

2021-01-03 14:25:43 +05:30
# frozen_string_literal: true
require "spec_helper"
RSpec.describe InviteMembersHelper do
2021-06-08 01:23:25 +05:30
include Devise::Test::ControllerHelpers
2021-01-03 14:25:43 +05:30
let_it_be(:project) { create(:project) }
let_it_be(:developer) { create(:user, developer_projects: [project]) }
2021-04-29 21:17:54 +05:30
2021-01-03 14:25:43 +05:30
let(:owner) { project.owner }
2021-03-11 19:13:27 +05:30
before do
helper.extend(Gitlab::Experimentation::ControllerConcern)
end
2021-10-27 15:23:28 +05:30
describe '#common_invite_modal_dataset' do
context 'when member_areas_of_focus is enabled', :experiment do
context 'with control experience' do
2021-03-11 19:13:27 +05:30
before do
2021-10-27 15:23:28 +05:30
stub_experiments(member_areas_of_focus: :control)
2021-03-11 19:13:27 +05:30
end
2021-10-27 15:23:28 +05:30
it 'has expected attributes' do
attributes = {
areas_of_focus_options: [],
no_selection_areas_of_focus: []
}
2021-03-11 19:13:27 +05:30
2021-10-27 15:23:28 +05:30
expect(helper.common_invite_modal_dataset(project)).to include(attributes)
2021-03-11 19:13:27 +05:30
end
end
2021-10-27 15:23:28 +05:30
context 'with candidate experience' do
2021-03-11 19:13:27 +05:30
before do
2021-10-27 15:23:28 +05:30
stub_experiments(member_areas_of_focus: :candidate)
2021-03-11 19:13:27 +05:30
end
2021-10-27 15:23:28 +05:30
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'
2021-03-11 19:13:27 +05:30
end
end
end
2021-10-27 15:23:28 +05:30
context 'when member_areas_of_focus is disabled' do
before do
stub_feature_flags(member_areas_of_focus: false)
2021-01-03 14:25:43 +05:30
end
2021-10-27 15:23:28 +05:30
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: []
}
2021-01-29 00:20:46 +05:30
2021-10-27 15:23:28 +05:30
expect(helper.common_invite_modal_dataset(project)).to match(attributes)
2021-01-03 14:25:43 +05:30
end
end
end
2021-10-27 15:23:28 +05:30
context 'with project' do
before do
allow(helper).to receive(:current_user) { owner }
assign(:project, project)
end
2021-01-03 14:25:43 +05:30
2021-10-27 15:23:28 +05:30
describe "#can_invite_members_for_project?" do
context 'when the user can_admin_project_member' do
2021-01-29 00:20:46 +05:30
before do
2021-10-27 15:23:28 +05:30
allow(helper).to receive(:can?).with(owner, :admin_project_member, project).and_return(true)
2021-01-29 00:20:46 +05:30
end
2021-01-03 14:25:43 +05:30
2021-10-27 15:23:28 +05:30
it 'returns true', :aggregate_failures do
expect(helper.can_invite_members_for_project?(project)).to eq true
expect(helper).to have_received(:can?).with(owner, :admin_project_member, project)
2021-01-29 00:20:46 +05:30
end
2021-01-03 14:25:43 +05:30
2021-10-27 15:23:28 +05:30
context 'when feature flag is disabled' do
before do
stub_feature_flags(invite_members_group_modal: false)
end
2021-01-03 14:25:43 +05:30
2021-10-27 15:23:28 +05:30
it 'returns false', :aggregate_failures do
expect(helper.can_invite_members_for_project?(project)).to eq false
expect(helper).not_to have_received(:can?).with(owner, :admin_project_member, project)
end
2021-01-29 00:20:46 +05:30
end
2021-01-03 14:25:43 +05:30
end
2021-10-27 15:23:28 +05:30
context 'when the user can not manage project members' do
2021-01-29 00:20:46 +05:30
before do
2021-10-27 15:23:28 +05:30
expect(helper).to receive(:can?).with(owner, :admin_project_member, project).and_return(false)
2021-01-29 00:20:46 +05:30
end
it 'returns false' do
2021-10-27 15:23:28 +05:30
expect(helper.can_invite_members_for_project?(project)).to eq false
2021-01-29 00:20:46 +05:30
end
2021-01-03 14:25:43 +05:30
end
end
end
end