diff options
Diffstat (limited to 'spec/services/members')
-rw-r--r-- | spec/services/members/create_service_spec.rb | 49 | ||||
-rw-r--r-- | spec/services/members/destroy_service_spec.rb | 31 |
2 files changed, 80 insertions, 0 deletions
diff --git a/spec/services/members/create_service_spec.rb b/spec/services/members/create_service_spec.rb index 25696ca209e..756e1cf403c 100644 --- a/spec/services/members/create_service_spec.rb +++ b/spec/services/members/create_service_spec.rb @@ -110,12 +110,61 @@ RSpec.describe Members::CreateService, :aggregate_failures, :clean_gitlab_redis_ expect(execute_service[:status]).to eq(:success) end end + + context 'when only one user fails validations' do + let_it_be(:source) { create(:project, group: create(:group)) } + let(:user_id) { [member.id, user_invited_by_id.id] } + + before do + # validations will fail because we try to invite them to the project as a guest + source.group.add_developer(member) + end + + it 'triggers the members added event' do + expect(Gitlab::EventStore) + .to receive(:publish) + .with(an_instance_of(Members::MembersAddedEvent)) + .and_call_original + + expect(execute_service[:status]).to eq(:error) + expect(execute_service[:message]) + .to include 'Access level should be greater than or equal to Developer inherited membership from group' + expect(source.users).not_to include(member) + expect(source.users).to include(user_invited_by_id) + end + end + + context 'when all users fail validations' do + let_it_be(:source) { create(:project, group: create(:group)) } + let(:user_id) { [member.id, user_invited_by_id.id] } + + before do + # validations will fail because we try to invite them to the project as a guest + source.group.add_developer(member) + source.group.add_developer(user_invited_by_id) + end + + it 'does not trigger the members added event' do + expect(Gitlab::EventStore) + .not_to receive(:publish) + .with(an_instance_of(Members::MembersAddedEvent)) + + expect(execute_service[:status]).to eq(:error) + expect(execute_service[:message]) + .to include 'Access level should be greater than or equal to Developer inherited membership from group' + expect(source.users).not_to include(member, user_invited_by_id) + end + end end context 'when passing no user ids' do let(:user_id) { '' } it 'does not add a member' do + expect(Gitlab::EventStore) + .not_to receive(:publish) + .with(an_instance_of(Members::MembersAddedEvent)) + expect(execute_service[:status]).to eq(:error) expect(execute_service[:message]).to be_present expect(source.users).not_to include member diff --git a/spec/services/members/destroy_service_spec.rb b/spec/services/members/destroy_service_spec.rb index 9f0daba3327..8559c02be57 100644 --- a/spec/services/members/destroy_service_spec.rb +++ b/spec/services/members/destroy_service_spec.rb @@ -95,6 +95,37 @@ RSpec.describe Members::DestroyService do end end + context 'With ExclusiveLeaseHelpers' do + let(:service_object) { described_class.new(current_user) } + let!(:member) { group_project.add_developer(member_user) } + + subject(:destroy_member) { service_object.execute(member, **opts) } + + before do + group_project.add_maintainer(current_user) + + allow(service_object).to receive(:in_lock) do |_, &block| + block.call if lock_obtained + end + end + + context 'when lock is obtained' do + let(:lock_obtained) { true } + + it 'destroys the membership' do + expect { destroy_member }.to change { group_project.members.count }.by(-1) + end + end + + context 'when the lock can not be obtained' do + let(:lock_obtained) { false } + + it 'does not destroy the membership' do + expect { destroy_member }.not_to change { group_project.members.count } + end + end + end + context 'with a member with access' do before do group_project.update_attribute(:visibility_level, Gitlab::VisibilityLevel::PRIVATE) |