Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-08-18 03:11:02 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-08-18 03:11:02 +0300
commitc95fc172145f1bdbc8d959b6cee31555fc545784 (patch)
tree5aa4940ddefb9bea164905d61916593cc265a05c /spec/finders
parenteda321fc0b96e44e296341f6288dd7f1a27ba93a (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/finders')
-rw-r--r--spec/finders/crm/organizations_finder_spec.rb71
1 files changed, 71 insertions, 0 deletions
diff --git a/spec/finders/crm/organizations_finder_spec.rb b/spec/finders/crm/organizations_finder_spec.rb
index f227fcd3748..c89ac3b1cb5 100644
--- a/spec/finders/crm/organizations_finder_spec.rb
+++ b/spec/finders/crm/organizations_finder_spec.rb
@@ -128,5 +128,76 @@ RSpec.describe Crm::OrganizationsFinder do
end
end
end
+
+ context 'when sorting' do
+ let_it_be(:group) { create(:group, :crm_enabled) }
+
+ let_it_be(:sort_test_a) do
+ create(
+ :organization,
+ group: group,
+ name: "ABC",
+ description: "1"
+ )
+ end
+
+ let_it_be(:sort_test_b) do
+ create(
+ :organization,
+ group: group,
+ name: "DEF",
+ description: "2",
+ default_rate: 10
+ )
+ end
+
+ let_it_be(:sort_test_c) do
+ create(
+ :organization,
+ group: group,
+ name: "GHI",
+ default_rate: 20
+ )
+ end
+
+ before do
+ group.add_developer(user)
+ end
+
+ it 'returns the organiztions sorted by name in ascending order' do
+ finder = described_class.new(user, group: group, sort: { field: 'name', direction: :asc })
+
+ expect(finder.execute).to eq([sort_test_a, sort_test_b, sort_test_c])
+ end
+
+ it 'returns the organizations sorted by description in descending order' do
+ finder = described_class.new(user, group: group, sort: { field: 'description', direction: :desc })
+
+ expect(finder.execute).to eq([sort_test_b, sort_test_a, sort_test_c])
+ end
+
+ it 'returns the contacts sorted by default_rate in ascending order' do
+ finder = described_class.new(user, group: group, sort: { field: 'default_rate', direction: :asc })
+
+ expect(finder.execute).to eq([sort_test_b, sort_test_c, sort_test_a])
+ end
+ end
+ end
+
+ describe '.counts_by_state' do
+ let_it_be(:group) { create(:group, :crm_enabled) }
+ let_it_be(:active_organizations) { create_list(:organization, 3, group: group, state: :active) }
+ let_it_be(:inactive_organizations) { create_list(:organization, 2, group: group, state: :inactive) }
+
+ before do
+ group.add_developer(user)
+ end
+
+ it 'returns correct counts' do
+ counts = described_class.counts_by_state(user, group: group)
+
+ expect(counts["active"]).to eq(3)
+ expect(counts["inactive"]).to eq(2)
+ end
end
end