2019-10-16 05:07:51 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-03-08 19:01:33 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-16 14:09:01 -04:00
|
|
|
RSpec.describe JoinedGroupsFinder do
|
2016-03-08 19:01:33 -05:00
|
|
|
describe '#execute' do
|
|
|
|
let!(:profile_owner) { create(:user) }
|
|
|
|
let!(:profile_visitor) { create(:user) }
|
|
|
|
|
2016-03-21 19:09:20 -04:00
|
|
|
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) }
|
2016-03-08 19:01:33 -05:00
|
|
|
let!(:finder) { described_class.new(profile_owner) }
|
|
|
|
|
2016-03-21 19:09:20 -04:00
|
|
|
context 'without a user' do
|
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
public_group.add_maintainer(profile_owner)
|
2016-03-08 19:01:33 -05:00
|
|
|
end
|
|
|
|
|
2016-03-21 19:09:20 -04:00
|
|
|
it 'only shows public groups from profile owner' do
|
|
|
|
expect(finder.execute).to eq([public_group])
|
|
|
|
end
|
|
|
|
end
|
2016-03-08 19:01:33 -05:00
|
|
|
|
2016-03-21 19:09:20 -04:00
|
|
|
context "with a user" do
|
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
private_group.add_maintainer(profile_owner)
|
|
|
|
internal_group.add_maintainer(profile_owner)
|
|
|
|
public_group.add_maintainer(profile_owner)
|
2016-03-21 19:09:20 -04:00
|
|
|
end
|
2016-03-08 19:01:33 -05:00
|
|
|
|
2016-03-21 19:23:58 -04:00
|
|
|
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
|
2016-03-08 19:01:33 -05:00
|
|
|
end
|
|
|
|
|
2016-03-21 19:23:58 -04:00
|
|
|
context 'if profile visitor is in one of the private group projects' do
|
2016-03-08 19:01:33 -05:00
|
|
|
before do
|
2017-08-02 15:55:11 -04:00
|
|
|
project = create(:project, :private, group: private_group, name: 'B', path: 'B')
|
2022-07-05 14:08:43 -04:00
|
|
|
project.add_member(profile_visitor, Gitlab::Access::DEVELOPER)
|
2016-03-08 19:01:33 -05:00
|
|
|
end
|
|
|
|
|
2016-03-21 19:09:20 -04:00
|
|
|
it 'shows group' do
|
2016-03-21 19:23:58 -04:00
|
|
|
expect(finder.execute(profile_visitor)).to eq([public_group, internal_group, private_group])
|
2016-03-21 19:09:20 -04:00
|
|
|
end
|
2016-03-08 19:01:33 -05:00
|
|
|
end
|
2016-03-17 18:42:46 -04:00
|
|
|
|
|
|
|
context 'external users' do
|
|
|
|
before do
|
2020-08-04 17:09:56 -04:00
|
|
|
profile_visitor.update!(external: true)
|
2016-03-17 18:42:46 -04:00
|
|
|
end
|
|
|
|
|
2016-03-21 19:09:20 -04:00
|
|
|
context 'if not a member' do
|
|
|
|
it "does not show internal groups" do
|
|
|
|
expect(finder.execute(profile_visitor)).to eq([public_group])
|
|
|
|
end
|
2016-03-17 18:42:46 -04:00
|
|
|
end
|
|
|
|
|
2016-03-21 19:09:20 -04:00
|
|
|
context "if authorized" do
|
|
|
|
before do
|
2018-07-11 10:36:08 -04:00
|
|
|
internal_group.add_maintainer(profile_visitor)
|
2016-03-21 19:09:20 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "shows internal groups if authorized" do
|
|
|
|
expect(finder.execute(profile_visitor)).to eq([public_group, internal_group])
|
|
|
|
end
|
2016-03-17 18:42:46 -04:00
|
|
|
end
|
|
|
|
end
|
2016-03-08 19:01:33 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|