diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
commit | 311b0269b4eb9839fa63f80c8d7a58f32b8138a0 (patch) | |
tree | 07e7870bca8aed6d61fdcc810731c50d2c40af47 /spec/services/members | |
parent | 27909cef6c4170ed9205afa7426b8d3de47cbb0c (diff) |
Add latest changes from gitlab-org/gitlab@14-5-stable-eev14.5.0-rc42
Diffstat (limited to 'spec/services/members')
-rw-r--r-- | spec/services/members/create_service_spec.rb | 104 | ||||
-rw-r--r-- | spec/services/members/invite_service_spec.rb | 5 |
2 files changed, 109 insertions, 0 deletions
diff --git a/spec/services/members/create_service_spec.rb b/spec/services/members/create_service_spec.rb index 2e6e6041fc3..fe866d73215 100644 --- a/spec/services/members/create_service_spec.rb +++ b/spec/services/members/create_service_spec.rb @@ -196,4 +196,108 @@ RSpec.describe Members::CreateService, :aggregate_failures, :clean_gitlab_redis_ end end end + + context 'when assigning tasks to be done' do + let(:additional_params) do + { invite_source: '_invite_source_', tasks_to_be_done: %w(ci code), tasks_project_id: source.id } + end + + before do + stub_experiments(invite_members_for_task: true) + end + + it 'creates 2 task issues', :aggregate_failures do + expect(TasksToBeDone::CreateWorker) + .to receive(:perform_async) + .with(anything, user.id, [member.id]) + .once + .and_call_original + expect { execute_service }.to change { source.issues.count }.by(2) + + expect(source.issues).to all have_attributes( + project: source, + author: user + ) + end + + context 'when passing many user ids' do + before do + stub_licensed_features(multiple_issue_assignees: false) + end + + let(:another_user) { create(:user) } + let(:user_ids) { [member.id, another_user.id].join(',') } + + it 'still creates 2 task issues', :aggregate_failures do + expect(TasksToBeDone::CreateWorker) + .to receive(:perform_async) + .with(anything, user.id, array_including(member.id, another_user.id)) + .once + .and_call_original + expect { execute_service }.to change { source.issues.count }.by(2) + + expect(source.issues).to all have_attributes( + project: source, + author: user + ) + end + end + + context 'when a `tasks_project_id` is missing' do + let(:additional_params) do + { invite_source: '_invite_source_', tasks_to_be_done: %w(ci code) } + end + + it 'does not create task issues' do + expect(TasksToBeDone::CreateWorker).not_to receive(:perform_async) + execute_service + end + end + + context 'when `tasks_to_be_done` are missing' do + let(:additional_params) do + { invite_source: '_invite_source_', tasks_project_id: source.id } + end + + it 'does not create task issues' do + expect(TasksToBeDone::CreateWorker).not_to receive(:perform_async) + execute_service + end + end + + context 'when invalid `tasks_to_be_done` are passed' do + let(:additional_params) do + { invite_source: '_invite_source_', tasks_project_id: source.id, tasks_to_be_done: %w(invalid_task) } + end + + it 'does not create task issues' do + expect(TasksToBeDone::CreateWorker).not_to receive(:perform_async) + execute_service + end + end + + context 'when invalid `tasks_project_id` is passed' do + let(:another_project) { create(:project) } + let(:additional_params) do + { invite_source: '_invite_source_', tasks_project_id: another_project.id, tasks_to_be_done: %w(ci code) } + end + + it 'does not create task issues' do + expect(TasksToBeDone::CreateWorker).not_to receive(:perform_async) + execute_service + end + end + + context 'when a member was already invited' do + let(:user_ids) { create(:project_member, :invited, project: source).invite_email } + let(:additional_params) do + { invite_source: '_invite_source_', tasks_project_id: source.id, tasks_to_be_done: %w(ci code) } + end + + it 'does not create task issues' do + expect(TasksToBeDone::CreateWorker).not_to receive(:perform_async) + execute_service + end + end + end end diff --git a/spec/services/members/invite_service_spec.rb b/spec/services/members/invite_service_spec.rb index 478733e8aa0..7b9ae19f038 100644 --- a/spec/services/members/invite_service_spec.rb +++ b/spec/services/members/invite_service_spec.rb @@ -22,6 +22,11 @@ RSpec.describe Members::InviteService, :aggregate_failures, :clean_gitlab_redis_ end it_behaves_like 'records an onboarding progress action', :user_added + + it 'does not create task issues' do + expect(TasksToBeDone::CreateWorker).not_to receive(:perform_async) + expect { result }.not_to change { project.issues.count } + end end context 'when email belongs to an existing user as a secondary email' do |