diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-24 15:12:29 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-24 15:12:29 +0300 |
commit | 83ffdf48518e121c1ccab9d7913d3f7e79d7766c (patch) | |
tree | 478c690873fcd6b448968f4ff3158e7050b04917 /spec/graphql | |
parent | aab5db568e1090b5a9ae9cec6d788f88ac6faa4c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/graphql')
-rw-r--r-- | spec/graphql/resolvers/ci/catalog/resources_resolver_spec.rb | 96 |
1 files changed, 75 insertions, 21 deletions
diff --git a/spec/graphql/resolvers/ci/catalog/resources_resolver_spec.rb b/spec/graphql/resolvers/ci/catalog/resources_resolver_spec.rb index 47fef51dec2..224af664ea1 100644 --- a/spec/graphql/resolvers/ci/catalog/resources_resolver_spec.rb +++ b/spec/graphql/resolvers/ci/catalog/resources_resolver_spec.rb @@ -6,23 +6,31 @@ RSpec.describe Resolvers::Ci::Catalog::ResourcesResolver, feature_category: :pip include GraphqlHelpers let_it_be(:namespace) { create(:group) } - let_it_be(:project_1) { create(:project, name: 'Z', namespace: namespace) } - let_it_be(:project_2) { create(:project, name: 'A_Test', namespace: namespace) } - let_it_be(:project_3) { create(:project, name: 'L', description: 'Test', namespace: namespace) } - let_it_be(:published_resource_1) { create(:ci_catalog_resource, :published, project: project_1) } - let_it_be(:published_resource_2) { create(:ci_catalog_resource, :published, project: project_2) } - let_it_be(:resource_3) { create(:ci_catalog_resource, project: project_3) } + let_it_be(:private_namespace_project) { create(:project, :private, name: 'z private test', namespace: namespace) } + let_it_be(:private_namespace_project_2) { create(:project, :private, name: 'a private test', namespace: namespace) } + let_it_be(:public_namespace_project) do + create(:project, :public, name: 'public', description: 'Test', namespace: namespace) + end + + let_it_be(:internal_project) { create(:project, :internal, :private, name: 'internal') } + let_it_be(:private_resource) { create(:ci_catalog_resource, :published, project: private_namespace_project) } + let_it_be(:private_resource_2) { create(:ci_catalog_resource, project: private_namespace_project_2) } + let_it_be(:public_resource) { create(:ci_catalog_resource, :published, project: public_namespace_project) } + let_it_be(:internal_resource) { create(:ci_catalog_resource, :published, project: internal_project) } let_it_be(:user) { create(:user) } let(:ctx) { { current_user: user } } let(:search) { nil } let(:sort) { nil } + let(:scope) { nil } + let(:project_path) { nil } let(:args) do { - project_path: project_1.full_path, + project_path: project_path, sort: sort, - search: search + search: search, + scope: scope }.compact end @@ -31,40 +39,86 @@ RSpec.describe Resolvers::Ci::Catalog::ResourcesResolver, feature_category: :pip describe '#resolve' do context 'with an authorized user' do before_all do - namespace.add_owner(user) + namespace.add_reporter(user) + internal_project.add_owner(user) end - it 'returns all published catalog resources visible to the current user in the namespace' do - expect(result.items.count).to be(2) - expect(result.items.pluck(:name)).to contain_exactly('Z', 'A_Test') + context 'when the project path argument is provided' do + let(:project_path) { private_namespace_project.full_path } + + it 'returns all catalog resources visible to the current user in the namespace' do + expect(result.items.count).to be(2) + expect(result.items.pluck(:name)).to contain_exactly('z private test', 'public') + end end - context 'when the sort parameter is not provided' do - it 'returns all published catalog resources sorted by descending created date' do - expect(result.items.pluck(:name)).to eq(%w[A_Test Z]) + context 'when sort argument is not provided' do + it 'returns all catalog resources sorted by descending created date' do + expect(result.items.pluck(:name)).to eq(['internal', 'public', 'z private test']) end end - context 'when the sort parameter is provided' do + context 'when the sort argument is provided' do let(:sort) { 'NAME_DESC' } it 'returns all published catalog resources sorted by descending name' do - expect(result.items.pluck(:name)).to eq(%w[Z A_Test]) + expect(result.items.pluck(:name)).to eq(['z private test', 'public', 'internal']) end end - context 'when the search parameter is provided' do + context 'when the search argument is provided' do let(:search) { 'test' } it 'returns published catalog resources that match the search term' do - expect(result.items.pluck(:name)).to contain_exactly('A_Test') + expect(result.items.pluck(:name)).to contain_exactly('z private test', 'public') + end + end + + context 'with scope argument' do + it 'defaults to :all and returns all catalog resources' do + expect(result.items.count).to be(3) + expect(result.items.pluck(:name)).to contain_exactly('public', 'internal', 'z private test') + end + + context 'when the scope argument is :namespaces' do + let(:scope) { 'NAMESPACES' } + + it 'returns only internal and public projects of the namespaces the user is a member of' do + namespace = create(:namespace, owner: user) + internal_public_project = create(:project, :internal, name: 'internal public', namespace: namespace) + create(:ci_catalog_resource, :published, project: internal_public_project) + + expect(result.items.count).to be(2) + expect(result.items.pluck(:name)).to contain_exactly('public', 'internal public') + end + end + + context 'and the ci_guard_for_catalog_resource_scope FF is disabled' do + before do + stub_feature_flags(ci_guard_for_catalog_resource_scope: false) + end + + it 'returns all the catalog resources' do + expect(result.items.count).to be(3) + expect(result.items.pluck(:name)).to contain_exactly('public', 'internal', 'z private test') + end + end + + context 'when the scope is invalid' do + let(:scope) { 'INVALID' } + + it 'defaults to :all and returns all catalog resources' do + expect(result.items.count).to be(3) + expect(result.items.pluck(:name)).to contain_exactly('public', 'internal', 'z private test') + end end end end context 'when the current user cannot read the namespace catalog' do - it 'returns empty response' do - expect(result).to be_empty + it 'returns only public projects' do + expect(result.items.count).to be(1) + expect(result.items.pluck(:name)).to contain_exactly('public') end end end |