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:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-10-20 11:43:02 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-10-20 11:43:02 +0300
commitd9ab72d6080f594d0b3cae15f14b3ef2c6c638cb (patch)
tree2341ef426af70ad1e289c38036737e04b0aa5007 /spec/graphql/types
parentd6e514dd13db8947884cd58fe2a9c2a063400a9b (diff)
Add latest changes from gitlab-org/gitlab@14-4-stable-eev14.4.0-rc42
Diffstat (limited to 'spec/graphql/types')
-rw-r--r--spec/graphql/types/base_field_spec.rb11
-rw-r--r--spec/graphql/types/board_list_type_spec.rb27
-rw-r--r--spec/graphql/types/ci/pipeline_type_spec.rb2
-rw-r--r--spec/graphql/types/ci/runner_type_spec.rb2
-rw-r--r--spec/graphql/types/clusters/agent_token_type_spec.rb13
-rw-r--r--spec/graphql/types/clusters/agent_type_spec.rb13
-rw-r--r--spec/graphql/types/container_expiration_policy_older_than_enum_spec.rb2
-rw-r--r--spec/graphql/types/error_tracking/sentry_detailed_error_type_spec.rb1
-rw-r--r--spec/graphql/types/issue_type_spec.rb2
-rw-r--r--spec/graphql/types/kas/agent_configuration_type_spec.rb11
-rw-r--r--spec/graphql/types/kas/agent_connection_type_spec.rb22
-rw-r--r--spec/graphql/types/kas/agent_metadata_type_spec.rb13
-rw-r--r--spec/graphql/types/packages/nuget/metadatum_type_spec.rb6
-rw-r--r--spec/graphql/types/packages/package_type_spec.rb2
-rw-r--r--spec/graphql/types/permission_types/ci/runner_spec.rb15
-rw-r--r--spec/graphql/types/project_type_spec.rb144
-rw-r--r--spec/graphql/types/query_type_spec.rb11
17 files changed, 286 insertions, 11 deletions
diff --git a/spec/graphql/types/base_field_spec.rb b/spec/graphql/types/base_field_spec.rb
index 82efd618e38..31d07f701e8 100644
--- a/spec/graphql/types/base_field_spec.rb
+++ b/spec/graphql/types/base_field_spec.rb
@@ -154,6 +154,17 @@ RSpec.describe Types::BaseField do
end
end
+ describe '#resolve' do
+ context "late_extensions is given" do
+ it 'registers the late extensions after the regular extensions' do
+ extension_class = Class.new(GraphQL::Schema::Field::ConnectionExtension)
+ field = described_class.new(name: 'test', type: GraphQL::Types::String.connection_type, null: true, late_extensions: [extension_class])
+
+ expect(field.extensions.last.class).to be(extension_class)
+ end
+ end
+ end
+
describe '#description' do
context 'feature flag given' do
let(:field) { described_class.new(name: 'test', type: GraphQL::Types::String, feature_flag: flag, null: false, description: 'Test description.') }
diff --git a/spec/graphql/types/board_list_type_spec.rb b/spec/graphql/types/board_list_type_spec.rb
index 7976936fc1f..d78d87c57bd 100644
--- a/spec/graphql/types/board_list_type_spec.rb
+++ b/spec/graphql/types/board_list_type_spec.rb
@@ -3,11 +3,36 @@
require 'spec_helper'
RSpec.describe GitlabSchema.types['BoardList'] do
+ include GraphqlHelpers
+ include Gitlab::Graphql::Laziness
+
specify { expect(described_class.graphql_name).to eq('BoardList') }
it 'has specific fields' do
- expected_fields = %w[id list_type position label issues_count issues]
+ expected_fields = %w[id title list_type position label issues_count issues]
expect(described_class).to include_graphql_fields(*expected_fields)
end
+
+ describe 'issues field' do
+ subject { described_class.fields['issues'] }
+
+ it 'has a correct extension' do
+ is_expected.to have_graphql_extension(Gitlab::Graphql::Board::IssuesConnectionExtension)
+ end
+ end
+
+ describe 'title' do
+ subject(:field) { described_class.fields['title'] }
+
+ it 'preloads the label association' do
+ a, b, c = create_list(:list, 3).map { _1.class.find(_1.id) }
+
+ baseline = ActiveRecord::QueryRecorder.new { force(resolve_field(field, a)) }
+
+ expect do
+ [resolve_field(field, b), resolve_field(field, c)].each { force _1 }
+ end.not_to exceed_query_limit(baseline)
+ end
+ end
end
diff --git a/spec/graphql/types/ci/pipeline_type_spec.rb b/spec/graphql/types/ci/pipeline_type_spec.rb
index 9ba4252bcd5..8c849114cf6 100644
--- a/spec/graphql/types/ci/pipeline_type_spec.rb
+++ b/spec/graphql/types/ci/pipeline_type_spec.rb
@@ -18,7 +18,7 @@ RSpec.describe Types::Ci::PipelineType do
]
if Gitlab.ee?
- expected_fields += %w[security_report_summary security_report_findings code_quality_reports]
+ expected_fields += %w[security_report_summary security_report_findings code_quality_reports dast_profile]
end
expect(described_class).to have_graphql_fields(*expected_fields)
diff --git a/spec/graphql/types/ci/runner_type_spec.rb b/spec/graphql/types/ci/runner_type_spec.rb
index cff4c459d79..cf8650a4a03 100644
--- a/spec/graphql/types/ci/runner_type_spec.rb
+++ b/spec/graphql/types/ci/runner_type_spec.rb
@@ -11,7 +11,7 @@ RSpec.describe GitlabSchema.types['CiRunner'] do
expected_fields = %w[
id description contacted_at maximum_timeout access_level active status
version short_sha revision locked run_untagged ip_address runner_type tag_list
- project_count job_count
+ project_count job_count admin_url user_permissions
]
expect(described_class).to include_graphql_fields(*expected_fields)
diff --git a/spec/graphql/types/clusters/agent_token_type_spec.rb b/spec/graphql/types/clusters/agent_token_type_spec.rb
new file mode 100644
index 00000000000..c872d201fd9
--- /dev/null
+++ b/spec/graphql/types/clusters/agent_token_type_spec.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe GitlabSchema.types['ClusterAgentToken'] do
+ let(:fields) { %i[cluster_agent created_at created_by_user description id last_used_at name] }
+
+ it { expect(described_class.graphql_name).to eq('ClusterAgentToken') }
+
+ it { expect(described_class).to require_graphql_authorizations(:admin_cluster) }
+
+ it { expect(described_class).to have_graphql_fields(fields) }
+end
diff --git a/spec/graphql/types/clusters/agent_type_spec.rb b/spec/graphql/types/clusters/agent_type_spec.rb
new file mode 100644
index 00000000000..4b4b601b230
--- /dev/null
+++ b/spec/graphql/types/clusters/agent_type_spec.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe GitlabSchema.types['ClusterAgent'] do
+ let(:fields) { %i[created_at created_by_user id name project updated_at tokens web_path connections] }
+
+ it { expect(described_class.graphql_name).to eq('ClusterAgent') }
+
+ it { expect(described_class).to require_graphql_authorizations(:admin_cluster) }
+
+ it { expect(described_class).to have_graphql_fields(fields) }
+end
diff --git a/spec/graphql/types/container_expiration_policy_older_than_enum_spec.rb b/spec/graphql/types/container_expiration_policy_older_than_enum_spec.rb
index 72ab605f2e6..1989b87a28f 100644
--- a/spec/graphql/types/container_expiration_policy_older_than_enum_spec.rb
+++ b/spec/graphql/types/container_expiration_policy_older_than_enum_spec.rb
@@ -3,7 +3,7 @@
require 'spec_helper'
RSpec.describe GitlabSchema.types['ContainerExpirationPolicyOlderThanEnum'] do
- let_it_be(:expected_values) { %w[SEVEN_DAYS FOURTEEN_DAYS THIRTY_DAYS NINETY_DAYS] }
+ let_it_be(:expected_values) { %w[SEVEN_DAYS FOURTEEN_DAYS THIRTY_DAYS SIXTY_DAYS NINETY_DAYS] }
it_behaves_like 'exposing container expiration policy option', :older_than
end
diff --git a/spec/graphql/types/error_tracking/sentry_detailed_error_type_spec.rb b/spec/graphql/types/error_tracking/sentry_detailed_error_type_spec.rb
index 8723c212486..09746750adc 100644
--- a/spec/graphql/types/error_tracking/sentry_detailed_error_type_spec.rb
+++ b/spec/graphql/types/error_tracking/sentry_detailed_error_type_spec.rb
@@ -10,6 +10,7 @@ RSpec.describe GitlabSchema.types['SentryDetailedError'] do
it 'exposes the expected fields' do
expected_fields = %i[
id
+ integrated
sentryId
title
type
diff --git a/spec/graphql/types/issue_type_spec.rb b/spec/graphql/types/issue_type_spec.rb
index 559f347810b..c0a0fdf3b0b 100644
--- a/spec/graphql/types/issue_type_spec.rb
+++ b/spec/graphql/types/issue_type_spec.rb
@@ -18,7 +18,7 @@ RSpec.describe GitlabSchema.types['Issue'] do
confidential hidden discussion_locked upvotes downvotes merge_requests_count user_notes_count user_discussions_count web_path web_url relative_position
emails_disabled subscribed time_estimate total_time_spent human_time_estimate human_total_time_spent closed_at created_at updated_at task_completion_status
design_collection alert_management_alert severity current_user_todos moved moved_to
- create_note_email timelogs project_id]
+ create_note_email timelogs project_id customer_relations_contacts]
fields.each do |field_name|
expect(described_class).to have_graphql_field(field_name)
diff --git a/spec/graphql/types/kas/agent_configuration_type_spec.rb b/spec/graphql/types/kas/agent_configuration_type_spec.rb
new file mode 100644
index 00000000000..e6cccfa56d2
--- /dev/null
+++ b/spec/graphql/types/kas/agent_configuration_type_spec.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe GitlabSchema.types['AgentConfiguration'] do
+ let(:fields) { %i[agent_name] }
+
+ it { expect(described_class.graphql_name).to eq('AgentConfiguration') }
+ it { expect(described_class.description).to eq('Configuration details for an Agent') }
+ it { expect(described_class).to have_graphql_fields(fields) }
+end
diff --git a/spec/graphql/types/kas/agent_connection_type_spec.rb b/spec/graphql/types/kas/agent_connection_type_spec.rb
new file mode 100644
index 00000000000..0990d02af11
--- /dev/null
+++ b/spec/graphql/types/kas/agent_connection_type_spec.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Types::Kas::AgentConnectionType do
+ include GraphqlHelpers
+
+ let(:fields) { %i[connected_at connection_id metadata] }
+
+ it { expect(described_class.graphql_name).to eq('ConnectedAgent') }
+ it { expect(described_class.description).to eq('Connection details for an Agent') }
+ it { expect(described_class).to have_graphql_fields(fields) }
+
+ describe '#connected_at' do
+ let(:connected_at) { double(Google::Protobuf::Timestamp, seconds: 123456, nanos: 654321) }
+ let(:object) { double(Gitlab::Agent::AgentTracker::ConnectedAgentInfo, connected_at: connected_at) }
+
+ it 'converts the seconds value to a timestamp' do
+ expect(resolve_field(:connected_at, object)).to eq(Time.at(connected_at.seconds))
+ end
+ end
+end
diff --git a/spec/graphql/types/kas/agent_metadata_type_spec.rb b/spec/graphql/types/kas/agent_metadata_type_spec.rb
new file mode 100644
index 00000000000..ebc12ebb72a
--- /dev/null
+++ b/spec/graphql/types/kas/agent_metadata_type_spec.rb
@@ -0,0 +1,13 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Types::Kas::AgentMetadataType do
+ include GraphqlHelpers
+
+ let(:fields) { %i[version commit pod_namespace pod_name] }
+
+ it { expect(described_class.graphql_name).to eq('AgentMetadata') }
+ it { expect(described_class.description).to eq('Information about a connected Agent') }
+ it { expect(described_class).to have_graphql_fields(fields) }
+end
diff --git a/spec/graphql/types/packages/nuget/metadatum_type_spec.rb b/spec/graphql/types/packages/nuget/metadatum_type_spec.rb
index e5baa7522e4..94a1dbaee43 100644
--- a/spec/graphql/types/packages/nuget/metadatum_type_spec.rb
+++ b/spec/graphql/types/packages/nuget/metadatum_type_spec.rb
@@ -10,4 +10,10 @@ RSpec.describe GitlabSchema.types['NugetMetadata'] do
expect(described_class).to include_graphql_fields(*expected_fields)
end
+
+ %w[projectUrl licenseUrl iconUrl].each do |optional_field|
+ it "#{optional_field} can be null" do
+ expect(described_class.fields[optional_field].type).to be_nullable
+ end
+ end
end
diff --git a/spec/graphql/types/packages/package_type_spec.rb b/spec/graphql/types/packages/package_type_spec.rb
index 07573044abb..3267c765dc7 100644
--- a/spec/graphql/types/packages/package_type_spec.rb
+++ b/spec/graphql/types/packages/package_type_spec.rb
@@ -9,7 +9,7 @@ RSpec.describe GitlabSchema.types['Package'] do
created_at updated_at
project
tags pipelines metadata versions
- status
+ status can_destroy
]
expect(described_class).to include_graphql_fields(*expected_fields)
diff --git a/spec/graphql/types/permission_types/ci/runner_spec.rb b/spec/graphql/types/permission_types/ci/runner_spec.rb
new file mode 100644
index 00000000000..e5fbbb346e4
--- /dev/null
+++ b/spec/graphql/types/permission_types/ci/runner_spec.rb
@@ -0,0 +1,15 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Types::PermissionTypes::Ci::Runner do
+ it do
+ expected_permissions = [
+ :read_runner, :update_runner, :delete_runner
+ ]
+
+ expected_permissions.each do |permission|
+ expect(described_class).to have_graphql_field(permission)
+ end
+ end
+end
diff --git a/spec/graphql/types/project_type_spec.rb b/spec/graphql/types/project_type_spec.rb
index d825bd7ebd4..45a718683be 100644
--- a/spec/graphql/types/project_type_spec.rb
+++ b/spec/graphql/types/project_type_spec.rb
@@ -33,6 +33,7 @@ RSpec.describe GitlabSchema.types['Project'] do
issue_status_counts terraform_states alert_management_integrations
container_repositories container_repositories_count
pipeline_analytics squash_read_only sast_ci_configuration
+ cluster_agent cluster_agents agent_configurations
ci_template timelogs
]
@@ -186,7 +187,7 @@ RSpec.describe GitlabSchema.types['Project'] do
expect(analyzer['enabled']).to eq(true)
end
- context "with guest user" do
+ context 'with guest user' do
before do
project.add_guest(user)
end
@@ -194,7 +195,7 @@ RSpec.describe GitlabSchema.types['Project'] do
context 'when project is private' do
let(:project) { create(:project, :private, :repository) }
- it "returns no configuration" do
+ it 'returns no configuration' do
secure_analyzers_prefix = subject.dig('data', 'project', 'sastCiConfiguration')
expect(secure_analyzers_prefix).to be_nil
end
@@ -214,7 +215,7 @@ RSpec.describe GitlabSchema.types['Project'] do
end
end
- context "with non-member user" do
+ context 'with non-member user', :sidekiq_inline do
before do
project.team.truncate
end
@@ -222,7 +223,7 @@ RSpec.describe GitlabSchema.types['Project'] do
context 'when project is private' do
let(:project) { create(:project, :private, :repository) }
- it "returns no configuration" do
+ it 'returns no configuration' do
secure_analyzers_prefix = subject.dig('data', 'project', 'sastCiConfiguration')
expect(secure_analyzers_prefix).to be_nil
end
@@ -240,7 +241,7 @@ RSpec.describe GitlabSchema.types['Project'] do
end
context 'when repository is accessible only by team members' do
- it "returns no configuration" do
+ it 'returns no configuration' do
project.project_feature.update!(
merge_requests_access_level: ProjectFeature::DISABLED,
builds_access_level: ProjectFeature::DISABLED,
@@ -458,4 +459,137 @@ RSpec.describe GitlabSchema.types['Project'] do
it { is_expected.to have_graphql_type(Types::Ci::JobTokenScopeType) }
it { is_expected.to have_graphql_resolver(Resolvers::Ci::JobTokenScopeResolver) }
end
+
+ describe 'agent_configurations' do
+ let_it_be(:project) { create(:project) }
+ let_it_be(:user) { create(:user) }
+ let_it_be(:query) do
+ %(
+ query {
+ project(fullPath: "#{project.full_path}") {
+ agentConfigurations {
+ nodes {
+ agentName
+ }
+ }
+ }
+ }
+ )
+ end
+
+ let(:agent_name) { 'example-agent-name' }
+ let(:kas_client) { instance_double(Gitlab::Kas::Client, list_agent_config_files: [double(agent_name: agent_name)]) }
+
+ subject { GitlabSchema.execute(query, context: { current_user: user }).as_json }
+
+ before do
+ project.add_maintainer(user)
+ allow(Gitlab::Kas::Client).to receive(:new).and_return(kas_client)
+ end
+
+ it 'returns configured agents' do
+ agents = subject.dig('data', 'project', 'agentConfigurations', 'nodes')
+
+ expect(agents.count).to eq(1)
+ expect(agents.first['agentName']).to eq(agent_name)
+ end
+ end
+
+ describe 'cluster_agents' do
+ let_it_be(:project) { create(:project) }
+ let_it_be(:user) { create(:user) }
+ let_it_be(:cluster_agent) { create(:cluster_agent, project: project, name: 'agent-name') }
+ let_it_be(:query) do
+ %(
+ query {
+ project(fullPath: "#{project.full_path}") {
+ clusterAgents {
+ count
+ nodes {
+ id
+ name
+ createdAt
+ updatedAt
+
+ project {
+ id
+ }
+ }
+ }
+ }
+ }
+ )
+ end
+
+ subject { GitlabSchema.execute(query, context: { current_user: user }).as_json }
+
+ before do
+ project.add_maintainer(user)
+ end
+
+ it 'returns associated cluster agents' do
+ agents = subject.dig('data', 'project', 'clusterAgents', 'nodes')
+
+ expect(agents.count).to be(1)
+ expect(agents.first['id']).to eq(cluster_agent.to_global_id.to_s)
+ expect(agents.first['name']).to eq('agent-name')
+ expect(agents.first['createdAt']).to be_present
+ expect(agents.first['updatedAt']).to be_present
+ expect(agents.first['project']['id']).to eq(project.to_global_id.to_s)
+ end
+
+ it 'returns count of cluster agents' do
+ count = subject.dig('data', 'project', 'clusterAgents', 'count')
+
+ expect(count).to be(project.cluster_agents.size)
+ end
+ end
+
+ describe 'cluster_agent' do
+ let_it_be(:project) { create(:project) }
+ let_it_be(:user) { create(:user) }
+ let_it_be(:cluster_agent) { create(:cluster_agent, project: project, name: 'agent-name') }
+ let_it_be(:agent_token) { create(:cluster_agent_token, agent: cluster_agent) }
+ let_it_be(:query) do
+ %(
+ query {
+ project(fullPath: "#{project.full_path}") {
+ clusterAgent(name: "#{cluster_agent.name}") {
+ id
+
+ tokens {
+ count
+ nodes {
+ id
+ }
+ }
+ }
+ }
+ }
+ )
+ end
+
+ subject { GitlabSchema.execute(query, context: { current_user: user }).as_json }
+
+ before do
+ project.add_maintainer(user)
+ end
+
+ it 'returns associated cluster agents' do
+ agent = subject.dig('data', 'project', 'clusterAgent')
+ tokens = agent.dig('tokens', 'nodes')
+
+ expect(agent['id']).to eq(cluster_agent.to_global_id.to_s)
+
+ expect(tokens.count).to be(1)
+ expect(tokens.first['id']).to eq(agent_token.to_global_id.to_s)
+ end
+
+ it 'returns count of agent tokens' do
+ agent = subject.dig('data', 'project', 'clusterAgent')
+ count = agent.dig('tokens', 'count')
+
+ expect(cluster_agent.agent_tokens.size).to be(count)
+ end
+ end
end
diff --git a/spec/graphql/types/query_type_spec.rb b/spec/graphql/types/query_type_spec.rb
index 6a43867f1fe..14ef03a64f9 100644
--- a/spec/graphql/types/query_type_spec.rb
+++ b/spec/graphql/types/query_type_spec.rb
@@ -27,6 +27,7 @@ RSpec.describe GitlabSchema.types['Query'] do
runner
runners
timelogs
+ board_list
]
expect(described_class).to have_graphql_fields(*expected_fields).at_least
@@ -136,4 +137,14 @@ RSpec.describe GitlabSchema.types['Query'] do
is_expected.to have_graphql_resolver(Resolvers::TimelogResolver)
end
end
+
+ describe 'boardList field' do
+ subject { described_class.fields['boardList'] }
+
+ it 'finds a board list by its gid' do
+ is_expected.to have_graphql_arguments(:id, :issue_filters)
+ is_expected.to have_graphql_type(Types::BoardListType)
+ is_expected.to have_graphql_resolver(Resolvers::BoardListResolver)
+ end
+ end
end