diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-06-20 14:10:13 +0300 |
commit | 0ea3fcec397b69815975647f5e2aa5fe944a8486 (patch) | |
tree | 7979381b89d26011bcf9bdc989a40fcc2f1ed4ff /spec/finders/crm | |
parent | 72123183a20411a36d607d70b12d57c484394c8e (diff) |
Add latest changes from gitlab-org/gitlab@15-1-stable-eev15.1.0-rc42
Diffstat (limited to 'spec/finders/crm')
-rw-r--r-- | spec/finders/crm/contacts_finder_spec.rb | 96 | ||||
-rw-r--r-- | spec/finders/crm/organizations_finder_spec.rb | 132 |
2 files changed, 218 insertions, 10 deletions
diff --git a/spec/finders/crm/contacts_finder_spec.rb b/spec/finders/crm/contacts_finder_spec.rb index 151af1ad825..dd5274a0574 100644 --- a/spec/finders/crm/contacts_finder_spec.rb +++ b/spec/finders/crm/contacts_finder_spec.rb @@ -26,16 +26,6 @@ RSpec.describe Crm::ContactsFinder do root_group.add_developer(user) end - context 'when feature flag is disabled' do - before do - stub_feature_flags(customer_relations: false) - end - - it 'returns an empty array' do - expect(subject).to be_empty - end - end - context 'when feature flag is enabled' do it 'returns all group contacts' do expect(subject).to match_array([contact_1, contact_2]) @@ -66,5 +56,91 @@ RSpec.describe Crm::ContactsFinder do expect(subject).to be_empty end end + + context 'with search informations' do + let_it_be(:search_test_group) { create(:group, :crm_enabled) } + + let_it_be(:search_test_a) do + create( + :contact, + group: search_test_group, + first_name: "ABC", + last_name: "DEF", + email: "ghi@test.com", + description: "LMNO", + state: "inactive" + ) + end + + let_it_be(:search_test_b) do + create( + :contact, + group: search_test_group, + first_name: "PQR", + last_name: "STU", + email: "vwx@test.com", + description: "YZ", + state: "active" + ) + end + + before do + search_test_group.add_developer(user) + end + + context 'when search term is empty' do + it 'returns all group contacts alphabetically ordered' do + finder = described_class.new(user, group: search_test_group, search: "") + expect(finder.execute).to eq([search_test_a, search_test_b]) + end + end + + context 'when search term is not empty' do + it 'searches for first name ignoring casing' do + finder = described_class.new(user, group: search_test_group, search: "aBc") + expect(finder.execute).to match_array([search_test_a]) + end + + it 'searches for last name ignoring casing' do + finder = described_class.new(user, group: search_test_group, search: "StU") + expect(finder.execute).to match_array([search_test_b]) + end + + it 'searches for email' do + finder = described_class.new(user, group: search_test_group, search: "ghi") + expect(finder.execute).to match_array([search_test_a]) + end + + it 'searches for description ignoring casing' do + finder = described_class.new(user, group: search_test_group, search: "Yz") + expect(finder.execute).to match_array([search_test_b]) + end + + it 'fuzzy searches for email and last name' do + finder = described_class.new(user, group: search_test_group, search: "s") + expect(finder.execute).to match_array([search_test_a, search_test_b]) + end + end + + context 'when searching for contacts state' do + it 'returns only inactive contacts' do + finder = described_class.new(user, group: search_test_group, state: :inactive) + expect(finder.execute).to match_array([search_test_a]) + end + + it 'returns only active contacts' do + finder = described_class.new(user, group: search_test_group, state: :active) + expect(finder.execute).to match_array([search_test_b]) + end + end + + context 'when searching for contacts ids' do + it 'returns the expected contacts' do + finder = described_class.new(user, group: search_test_group, ids: [search_test_b.id]) + + expect(finder.execute).to match_array([search_test_b]) + end + end + end end end diff --git a/spec/finders/crm/organizations_finder_spec.rb b/spec/finders/crm/organizations_finder_spec.rb new file mode 100644 index 00000000000..f227fcd3748 --- /dev/null +++ b/spec/finders/crm/organizations_finder_spec.rb @@ -0,0 +1,132 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Crm::OrganizationsFinder do + let_it_be(:user) { create(:user) } + + describe '#execute' do + subject { described_class.new(user, group: group).execute } + + context 'when customer relations feature is enabled for the group' do + let_it_be(:root_group) { create(:group, :crm_enabled) } + let_it_be(:group) { create(:group, parent: root_group) } + + let_it_be(:organization_1) { create(:organization, group: root_group) } + let_it_be(:organization_2) { create(:organization, group: root_group) } + + context 'when user does not have permissions to see organizations in the group' do + it 'returns an empty array' do + expect(subject).to be_empty + end + end + + context 'when user is member of the root group' do + before do + root_group.add_developer(user) + end + + context 'when feature flag is enabled' do + it 'returns all group organizations' do + expect(subject).to match_array([organization_1, organization_2]) + end + end + end + + context 'when user is member of the sub group' do + before do + group.add_developer(user) + end + + it 'returns an empty array' do + expect(subject).to be_empty + end + end + end + + context 'when customer relations feature is disabled for the group' do + let_it_be(:group) { create(:group) } + let_it_be(:organization) { create(:organization, group: group) } + + before do + group.add_developer(user) + end + + it 'returns an empty array' do + expect(subject).to be_empty + end + end + + context 'with search informations' do + let_it_be(:search_test_group) { create(:group, :crm_enabled) } + + let_it_be(:search_test_a) do + create( + :organization, + group: search_test_group, + name: "DEF", + description: "ghi_st", + state: "inactive" + ) + end + + let_it_be(:search_test_b) do + create( + :organization, + group: search_test_group, + name: "ABC_st", + description: "JKL", + state: "active" + ) + end + + before do + search_test_group.add_developer(user) + end + + context 'when search term is empty' do + it 'returns all group organizations alphabetically ordered' do + finder = described_class.new(user, group: search_test_group, search: "") + expect(finder.execute).to eq([search_test_b, search_test_a]) + end + end + + context 'when search term is not empty' do + it 'searches for name' do + finder = described_class.new(user, group: search_test_group, search: "aBc") + expect(finder.execute).to match_array([search_test_b]) + end + + it 'searches for description' do + finder = described_class.new(user, group: search_test_group, search: "ghI") + expect(finder.execute).to match_array([search_test_a]) + end + + it 'searches for name and description' do + finder = described_class.new(user, group: search_test_group, search: "_st") + expect(finder.execute).to eq([search_test_b, search_test_a]) + end + end + + context 'when searching for organizations state' do + it 'returns only inactive organizations' do + finder = described_class.new(user, group: search_test_group, state: :inactive) + expect(finder.execute).to match_array([search_test_a]) + end + + it 'returns only active organizations' do + finder = described_class.new(user, group: search_test_group, state: :active) + expect(finder.execute).to match_array([search_test_b]) + end + end + + context 'when searching for organizations ids' do + it 'returns the expected organizations' do + finder = described_class.new(user, group: search_test_group, ids: [search_test_a.id]) + + expect(finder.execute).to match_array([search_test_a]) + end + end + end + end +end |