summaryrefslogtreecommitdiff
path: root/spec/services/members
diff options
context:
space:
mode:
Diffstat (limited to 'spec/services/members')
-rw-r--r--spec/services/members/create_service_spec.rb74
-rw-r--r--spec/services/members/import_project_team_service_spec.rb91
2 files changed, 163 insertions, 2 deletions
diff --git a/spec/services/members/create_service_spec.rb b/spec/services/members/create_service_spec.rb
index ee5250b5b3d..15ed5c5a33f 100644
--- a/spec/services/members/create_service_spec.rb
+++ b/spec/services/members/create_service_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
RSpec.describe Members::CreateService, :aggregate_failures, :clean_gitlab_redis_cache, :clean_gitlab_redis_shared_state, :sidekiq_inline do
- let_it_be(:source) { create(:project) }
+ let_it_be(:source, reload: true) { create(:project) }
let_it_be(:user) { create(:user) }
let_it_be(:member) { create(:user) }
let_it_be(:user_ids) { member.id.to_s }
@@ -89,7 +89,7 @@ RSpec.describe Members::CreateService, :aggregate_failures, :clean_gitlab_redis_
context 'when invite_source is not passed' do
let(:additional_params) { {} }
- it 'tracks the invite source as unknown' do
+ it 'raises an error' do
expect { execute_service }.to raise_error(ArgumentError, 'No invite source provided.')
expect_no_snowplow_event
@@ -126,4 +126,74 @@ RSpec.describe Members::CreateService, :aggregate_failures, :clean_gitlab_redis_
end
end
end
+
+ context 'when tracking the areas of focus', :snowplow do
+ context 'when areas_of_focus is not passed' do
+ it 'does not track' do
+ execute_service
+
+ expect_no_snowplow_event(category: described_class.name, action: 'area_of_focus')
+ end
+ end
+
+ context 'when 1 areas_of_focus is passed' do
+ let(:additional_params) { { invite_source: '_invite_source_', areas_of_focus: ['no_selection'] } }
+
+ it 'tracks the areas_of_focus from params' do
+ execute_service
+
+ expect_snowplow_event(
+ category: described_class.name,
+ action: 'area_of_focus',
+ label: 'no_selection',
+ property: source.members.last.id.to_s
+ )
+ end
+
+ context 'when passing many user ids' do
+ let(:another_user) { create(:user) }
+ let(:user_ids) { [member.id, another_user.id].join(',') }
+
+ it 'tracks the areas_of_focus from params' do
+ execute_service
+
+ members = source.members.last(2)
+
+ expect_snowplow_event(
+ category: described_class.name,
+ action: 'area_of_focus',
+ label: 'no_selection',
+ property: members.first.id.to_s
+ )
+ expect_snowplow_event(
+ category: described_class.name,
+ action: 'area_of_focus',
+ label: 'no_selection',
+ property: members.last.id.to_s
+ )
+ end
+ end
+ end
+
+ context 'when multiple areas_of_focus are passed' do
+ let(:additional_params) { { invite_source: '_invite_source_', areas_of_focus: %w[no_selection Other] } }
+
+ it 'tracks the areas_of_focus from params' do
+ execute_service
+
+ expect_snowplow_event(
+ category: described_class.name,
+ action: 'area_of_focus',
+ label: 'no_selection',
+ property: source.members.last.id.to_s
+ )
+ expect_snowplow_event(
+ category: described_class.name,
+ action: 'area_of_focus',
+ label: 'Other',
+ property: source.members.last.id.to_s
+ )
+ end
+ end
+ end
end
diff --git a/spec/services/members/import_project_team_service_spec.rb b/spec/services/members/import_project_team_service_spec.rb
new file mode 100644
index 00000000000..96e8db1ba73
--- /dev/null
+++ b/spec/services/members/import_project_team_service_spec.rb
@@ -0,0 +1,91 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Members::ImportProjectTeamService do
+ describe '#execute' do
+ let_it_be(:source_project) { create(:project) }
+ let_it_be(:target_project) { create(:project) }
+ let_it_be(:user) { create(:user) }
+
+ subject { described_class.new(user, { id: target_project_id, project_id: source_project_id }) }
+
+ before_all do
+ source_project.add_guest(user)
+ target_project.add_maintainer(user)
+ end
+
+ context 'when project team members are imported successfully' do
+ let(:source_project_id) { source_project.id }
+ let(:target_project_id) { target_project.id }
+
+ it 'returns true' do
+ expect(subject.execute).to be(true)
+ end
+ end
+
+ context 'when the project team import fails' do
+ context 'when the target project cannot be found' do
+ let(:source_project_id) { source_project.id }
+ let(:target_project_id) { non_existing_record_id }
+
+ it 'returns false' do
+ expect(subject.execute).to be(false)
+ end
+ end
+
+ context 'when the source project cannot be found' do
+ let(:source_project_id) { non_existing_record_id }
+ let(:target_project_id) { target_project.id }
+
+ it 'returns false' do
+ expect(subject.execute).to be(false)
+ end
+ end
+
+ context 'when the user doing the import does not exist' do
+ let(:user) { nil }
+ let(:source_project_id) { source_project.id }
+ let(:target_project_id) { target_project.id }
+
+ it 'returns false' do
+ expect(subject.execute).to be(false)
+ end
+ end
+
+ context 'when the user does not have permission to read the source project members' do
+ let(:user) { create(:user) }
+ let(:source_project_id) { create(:project, :private).id }
+ let(:target_project_id) { target_project.id }
+
+ it 'returns false' do
+ expect(subject.execute).to be(false)
+ end
+ end
+
+ context 'when the user does not have permission to admin the target project' do
+ let(:source_project_id) { source_project.id }
+ let(:target_project_id) { create(:project).id }
+
+ it 'returns false' do
+ expect(subject.execute).to be(false)
+ end
+ end
+
+ context 'when the source and target project are valid but the ProjectTeam#import command fails' do
+ let(:source_project_id) { source_project.id }
+ let(:target_project_id) { target_project.id }
+
+ before do
+ allow_next_instance_of(ProjectTeam) do |project_team|
+ allow(project_team).to receive(:import).and_return(false)
+ end
+ end
+
+ it 'returns false' do
+ expect(subject.execute).to be(false)
+ end
+ end
+ end
+ end
+end