From f9da8786f9421281e390d921333f8ff4c9941354 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Fri, 15 Dec 2023 15:13:59 +0000 Subject: Add latest changes from gitlab-org/gitlab@master --- spec/finders/groups_finder_spec.rb | 32 +++++++++ spec/finders/organizations/groups_finder_spec.rb | 84 ------------------------ 2 files changed, 32 insertions(+), 84 deletions(-) delete mode 100644 spec/finders/organizations/groups_finder_spec.rb (limited to 'spec/finders') diff --git a/spec/finders/groups_finder_spec.rb b/spec/finders/groups_finder_spec.rb index f20c03c9658..5d69988a761 100644 --- a/spec/finders/groups_finder_spec.rb +++ b/spec/finders/groups_finder_spec.rb @@ -274,6 +274,38 @@ RSpec.describe GroupsFinder, feature_category: :groups_and_projects do end end + context 'with organization' do + let_it_be(:organization_user) { create(:organization_user) } + let_it_be(:organization) { organization_user.organization } + let_it_be(:user) { organization_user.user } + let_it_be(:public_group) { create(:group, name: 'public-group', organization: organization) } + let_it_be(:outside_organization_group) { create(:group) } + let_it_be(:private_group) { create(:group, :private, name: 'private-group', organization: organization) } + let_it_be(:no_access_group_in_org) { create(:group, :private, name: 'no-access', organization: organization) } + + let(:current_user) { user } + let(:params) { { organization: organization } } + let(:finder) { described_class.new(current_user, params) } + + subject(:result) { finder.execute.to_a } + + before_all do + private_group.add_developer(user) + public_group.add_developer(user) + outside_organization_group.add_developer(user) + end + + context 'when user is only authorized to read the public group' do + let(:current_user) { create(:user) } + + it { is_expected.to contain_exactly(public_group) } + end + + it 'return all groups inside the organization' do + expect(result).to contain_exactly(public_group, private_group) + end + end + context 'with include_ancestors' do let_it_be(:user) { create(:user) } diff --git a/spec/finders/organizations/groups_finder_spec.rb b/spec/finders/organizations/groups_finder_spec.rb deleted file mode 100644 index 08c5604149b..00000000000 --- a/spec/finders/organizations/groups_finder_spec.rb +++ /dev/null @@ -1,84 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Organizations::GroupsFinder, feature_category: :cell do - let_it_be(:organization_user) { create(:organization_user) } - let_it_be(:organization) { organization_user.organization } - let_it_be(:user) { organization_user.user } - let_it_be(:public_group) { create(:group, name: 'public-group', organization: organization) } - let_it_be(:other_group) { create(:group, name: 'other-group', organization: organization) } - let_it_be(:outside_organization_group) { create(:group) } - let_it_be(:private_group) do - create(:group, :private, name: 'private-group', organization: organization) - end - - let_it_be(:no_access_group_in_org) do - create(:group, :private, name: 'no-access', organization: organization) - end - - let(:current_user) { user } - let(:params) { {} } - let(:finder) { described_class.new(organization: organization, current_user: current_user, params: params) } - - before_all do - private_group.add_developer(user) - public_group.add_developer(user) - other_group.add_developer(user) - outside_organization_group.add_developer(user) - end - - subject(:result) { finder.execute.to_a } - - describe '#execute' do - context 'when user is not authorized to read the organization' do - let(:current_user) { create(:user) } - - it { is_expected.to be_empty } - end - - context 'when organization is nil' do - let(:organization) { nil } - - it { is_expected.to be_empty } - end - - context 'when user is authorized to read the organization' do - it 'return all accessible groups' do - expect(result).to contain_exactly(public_group, private_group, other_group) - end - - context 'when search param is passed' do - let(:params) { { search: 'the' } } - - it 'filters the groups by search' do - expect(result).to contain_exactly(other_group) - end - end - - context 'when sort param is not passed' do - it 'return groups sorted by name in ascending order by default' do - expect(result).to eq([other_group, private_group, public_group]) - end - end - - context 'when sort param is passed' do - using RSpec::Parameterized::TableSyntax - - where(:field, :direction, :sorted_groups) do - 'name' | 'asc' | lazy { [other_group, private_group, public_group] } - 'name' | 'desc' | lazy { [public_group, private_group, other_group] } - 'path' | 'asc' | lazy { [other_group, private_group, public_group] } - 'path' | 'desc' | lazy { [public_group, private_group, other_group] } - end - - with_them do - let(:params) { { sort: { field: field, direction: direction } } } - it 'sorts the groups' do - expect(result).to eq(sorted_groups) - end - end - end - end - end -end -- cgit v1.2.3