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

organizations_finder_spec.rb « crm « finders « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: f227fcd37486998324325b228a4f9d12d2376b7c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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