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) }
|
2021-11-18 10:10:19 -05:00
|
|
|
let_it_be(:group) { create(:group, projects: [project]) }
|
2020-10-14 14:08:47 -04:00
|
|
|
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
|
|
|
|
|
2021-08-02 11:08:56 -04:00
|
|
|
describe '#common_invite_modal_dataset' do
|
2021-12-02 19:11:20 -05:00
|
|
|
it 'has expected common attributes' do
|
|
|
|
attributes = {
|
|
|
|
id: project.id,
|
|
|
|
name: project.name,
|
|
|
|
default_access_level: Gitlab::Access::GUEST
|
|
|
|
}
|
|
|
|
|
|
|
|
expect(helper.common_invite_modal_dataset(project)).to include(attributes)
|
2021-10-25 08:10:19 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'tasks_to_be_done' do
|
2021-11-18 10:10:19 -05:00
|
|
|
using RSpec::Parameterized::TableSyntax
|
2021-10-25 08:10:19 -04:00
|
|
|
|
2021-11-18 10:10:19 -05:00
|
|
|
subject(:output) { helper.common_invite_modal_dataset(source) }
|
2021-10-25 08:10:19 -04:00
|
|
|
|
2021-11-18 10:10:19 -05:00
|
|
|
shared_examples_for 'including the tasks to be done attributes' do
|
|
|
|
it 'includes the tasks to be done attributes when expected' do
|
|
|
|
if expected?
|
2021-10-25 08:10:19 -04:00
|
|
|
expect(output[:tasks_to_be_done_options]).to eq(
|
|
|
|
[
|
|
|
|
{ value: :code, text: 'Create/import code into a project (repository)' },
|
|
|
|
{ value: :ci, text: 'Set up CI/CD pipelines to build, test, deploy, and monitor code' },
|
|
|
|
{ value: :issues, text: 'Create/import issues (tickets) to collaborate on ideas and plan work' }
|
|
|
|
].to_json
|
|
|
|
)
|
|
|
|
expect(output[:projects]).to eq(
|
|
|
|
[{ id: project.id, title: project.title }].to_json
|
|
|
|
)
|
|
|
|
expect(output[:new_project_path]).to eq(
|
2021-11-18 10:10:19 -05:00
|
|
|
source.is_a?(Project) ? '' : new_project_path(namespace_id: group.id)
|
2021-10-25 08:10:19 -04:00
|
|
|
)
|
2021-11-18 10:10:19 -05:00
|
|
|
else
|
|
|
|
expect(output[:tasks_to_be_done_options]).to be_nil
|
|
|
|
expect(output[:projects]).to be_nil
|
|
|
|
expect(output[:new_project_path]).to be_nil
|
2021-10-25 08:10:19 -04:00
|
|
|
end
|
|
|
|
end
|
2021-11-18 10:10:19 -05:00
|
|
|
end
|
2021-10-25 08:10:19 -04:00
|
|
|
|
2021-11-23 19:12:33 -05:00
|
|
|
context 'inviting members for tasks' do
|
|
|
|
where(:open_modal_param_present?, :logged_in?, :expected?) do
|
|
|
|
true | true | true
|
|
|
|
true | false | false
|
|
|
|
false | true | false
|
|
|
|
false | false | false
|
2021-11-18 10:10:19 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:current_user).and_return(developer) if logged_in?
|
|
|
|
allow(helper).to receive(:params).and_return({ open_modal: 'invite_members_for_task' }) if open_modal_param_present?
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the source is a project' do
|
|
|
|
let_it_be(:source) { project }
|
|
|
|
|
|
|
|
it_behaves_like 'including the tasks to be done attributes'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the source is a group' do
|
|
|
|
let_it_be(:source) { group }
|
|
|
|
|
|
|
|
it_behaves_like 'including the tasks to be done attributes'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'the invite_for_help_continuous_onboarding experiment' do
|
|
|
|
where(:invite_for_help_continuous_onboarding?, :logged_in?, :expected?) do
|
|
|
|
true | true | true
|
|
|
|
true | false | false
|
|
|
|
false | true | false
|
|
|
|
false | false | false
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:current_user).and_return(developer) if logged_in?
|
|
|
|
stub_experiments(invite_for_help_continuous_onboarding: :candidate) if invite_for_help_continuous_onboarding?
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the source is a project' do
|
|
|
|
let_it_be(:source) { project }
|
|
|
|
|
|
|
|
it_behaves_like 'including the tasks to be done attributes'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the source is a group' do
|
|
|
|
let_it_be(:source) { group }
|
|
|
|
|
|
|
|
let(:expected?) { false }
|
|
|
|
|
|
|
|
it_behaves_like 'including the tasks to be done attributes'
|
2021-10-25 08:10:19 -04:00
|
|
|
end
|
|
|
|
end
|
2021-08-02 11:08:56 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
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-08-18 20:11:16 -04:00
|
|
|
context 'when the user can_admin_project_member' do
|
2021-01-19 13:11:04 -05:00
|
|
|
before do
|
2021-08-18 20:11:16 -04:00
|
|
|
allow(helper).to receive(:can?).with(owner, :admin_project_member, project).and_return(true)
|
2021-01-19 13:11:04 -05:00
|
|
|
end
|
|
|
|
|
2021-08-18 20:11:16 -04:00
|
|
|
it 'returns true', :aggregate_failures do
|
2021-01-19 13:11:04 -05:00
|
|
|
expect(helper.can_invite_members_for_project?(project)).to eq true
|
2021-08-18 20:11:16 -04:00
|
|
|
expect(helper).to have_received(:can?).with(owner, :admin_project_member, project)
|
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
|
|
|
|
|
2021-08-18 20:11:16 -04:00
|
|
|
it 'returns false', :aggregate_failures do
|
2021-01-19 13:11:04 -05:00
|
|
|
expect(helper.can_invite_members_for_project?(project)).to eq false
|
2021-08-18 20:11:16 -04:00
|
|
|
expect(helper).not_to have_received(:can?).with(owner, :admin_project_member, project)
|
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-08-18 20:11:16 -04:00
|
|
|
expect(helper).to receive(:can?).with(owner, :admin_project_member, project).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-14 14:08:47 -04:00
|
|
|
end
|
|
|
|
end
|