diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-22 15:07:28 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-03-22 15:07:28 +0300 |
commit | 4220cf46a314ac1c4d88be13608752bc07bb28fb (patch) | |
tree | 169db13fd06c7622bbcf59b707d57d516f44e299 /spec/services/groups | |
parent | 4c7e34071eceb05a9ce271354c21de7487e4ff84 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/services/groups')
-rw-r--r-- | spec/services/groups/transfer_service_spec.rb | 105 |
1 files changed, 104 insertions, 1 deletions
diff --git a/spec/services/groups/transfer_service_spec.rb b/spec/services/groups/transfer_service_spec.rb index 3a696228382..5bc215b4ac4 100644 --- a/spec/services/groups/transfer_service_spec.rb +++ b/spec/services/groups/transfer_service_spec.rb @@ -17,7 +17,7 @@ RSpec.describe Groups::TransferService, :sidekiq_inline do end let_it_be(:user) { create(:user) } - let_it_be(:new_parent_group) { create(:group, :public) } + let_it_be(:new_parent_group) { create(:group, :public, :crm_enabled) } let!(:group_member) { create(:group_member, :owner, group: group, user: user) } let(:transfer_service) { described_class.new(group, user) } @@ -876,5 +876,108 @@ RSpec.describe Groups::TransferService, :sidekiq_inline do end end end + + context 'crm' do + let(:root_group) { create(:group, :public) } + let(:subgroup) { create(:group, :public, parent: root_group) } + let(:another_subgroup) { create(:group, :public, parent: root_group) } + let(:subsubgroup) { create(:group, :public, parent: subgroup) } + + let(:root_project) { create(:project, group: root_group) } + let(:sub_project) { create(:project, group: subgroup) } + let(:another_project) { create(:project, group: another_subgroup) } + let(:subsub_project) { create(:project, group: subsubgroup) } + + let!(:contacts) { create_list(:contact, 4, group: root_group) } + let!(:organizations) { create_list(:organization, 2, group: root_group) } + + before do + create(:issue_customer_relations_contact, contact: contacts[0], issue: create(:issue, project: root_project)) + create(:issue_customer_relations_contact, contact: contacts[1], issue: create(:issue, project: sub_project)) + create(:issue_customer_relations_contact, contact: contacts[2], issue: create(:issue, project: another_project)) + create(:issue_customer_relations_contact, contact: contacts[3], issue: create(:issue, project: subsub_project)) + root_group.add_owner(user) + end + + context 'moving up' do + let(:group) { subsubgroup } + + it 'retains issue contacts' do + expect { transfer_service.execute(root_group) } + .not_to change { CustomerRelations::IssueContact.count } + end + end + + context 'moving down' do + let(:group) { subgroup } + + it 'retains issue contacts' do + expect { transfer_service.execute(another_subgroup) } + .not_to change { CustomerRelations::IssueContact.count } + end + end + + context 'moving sideways' do + let(:group) { subsubgroup } + + it 'retains issue contacts' do + expect { transfer_service.execute(another_subgroup) } + .not_to change { CustomerRelations::IssueContact.count } + end + end + + context 'moving to new root group' do + let(:group) { root_group } + + before do + new_parent_group.add_owner(user) + end + + it 'moves all crm objects' do + expect { transfer_service.execute(new_parent_group) } + .to change { root_group.contacts.count }.by(-4) + .and change { root_group.organizations.count }.by(-2) + end + + it 'retains issue contacts' do + expect { transfer_service.execute(new_parent_group) } + .not_to change { CustomerRelations::IssueContact.count } + end + end + + context 'moving to a subgroup within a new root group' do + let(:group) { root_group } + let(:subgroup_in_new_parent_group) { create(:group, parent: new_parent_group) } + + context 'with permission on the root group' do + before do + new_parent_group.add_owner(user) + end + + it 'moves all crm objects' do + expect { transfer_service.execute(subgroup_in_new_parent_group) } + .to change { root_group.contacts.count }.by(-4) + .and change { root_group.organizations.count }.by(-2) + end + + it 'retains issue contacts' do + expect { transfer_service.execute(subgroup_in_new_parent_group) } + .not_to change { CustomerRelations::IssueContact.count } + end + end + + context 'with permission on the subgroup' do + before do + subgroup_in_new_parent_group.add_owner(user) + end + + it 'raises error' do + transfer_service.execute(subgroup_in_new_parent_group) + + expect(transfer_service.error).to eq("Transfer failed: Group contains contacts/organizations and you don't have enough permissions to move them to the new root group.") + end + end + end + end end end |