diff options
Diffstat (limited to 'spec/services/members')
-rw-r--r-- | spec/services/members/create_service_spec.rb | 12 | ||||
-rw-r--r-- | spec/services/members/creator_service_spec.rb | 4 | ||||
-rw-r--r-- | spec/services/members/groups/creator_service_spec.rb | 6 | ||||
-rw-r--r-- | spec/services/members/invite_member_builder_spec.rb | 44 | ||||
-rw-r--r-- | spec/services/members/invite_service_spec.rb | 13 | ||||
-rw-r--r-- | spec/services/members/projects/creator_service_spec.rb | 6 | ||||
-rw-r--r-- | spec/services/members/standard_member_builder_spec.rb | 25 |
7 files changed, 91 insertions, 19 deletions
diff --git a/spec/services/members/create_service_spec.rb b/spec/services/members/create_service_spec.rb index e79e13af769..fe9f3ddc14d 100644 --- a/spec/services/members/create_service_spec.rb +++ b/spec/services/members/create_service_spec.rb @@ -146,12 +146,14 @@ RSpec.describe Members::CreateService, :aggregate_failures, :clean_gitlab_redis_ end context 'when passing an existing invite user id' do - let(:user_id) { create(:project_member, :invited, project: source).invite_email } + let(:invited_member) { create(:project_member, :guest, :invited, project: source) } + let(:user_id) { invited_member.invite_email } + let(:access_level) { ProjectMember::MAINTAINER } - it 'does not add a member' do - expect(execute_service[:status]).to eq(:error) - expect(execute_service[:message]).to eq("The member's email address has already been taken") - expect(OnboardingProgress.completed?(source.namespace, :user_added)).to be(false) + it 'allows already invited members to be re-invited by email and updates the member access' do + expect(execute_service[:status]).to eq(:success) + expect(invited_member.reset.access_level).to eq ProjectMember::MAINTAINER + expect(OnboardingProgress.completed?(source.namespace, :user_added)).to be(true) end end diff --git a/spec/services/members/creator_service_spec.rb b/spec/services/members/creator_service_spec.rb index 8b1df2ab86d..ad4c649086b 100644 --- a/spec/services/members/creator_service_spec.rb +++ b/spec/services/members/creator_service_spec.rb @@ -11,7 +11,7 @@ RSpec.describe Members::CreatorService do describe '#execute' do it 'raises error for new member on authorization check implementation' do expect do - described_class.add_user(source, user, :maintainer, current_user: current_user) + described_class.add_member(source, user, :maintainer, current_user: current_user) end.to raise_error(NotImplementedError) end @@ -19,7 +19,7 @@ RSpec.describe Members::CreatorService do source.add_developer(user) expect do - described_class.add_user(source, user, :maintainer, current_user: current_user) + described_class.add_member(source, user, :maintainer, current_user: current_user) end.to raise_error(NotImplementedError) end end diff --git a/spec/services/members/groups/creator_service_spec.rb b/spec/services/members/groups/creator_service_spec.rb index b80b7998eac..4130fbd44fa 100644 --- a/spec/services/members/groups/creator_service_spec.rb +++ b/spec/services/members/groups/creator_service_spec.rb @@ -14,13 +14,13 @@ RSpec.describe Members::Groups::CreatorService do it_behaves_like 'owner management' - describe '.add_users' do + describe '.add_members' do it_behaves_like 'bulk member creation' do let_it_be(:member_type) { GroupMember } end end - describe '.add_user' do + describe '.add_member' do it_behaves_like 'member creation' do let_it_be(:member_type) { GroupMember } end @@ -30,7 +30,7 @@ RSpec.describe Members::Groups::CreatorService do expect(AuthorizedProjectsWorker).to receive(:bulk_perform_and_wait).once 1.upto(3) do - described_class.add_user(source, user, :maintainer) + described_class.add_member(source, user, :maintainer) end end end diff --git a/spec/services/members/invite_member_builder_spec.rb b/spec/services/members/invite_member_builder_spec.rb new file mode 100644 index 00000000000..52de65364c4 --- /dev/null +++ b/spec/services/members/invite_member_builder_spec.rb @@ -0,0 +1,44 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Members::InviteMemberBuilder do + let_it_be(:source) { create(:group) } + let_it_be(:existing_member) { create(:group_member) } + + let(:existing_members) { { existing_member.user.id => existing_member } } + + describe '#execute' do + context 'when user record found by email' do + it 'returns member from existing members hash' do + expect(described_class.new(source, existing_member.user.email, existing_members).execute).to eq existing_member + end + + it 'builds a new member' do + user = create(:user) + + member = described_class.new(source, user.email, existing_members).execute + + expect(member).to be_new_record + expect(member.user).to eq user + end + end + end + + context 'when no existing users found by the email' do + it 'finds existing member' do + member = create(:group_member, :invited, source: source) + + expect(described_class.new(source, member.invite_email, existing_members).execute).to eq member + end + + it 'builds a new member' do + email = 'test@example.com' + + member = described_class.new(source, email, existing_members).execute + + expect(member).to be_new_record + expect(member.invite_email).to eq email + end + end +end diff --git a/spec/services/members/invite_service_spec.rb b/spec/services/members/invite_service_spec.rb index a948041479b..7a1512970b4 100644 --- a/spec/services/members/invite_service_spec.rb +++ b/spec/services/members/invite_service_spec.rb @@ -353,15 +353,16 @@ RSpec.describe Members::InviteService, :aggregate_failures, :clean_gitlab_redis_ context 'when member already exists' do context 'with email' do - let!(:invited_member) { create(:project_member, :invited, project: project) } - let(:params) { { email: "#{invited_member.invite_email},#{project_user.email}" } } + let!(:invited_member) { create(:project_member, :guest, :invited, project: project) } + let(:params) do + { email: "#{invited_member.invite_email},#{project_user.email}", access_level: ProjectMember::MAINTAINER } + end - it 'adds new email and returns an error for the already invited email' do + it 'adds new email and allows already invited members to be re-invited by email and updates the member access' do expect_to_create_members(count: 1) - expect(result[:status]).to eq(:error) - expect(result[:message][invited_member.invite_email]) - .to eq("The member's email address has already been taken") + expect(result[:status]).to eq(:success) expect(project.users).to include project_user + expect(invited_member.reset.access_level).to eq ProjectMember::MAINTAINER end end diff --git a/spec/services/members/projects/creator_service_spec.rb b/spec/services/members/projects/creator_service_spec.rb index 38955122ab0..8304bee2ffc 100644 --- a/spec/services/members/projects/creator_service_spec.rb +++ b/spec/services/members/projects/creator_service_spec.rb @@ -14,13 +14,13 @@ RSpec.describe Members::Projects::CreatorService do it_behaves_like 'owner management' - describe '.add_users' do + describe '.add_members' do it_behaves_like 'bulk member creation' do let_it_be(:member_type) { ProjectMember } end end - describe '.add_user' do + describe '.add_member' do it_behaves_like 'member creation' do let_it_be(:member_type) { ProjectMember } end @@ -30,7 +30,7 @@ RSpec.describe Members::Projects::CreatorService do expect(AuthorizedProjectUpdate::UserRefreshFromReplicaWorker).to receive(:bulk_perform_in).once 1.upto(3) do - described_class.add_user(source, user, :maintainer) + described_class.add_member(source, user, :maintainer) end end end diff --git a/spec/services/members/standard_member_builder_spec.rb b/spec/services/members/standard_member_builder_spec.rb new file mode 100644 index 00000000000..16daff53d31 --- /dev/null +++ b/spec/services/members/standard_member_builder_spec.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Members::StandardMemberBuilder do + let_it_be(:source) { create(:group) } + let_it_be(:existing_member) { create(:group_member) } + + let(:existing_members) { { existing_member.user.id => existing_member } } + + describe '#execute' do + it 'returns member from existing members hash' do + expect(described_class.new(source, existing_member.user, existing_members).execute).to eq existing_member + end + + it 'builds a new member' do + user = create(:user) + + member = described_class.new(source, user, existing_members).execute + + expect(member).to be_new_record + expect(member.user).to eq user + end + end +end |