diff options
Diffstat (limited to 'spec/requests/api/graphql/ci')
-rw-r--r-- | spec/requests/api/graphql/ci/ci_cd_setting_spec.rb | 2 | ||||
-rw-r--r-- | spec/requests/api/graphql/ci/config_spec.rb | 64 | ||||
-rw-r--r-- | spec/requests/api/graphql/ci/config_variables_spec.rb | 9 | ||||
-rw-r--r-- | spec/requests/api/graphql/ci/jobs_spec.rb | 11 | ||||
-rw-r--r-- | spec/requests/api/graphql/ci/pipeline_schedules_spec.rb | 88 |
5 files changed, 137 insertions, 37 deletions
diff --git a/spec/requests/api/graphql/ci/ci_cd_setting_spec.rb b/spec/requests/api/graphql/ci/ci_cd_setting_spec.rb index c19defa37e8..2dc7b9764fe 100644 --- a/spec/requests/api/graphql/ci/ci_cd_setting_spec.rb +++ b/spec/requests/api/graphql/ci/ci_cd_setting_spec.rb @@ -48,6 +48,8 @@ RSpec.describe 'Getting Ci Cd Setting' do expect(settings_data['mergeTrainsEnabled']).to eql project.ci_cd_settings.merge_trains_enabled? expect(settings_data['keepLatestArtifact']).to eql project.keep_latest_artifacts_available? expect(settings_data['jobTokenScopeEnabled']).to eql project.ci_cd_settings.job_token_scope_enabled? + expect(settings_data['inboundJobTokenScopeEnabled']).to eql( + project.ci_cd_settings.inbound_job_token_scope_enabled?) end end end diff --git a/spec/requests/api/graphql/ci/config_spec.rb b/spec/requests/api/graphql/ci/config_spec.rb index 960fda80dd9..784019ee926 100644 --- a/spec/requests/api/graphql/ci/config_spec.rb +++ b/spec/requests/api/graphql/ci/config_spec.rb @@ -176,22 +176,22 @@ RSpec.describe 'Query.ciConfig' do "jobs" => { "nodes" => [ - { - "name" => "docker", - "groupName" => "docker", - "stage" => "test", - "script" => ["curl http://dockerhub/URL"], - "beforeScript" => ["bundle install", "bundle exec rake db:create"], - "afterScript" => ["echo 'run this after'"], - "allowFailure" => true, - "only" => { "refs" => %w[branches tags] }, - "when" => "manual", - "except" => { "refs" => ["branches"] }, - "environment" => nil, - "tags" => [], - "needs" => { "nodes" => [{ "name" => "spinach" }, { "name" => "rspec 0 1" }] } - } - ] + { + "name" => "docker", + "groupName" => "docker", + "stage" => "test", + "script" => ["curl http://dockerhub/URL"], + "beforeScript" => ["bundle install", "bundle exec rake db:create"], + "afterScript" => ["echo 'run this after'"], + "allowFailure" => true, + "only" => { "refs" => %w[branches tags] }, + "when" => "manual", + "except" => { "refs" => ["branches"] }, + "environment" => nil, + "tags" => [], + "needs" => { "nodes" => [{ "name" => "spinach" }, { "name" => "rspec 0 1" }] } + } + ] } } ] @@ -209,22 +209,22 @@ RSpec.describe 'Query.ciConfig' do "jobs" => { "nodes" => [ - { - "name" => "deploy_job", - "groupName" => "deploy_job", - "stage" => "deploy", - "script" => ["echo 'done'"], - "beforeScript" => ["bundle install", "bundle exec rake db:create"], - "afterScript" => ["echo 'run this after'"], - "allowFailure" => false, - "only" => { "refs" => %w[branches tags] }, - "when" => "on_success", - "except" => nil, - "environment" => "production", - "tags" => [], - "needs" => { "nodes" => [] } - } - ] + { + "name" => "deploy_job", + "groupName" => "deploy_job", + "stage" => "deploy", + "script" => ["echo 'done'"], + "beforeScript" => ["bundle install", "bundle exec rake db:create"], + "afterScript" => ["echo 'run this after'"], + "allowFailure" => false, + "only" => { "refs" => %w[branches tags] }, + "when" => "on_success", + "except" => nil, + "environment" => "production", + "tags" => [], + "needs" => { "nodes" => [] } + } + ] } } ] diff --git a/spec/requests/api/graphql/ci/config_variables_spec.rb b/spec/requests/api/graphql/ci/config_variables_spec.rb index 2b5a5d0dc93..17133d7ea66 100644 --- a/spec/requests/api/graphql/ci/config_variables_spec.rb +++ b/spec/requests/api/graphql/ci/config_variables_spec.rb @@ -23,6 +23,7 @@ RSpec.describe 'Query.project(fullPath).ciConfigVariables(sha)' do ciConfigVariables(sha: "#{sha}") { key value + valueOptions description } } @@ -53,13 +54,21 @@ RSpec.describe 'Query.project(fullPath).ciConfigVariables(sha)' do expect(graphql_data.dig('project', 'ciConfigVariables')).to contain_exactly( { + 'key' => 'KEY_VALUE_VAR', + 'value' => 'value x', + 'valueOptions' => nil, + 'description' => 'value of KEY_VALUE_VAR' + }, + { 'key' => 'DB_NAME', 'value' => 'postgres', + 'valueOptions' => nil, 'description' => nil }, { 'key' => 'ENVIRONMENT_VAR', 'value' => 'env var value', + 'valueOptions' => ['env var value', 'env var value2'], 'description' => 'env var description' } ) diff --git a/spec/requests/api/graphql/ci/jobs_spec.rb b/spec/requests/api/graphql/ci/jobs_spec.rb index fa8fb1d54aa..47e3221c567 100644 --- a/spec/requests/api/graphql/ci/jobs_spec.rb +++ b/spec/requests/api/graphql/ci/jobs_spec.rb @@ -25,11 +25,12 @@ RSpec.describe 'Query.project.pipeline' do let(:first_n) { var('Int') } let(:query) do - with_signature([first_n], wrap_fields(query_graphql_path([ - [:project, { full_path: project.full_path }], - [:pipeline, { iid: pipeline.iid.to_s }], - [:stages, { first: first_n }] - ], stage_fields))) + with_signature([first_n], wrap_fields(query_graphql_path( + [ + [:project, { full_path: project.full_path }], + [:pipeline, { iid: pipeline.iid.to_s }], + [:stages, { first: first_n }] + ], stage_fields))) end let(:stage_fields) do diff --git a/spec/requests/api/graphql/ci/pipeline_schedules_spec.rb b/spec/requests/api/graphql/ci/pipeline_schedules_spec.rb new file mode 100644 index 00000000000..8b8ba09a95c --- /dev/null +++ b/spec/requests/api/graphql/ci/pipeline_schedules_spec.rb @@ -0,0 +1,88 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe 'Query.project.pipelineSchedules' do + include GraphqlHelpers + + let_it_be(:project) { create(:project, :repository, :public) } + let_it_be(:user) { create(:user) } + let_it_be(:pipeline_schedule) { create(:ci_pipeline_schedule, project: project, owner: user) } + + let(:pipeline_schedule_graphql_data) { graphql_data_at(:project, :pipeline_schedules, :nodes, 0) } + + let(:params) { {} } + + let(:fields) do + <<~QUERY + nodes { + id + description + active + nextRunAt + realNextRun + lastPipeline { + id + } + refForDisplay + refPath + forTag + cron + cronTimezone + } + QUERY + end + + let(:query) do + %( + query { + project(fullPath: "#{project.full_path}") { + pipelineSchedules { + #{fields} + } + } + } + ) + end + + describe 'computed graphql fields' do + before do + pipeline_schedule.pipelines << build(:ci_pipeline, project: project) + + post_graphql(query, current_user: user) + end + + it_behaves_like 'a working graphql query' + + it 'returns calculated fields for a pipeline schedule' do + ref_for_display = pipeline_schedule_graphql_data['refForDisplay'] + + expect(ref_for_display).to eq('master') + expect(pipeline_schedule_graphql_data['refPath']).to eq("/#{project.full_path}/-/commits/#{ref_for_display}") + expect(pipeline_schedule_graphql_data['forTag']).to be(false) + end + end + + it 'avoids N+1 queries' do + create_pipeline_schedules(1) + + control = ActiveRecord::QueryRecorder.new { post_graphql(query, current_user: user) } + + create_pipeline_schedules(3) + + action = ActiveRecord::QueryRecorder.new { post_graphql(query, current_user: user) } + + expect(action).not_to exceed_query_limit(control) + end + + def create_pipeline_schedules(count) + create_list(:ci_pipeline_schedule, count, project: project) + .each do |pipeline_schedule| + create(:user).tap do |user| + project.add_developer(user) + pipeline_schedule.update!(owner: user) + end + pipeline_schedule.pipelines << build(:ci_pipeline, project: project) + end + end +end |