diff options
Diffstat (limited to 'spec/requests/api/graphql/ci/catalog/resource_spec.rb')
-rw-r--r-- | spec/requests/api/graphql/ci/catalog/resource_spec.rb | 188 |
1 files changed, 110 insertions, 78 deletions
diff --git a/spec/requests/api/graphql/ci/catalog/resource_spec.rb b/spec/requests/api/graphql/ci/catalog/resource_spec.rb index fce773f320b..9fe73e7ba45 100644 --- a/spec/requests/api/graphql/ci/catalog/resource_spec.rb +++ b/spec/requests/api/graphql/ci/catalog/resource_spec.rb @@ -15,11 +15,14 @@ RSpec.describe 'Query.ciCatalogResource', feature_category: :pipeline_compositio description: 'A simple component', namespace: namespace, star_count: 1, - files: { 'README.md' => '[link](README.md)' } + files: { + 'README.md' => '[link](README.md)', + 'templates/secret-detection.yml' => "spec:\n inputs:\n website:\n---\nimage: alpine_1" + } ) end - let_it_be(:resource) { create(:ci_catalog_resource, project: project) } + let_it_be(:resource) { create(:ci_catalog_resource, :published, project: project) } let(:query) do <<~GQL @@ -33,10 +36,12 @@ RSpec.describe 'Query.ciCatalogResource', feature_category: :pipeline_compositio subject(:post_query) { post_graphql(query, current_user: user) } + before_all do + namespace.add_developer(user) + end + context 'when the current user has permission to read the namespace catalog' do it 'returns the resource with the expected data' do - namespace.add_developer(user) - post_query expect(graphql_data_at(:ciCatalogResource)).to match( @@ -45,7 +50,6 @@ RSpec.describe 'Query.ciCatalogResource', feature_category: :pipeline_compositio icon: project.avatar_path, webPath: "/#{project.full_path}", starCount: project.star_count, - forksCount: project.forks_count, readmeHtml: a_string_including( "#{project.full_path}/-/blob/#{project.default_branch}/README.md" ) @@ -64,15 +68,94 @@ RSpec.describe 'Query.ciCatalogResource', feature_category: :pipeline_compositio end end - describe 'versions' do - before_all do - namespace.add_developer(user) + describe 'components' do + let(:query) do + <<~GQL + query { + ciCatalogResource(id: "#{resource.to_global_id}") { + id + versions { + nodes { + id + components { + nodes { + id + name + path + inputs { + name + default + required + } + } + } + } + } + } + } + GQL end - before do - stub_licensed_features(ci_namespace_catalog: true) + context 'when the catalog resource has components' do + let_it_be(:inputs) do + { + website: nil, + environment: { + default: 'test' + }, + tags: { + type: 'array' + } + } + end + + let_it_be(:version) do + create(:release, :with_catalog_resource_version, project: project).catalog_resource_version + end + + let_it_be(:components) do + create_list(:ci_catalog_resource_component, 2, version: version, inputs: inputs, path: 'templates/comp.yml') + end + + it 'returns the resource with the component data' do + post_query + + expect(graphql_data_at(:ciCatalogResource)).to match(a_graphql_entity_for(resource)) + + expect(graphql_data_at(:ciCatalogResource, :versions, :nodes, :components, :nodes)).to contain_exactly( + a_graphql_entity_for( + components.first, + name: components.first.name, + path: components.first.path, + inputs: [ + a_graphql_entity_for( + name: 'tags', + default: nil, + required: true + ), + a_graphql_entity_for( + name: 'website', + default: nil, + required: true + ), + a_graphql_entity_for( + name: 'environment', + default: 'test', + required: false + ) + ] + ), + a_graphql_entity_for( + components.last, + name: components.last.name, + path: components.last.path + ) + ) + end end + end + describe 'versions' do let(:query) do <<~GQL query { @@ -82,6 +165,7 @@ RSpec.describe 'Query.ciCatalogResource', feature_category: :pipeline_compositio nodes { id tagName + tagPath releasedAt author { id @@ -99,11 +183,13 @@ RSpec.describe 'Query.ciCatalogResource', feature_category: :pipeline_compositio let_it_be(:author) { create(:user, name: 'author') } let_it_be(:version1) do - create(:release, project: project, released_at: '2023-01-01T00:00:00Z', author: author) + create(:release, :with_catalog_resource_version, project: project, released_at: '2023-01-01T00:00:00Z', + author: author).catalog_resource_version end let_it_be(:version2) do - create(:release, project: project, released_at: '2023-02-01T00:00:00Z', author: author) + create(:release, :with_catalog_resource_version, project: project, released_at: '2023-02-01T00:00:00Z', + author: author).catalog_resource_version end it 'returns the resource with the versions data' do @@ -116,13 +202,15 @@ RSpec.describe 'Query.ciCatalogResource', feature_category: :pipeline_compositio expect(graphql_data_at(:ciCatalogResource, :versions, :nodes)).to contain_exactly( a_graphql_entity_for( version1, - tagName: version1.tag, + tagName: version1.name, + tagPath: project_tag_path(project, version1.name), releasedAt: version1.released_at, author: a_graphql_entity_for(author, :name) ), a_graphql_entity_for( version2, - tagName: version2.tag, + tagName: version2.name, + tagPath: project_tag_path(project, version2.name), releasedAt: version2.released_at, author: a_graphql_entity_for(author, :name) ) @@ -142,14 +230,6 @@ RSpec.describe 'Query.ciCatalogResource', feature_category: :pipeline_compositio end describe 'latestVersion' do - before_all do - namespace.add_developer(user) - end - - before do - stub_licensed_features(ci_namespace_catalog: true) - end - let(:query) do <<~GQL query { @@ -158,6 +238,7 @@ RSpec.describe 'Query.ciCatalogResource', feature_category: :pipeline_compositio latestVersion { id tagName + tagPath releasedAt author { id @@ -174,12 +255,14 @@ RSpec.describe 'Query.ciCatalogResource', feature_category: :pipeline_compositio let_it_be(:author) { create(:user, name: 'author') } let_it_be(:latest_version) do - create(:release, project: project, released_at: '2023-02-01T00:00:00Z', author: author) + create(:release, :with_catalog_resource_version, project: project, released_at: '2023-02-01T00:00:00Z', + author: author).catalog_resource_version end before_all do - # Previous version of the project - create(:release, project: project, released_at: '2023-01-01T00:00:00Z', author: author) + # Previous version of the catalog resource + create(:release, :with_catalog_resource_version, project: project, released_at: '2023-01-01T00:00:00Z', + author: author) end it 'returns the resource with the latest version data' do @@ -190,7 +273,8 @@ RSpec.describe 'Query.ciCatalogResource', feature_category: :pipeline_compositio resource, latestVersion: a_graphql_entity_for( latest_version, - tagName: latest_version.tag, + tagName: latest_version.name, + tagPath: project_tag_path(project, latest_version.name), releasedAt: latest_version.released_at, author: a_graphql_entity_for(author, :name) ) @@ -210,47 +294,7 @@ RSpec.describe 'Query.ciCatalogResource', feature_category: :pipeline_compositio end end - describe 'rootNamespace' do - before_all do - namespace.add_developer(user) - end - - before do - stub_licensed_features(ci_namespace_catalog: true) - end - - let(:query) do - <<~GQL - query { - ciCatalogResource(id: "#{resource.to_global_id}") { - id - rootNamespace { - id - name - path - } - } - } - GQL - end - - it 'returns the correct root namespace data' do - post_query - - expect(graphql_data_at(:ciCatalogResource)).to match( - a_graphql_entity_for( - resource, - rootNamespace: a_graphql_entity_for(namespace, :name, :path) - ) - ) - end - end - describe 'openIssuesCount' do - before do - stub_licensed_features(ci_namespace_catalog: true) - end - context 'when open_issue_count is requested' do let(:query) do <<~GQL @@ -266,8 +310,6 @@ RSpec.describe 'Query.ciCatalogResource', feature_category: :pipeline_compositio create(:issue, :opened, project: project) create(:issue, :opened, project: project) - namespace.add_developer(user) - post_query expect(graphql_data_at(:ciCatalogResource)).to match( @@ -279,8 +321,6 @@ RSpec.describe 'Query.ciCatalogResource', feature_category: :pipeline_compositio context 'when open_issue_count is zero' do it 'returns zero' do - namespace.add_developer(user) - post_query expect(graphql_data_at(:ciCatalogResource)).to match( @@ -294,10 +334,6 @@ RSpec.describe 'Query.ciCatalogResource', feature_category: :pipeline_compositio end describe 'openMergeRequestsCount' do - before do - stub_licensed_features(ci_namespace_catalog: true) - end - context 'when merge_requests_count is requested' do let(:query) do <<~GQL @@ -312,8 +348,6 @@ RSpec.describe 'Query.ciCatalogResource', feature_category: :pipeline_compositio it 'returns the correct count' do create(:merge_request, :opened, source_project: project) - namespace.add_developer(user) - post_query expect(graphql_data_at(:ciCatalogResource)).to match( @@ -325,8 +359,6 @@ RSpec.describe 'Query.ciCatalogResource', feature_category: :pipeline_compositio context 'when open merge_requests_count is zero' do it 'returns zero' do - namespace.add_developer(user) - post_query expect(graphql_data_at(:ciCatalogResource)).to match( |