Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/requests/api/graphql/ci/catalog')
-rw-r--r--spec/requests/api/graphql/ci/catalog/resource_spec.rb188
-rw-r--r--spec/requests/api/graphql/ci/catalog/resources_spec.rb76
2 files changed, 132 insertions, 132 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(
diff --git a/spec/requests/api/graphql/ci/catalog/resources_spec.rb b/spec/requests/api/graphql/ci/catalog/resources_spec.rb
index 7c955a1202c..49a3f3be1d7 100644
--- a/spec/requests/api/graphql/ci/catalog/resources_spec.rb
+++ b/spec/requests/api/graphql/ci/catalog/resources_spec.rb
@@ -29,8 +29,11 @@ RSpec.describe 'Query.ciCatalogResources', feature_category: :pipeline_compositi
)
end
- let_it_be(:resource1) { create(:ci_catalog_resource, project: project1, latest_released_at: '2023-01-01T00:00:00Z') }
- let_it_be(:public_resource) { create(:ci_catalog_resource, project: public_project) }
+ let_it_be(:resource1) do
+ create(:ci_catalog_resource, :published, project: project1, latest_released_at: '2023-01-01T00:00:00Z')
+ end
+
+ let_it_be(:public_resource) { create(:ci_catalog_resource, :published, project: public_project) }
let(:query) do
<<~GQL
@@ -44,7 +47,6 @@ RSpec.describe 'Query.ciCatalogResources', feature_category: :pipeline_compositi
webPath
latestReleasedAt
starCount
- forksCount
readmeHtml
}
}
@@ -58,11 +60,11 @@ RSpec.describe 'Query.ciCatalogResources', feature_category: :pipeline_compositi
it do
ctx = { current_user: user }
- control_count = ActiveRecord::QueryRecorder.new do
+ control_count = ActiveRecord::QueryRecorder.new(skip_cached: false) do
run_with_clean_state(query, context: ctx)
end
- create(:ci_catalog_resource, project: project2)
+ create(:ci_catalog_resource, :published, project: project2)
expect do
run_with_clean_state(query, context: ctx)
@@ -83,7 +85,6 @@ RSpec.describe 'Query.ciCatalogResources', feature_category: :pipeline_compositi
icon: project1.avatar_path,
webPath: "/#{project1.full_path}",
starCount: project1.star_count,
- forksCount: project1.forks_count,
readmeHtml: a_string_including('Test</strong>'),
latestReleasedAt: resource1.latest_released_at
),
@@ -121,7 +122,7 @@ RSpec.describe 'Query.ciCatalogResources', feature_category: :pipeline_compositi
end
it 'limits the request to 1 resource at a time' do
- create(:ci_catalog_resource, project: project2)
+ create(:ci_catalog_resource, :published, project: project2)
post_query
@@ -135,11 +136,13 @@ RSpec.describe 'Query.ciCatalogResources', feature_category: :pipeline_compositi
let_it_be(:author2) { create(:user, name: 'author2') }
let_it_be(:latest_version1) do
- create(:release, project: project1, released_at: '2023-02-01T00:00:00Z', author: author1)
+ create(:release, :with_catalog_resource_version, project: project1, released_at: '2023-02-01T00:00:00Z',
+ author: author1).catalog_resource_version
end
let_it_be(:latest_version2) do
- create(:release, project: public_project, released_at: '2023-02-01T00:00:00Z', author: author2)
+ create(:release, :with_catalog_resource_version, project: public_project, released_at: '2023-02-01T00:00:00Z',
+ author: author2).catalog_resource_version
end
let(:query) do
@@ -167,9 +170,11 @@ RSpec.describe 'Query.ciCatalogResources', feature_category: :pipeline_compositi
before_all do
namespace.add_developer(user)
- # Previous versions of the projects
- create(:release, project: project1, released_at: '2023-01-01T00:00:00Z', author: author1)
- create(:release, project: public_project, released_at: '2023-01-01T00:00:00Z', author: author2)
+ # Previous versions of the catalog resources
+ create(:release, :with_catalog_resource_version, project: project1, released_at: '2023-01-01T00:00:00Z',
+ author: author1)
+ create(:release, :with_catalog_resource_version, project: public_project, released_at: '2023-01-01T00:00:00Z',
+ author: author2)
end
it 'returns all resources with the latest version data' do
@@ -180,7 +185,7 @@ RSpec.describe 'Query.ciCatalogResources', feature_category: :pipeline_compositi
resource1,
latestVersion: a_graphql_entity_for(
latest_version1,
- tagName: latest_version1.tag,
+ tagName: latest_version1.name,
releasedAt: latest_version1.released_at,
author: a_graphql_entity_for(author1, :name)
)
@@ -189,7 +194,7 @@ RSpec.describe 'Query.ciCatalogResources', feature_category: :pipeline_compositi
public_resource,
latestVersion: a_graphql_entity_for(
latest_version2,
- tagName: latest_version2.tag,
+ tagName: latest_version2.name,
releasedAt: latest_version2.released_at,
author: a_graphql_entity_for(author2, :name)
)
@@ -197,43 +202,7 @@ RSpec.describe 'Query.ciCatalogResources', feature_category: :pipeline_compositi
)
end
- # TODO: https://gitlab.com/gitlab-org/gitlab/-/issues/430350
- # it_behaves_like 'avoids N+1 queries'
- end
-
- describe 'rootNamespace' do
- before_all do
- namespace.add_developer(user)
- end
-
- let(:query) do
- <<~GQL
- query {
- ciCatalogResources {
- nodes {
- id
- rootNamespace {
- id
- name
- path
- }
- }
- }
- }
- GQL
- end
-
- it 'returns the correct root namespace data' do
- post_query
-
- expect(graphql_data_at(:ciCatalogResources, :nodes)).to contain_exactly(
- a_graphql_entity_for(
- resource1,
- rootNamespace: a_graphql_entity_for(namespace, :name, :path)
- ),
- a_graphql_entity_for(public_resource, rootNamespace: nil)
- )
- end
+ it_behaves_like 'avoids N+1 queries'
end
describe 'openIssuesCount' do
@@ -326,8 +295,8 @@ RSpec.describe 'Query.ciCatalogResources', feature_category: :pipeline_compositi
end
it 'returns catalog resources with the expected data' do
- resource2 = create(:ci_catalog_resource, project: project2)
- _resource_in_another_namespace = create(:ci_catalog_resource)
+ resource2 = create(:ci_catalog_resource, :published, project: project2)
+ _resource_in_another_namespace = create(:ci_catalog_resource, :published)
post_query
@@ -338,7 +307,6 @@ RSpec.describe 'Query.ciCatalogResources', feature_category: :pipeline_compositi
icon: project2.avatar_path,
webPath: "/#{project2.full_path}",
starCount: project2.star_count,
- forksCount: project2.forks_count,
readmeHtml: '',
latestReleasedAt: resource2.latest_released_at
)