joined_groups_finder_spec.rb 2.4 KB
Newer Older
1
2
# frozen_string_literal: true

3
4
5
6
7
8
9
require 'spec_helper'

describe JoinedGroupsFinder do
  describe '#execute' do
    let!(:profile_owner)    { create(:user) }
    let!(:profile_visitor)  { create(:user) }

Douwe Maan's avatar
Douwe Maan committed
10
11
12
13
14
15
    let!(:private_group)    { create(:group, :private) }
    let!(:private_group_2)  { create(:group, :private) }
    let!(:internal_group)   { create(:group, :internal) }
    let!(:internal_group_2) { create(:group, :internal) }
    let!(:public_group)     { create(:group, :public) }
    let!(:public_group_2)   { create(:group, :public) }
16
17
    let!(:finder) { described_class.new(profile_owner) }

Douwe Maan's avatar
Douwe Maan committed
18
19
    context 'without a user' do
      before do
20
        public_group.add_maintainer(profile_owner)
21
22
      end

Douwe Maan's avatar
Douwe Maan committed
23
24
25
26
      it 'only shows public groups from profile owner' do
        expect(finder.execute).to eq([public_group])
      end
    end
27

Douwe Maan's avatar
Douwe Maan committed
28
29
    context "with a user" do
      before do
30
31
32
        private_group.add_maintainer(profile_owner)
        internal_group.add_maintainer(profile_owner)
        public_group.add_maintainer(profile_owner)
Douwe Maan's avatar
Douwe Maan committed
33
      end
34

Douwe Maan's avatar
Douwe Maan committed
35
36
37
38
39
40
41
42
      context "when the profile visitor is in the private group" do
        before do
          private_group.add_developer(profile_visitor)
        end

        it 'only shows groups where both users are authorized to see' do
          expect(finder.execute(profile_visitor)).to eq([public_group, internal_group, private_group])
        end
43
44
      end

Douwe Maan's avatar
Douwe Maan committed
45
      context 'if profile visitor is in one of the private group projects' do
46
        before do
47
          project = create(:project, :private, group: private_group, name: 'B', path: 'B')
48
          project.add_user(profile_visitor, Gitlab::Access::DEVELOPER)
49
50
        end

Douwe Maan's avatar
Douwe Maan committed
51
        it 'shows group' do
Douwe Maan's avatar
Douwe Maan committed
52
          expect(finder.execute(profile_visitor)).to eq([public_group, internal_group, private_group])
Douwe Maan's avatar
Douwe Maan committed
53
        end
54
      end
Felipe Artur's avatar
Felipe Artur committed
55
56
57

      context 'external users' do
        before do
Lin Jen-Shin's avatar
Lin Jen-Shin committed
58
          profile_visitor.update(external: true)
Felipe Artur's avatar
Felipe Artur committed
59
60
        end

Douwe Maan's avatar
Douwe Maan committed
61
62
63
64
        context 'if not a member' do
          it "does not show internal groups" do
            expect(finder.execute(profile_visitor)).to eq([public_group])
          end
Felipe Artur's avatar
Felipe Artur committed
65
66
        end

Douwe Maan's avatar
Douwe Maan committed
67
68
        context "if authorized" do
          before do
69
            internal_group.add_maintainer(profile_visitor)
Douwe Maan's avatar
Douwe Maan committed
70
71
72
73
74
          end

          it "shows internal groups if authorized" do
            expect(finder.execute(profile_visitor)).to eq([public_group, internal_group])
          end
Felipe Artur's avatar
Felipe Artur committed
75
76
        end
      end
77
78
79
    end
  end
end