File: shared_groups_finder_spec.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (68 lines) | stat: -rw-r--r-- 2,066 bytes parent folder | download
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
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Namespaces::Groups::SharedGroupsFinder, feature_category: :groups_and_projects do
  let_it_be(:user) { create(:user) }
  let_it_be(:another_user) { create(:user) }
  let_it_be(:current_user) { user }
  let_it_be(:group) { create(:group, :private, owners: user, name: "group") }
  let_it_be(:shared_group) { create(:group, :private, name: "shared group") }
  let_it_be(:other_group) { create(:group, :public, name: "other group") }

  let(:params) { {} }

  subject(:results) { described_class.new(group, current_user, params).execute }

  before do
    create(:group_group_link, shared_group: shared_group, shared_with_group: group)
    create(:group_group_link, shared_group: other_group, shared_with_group: group)
  end

  describe '#execute' do
    context 'when the user has permission to read the group' do
      let(:current_user) { user }

      it 'returns the shared groups which is public or visible to the user' do
        expect(results).to contain_exactly(shared_group, other_group)
      end
    end

    context 'when the user does not have permission to read the group' do
      let(:current_user) { another_user }

      it 'returns no groups' do
        expect(results).to be_empty
      end
    end

    context 'with search filter' do
      let(:params) { { search: "other group" } }

      it 'filters by search term' do
        expect(results).to contain_exactly(other_group)
      end
    end

    context 'with visibility filter' do
      let(:params) { { visibility: 'private' } }

      it 'filters by visibility' do
        expect(results).to contain_exactly(shared_group)
      end
    end

    context 'with min_access_level filter' do
      before_all do
        shared_group.add_owner(current_user)
        other_group.add_owner(current_user)
      end

      let(:params) { { min_access_level: Gitlab::Access::OWNER } }

      it 'filters by minimum access level' do
        expect(results).to contain_exactly(shared_group, other_group)
      end
    end
  end
end