diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-08-20 21:42:06 +0300 |
commit | 6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch) | |
tree | 78be5963ec075d80116a932011d695dd33910b4e /spec/requests/api/graphql/ci | |
parent | 1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff) |
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'spec/requests/api/graphql/ci')
-rw-r--r-- | spec/requests/api/graphql/ci/groups_spec.rb | 55 | ||||
-rw-r--r-- | spec/requests/api/graphql/ci/jobs_spec.rb | 93 | ||||
-rw-r--r-- | spec/requests/api/graphql/ci/stages_spec.rb | 46 |
3 files changed, 194 insertions, 0 deletions
diff --git a/spec/requests/api/graphql/ci/groups_spec.rb b/spec/requests/api/graphql/ci/groups_spec.rb new file mode 100644 index 00000000000..9e81358a152 --- /dev/null +++ b/spec/requests/api/graphql/ci/groups_spec.rb @@ -0,0 +1,55 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe 'Query.project.pipeline.stages.groups' do + include GraphqlHelpers + + let(:project) { create(:project, :repository, :public) } + let(:user) { create(:user) } + let(:pipeline) { create(:ci_pipeline, project: project, user: user) } + let(:group_graphql_data) { graphql_data.dig('project', 'pipeline', 'stages', 'nodes', 0, 'groups', 'nodes') } + + let(:params) { {} } + + let(:fields) do + <<~QUERY + nodes { + #{all_graphql_fields_for('CiGroup')} + } + QUERY + end + + let(:query) do + %( + query { + project(fullPath: "#{project.full_path}") { + pipeline(iid: "#{pipeline.iid}") { + stages { + nodes { + groups { + #{fields} + } + } + } + } + } + } + ) + end + + before do + create(:commit_status, pipeline: pipeline, name: 'rspec 0 2') + create(:commit_status, pipeline: pipeline, name: 'rspec 0 1') + create(:commit_status, pipeline: pipeline, name: 'spinach 0 1') + post_graphql(query, current_user: user) + end + + it_behaves_like 'a working graphql query' + + it 'returns a array of jobs belonging to a pipeline' do + expect(group_graphql_data.map { |g| g.slice('name', 'size') }).to eq([ + { 'name' => 'rspec', 'size' => 2 }, + { 'name' => 'spinach', 'size' => 1 } + ]) + end +end diff --git a/spec/requests/api/graphql/ci/jobs_spec.rb b/spec/requests/api/graphql/ci/jobs_spec.rb new file mode 100644 index 00000000000..7d416f4720b --- /dev/null +++ b/spec/requests/api/graphql/ci/jobs_spec.rb @@ -0,0 +1,93 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe 'Query.project.pipeline.stages.groups.jobs' do + include GraphqlHelpers + + let(:project) { create(:project, :repository, :public) } + let(:user) { create(:user) } + let(:pipeline) do + pipeline = create(:ci_pipeline, project: project, user: user) + stage = create(:ci_stage_entity, pipeline: pipeline, name: 'first') + create(:commit_status, stage_id: stage.id, pipeline: pipeline, name: 'my test job') + + pipeline + end + + def first(field) + [field.pluralize, 'nodes', 0] + end + + let(:jobs_graphql_data) { graphql_data.dig(*%w[project pipeline], *first('stage'), *first('group'), 'jobs', 'nodes') } + + let(:query) do + %( + query { + project(fullPath: "#{project.full_path}") { + pipeline(iid: "#{pipeline.iid}") { + stages { + nodes { + name + groups { + nodes { + name + jobs { + nodes { + name + } + } + } + } + } + } + } + } + } + ) + end + + it 'returns the jobs of a pipeline stage' do + post_graphql(query, current_user: user) + + expect(jobs_graphql_data).to contain_exactly(a_hash_including('name' => 'my test job')) + end + + context 'when fetching jobs from the pipeline' do + it 'avoids N+1 queries' do + control_count = ActiveRecord::QueryRecorder.new do + post_graphql(query, current_user: user) + end + + build_stage = create(:ci_stage_entity, name: 'build', pipeline: pipeline) + test_stage = create(:ci_stage_entity, name: 'test', pipeline: pipeline) + create(:commit_status, pipeline: pipeline, stage_id: build_stage.id, name: 'docker 1 2') + create(:commit_status, pipeline: pipeline, stage_id: build_stage.id, name: 'docker 2 2') + create(:commit_status, pipeline: pipeline, stage_id: test_stage.id, name: 'rspec 1 2') + create(:commit_status, pipeline: pipeline, stage_id: test_stage.id, name: 'rspec 2 2') + + expect do + post_graphql(query, current_user: user) + end.not_to exceed_query_limit(control_count) + + expect(response).to have_gitlab_http_status(:ok) + + build_stage = graphql_data.dig('project', 'pipeline', 'stages', 'nodes').find do |stage| + stage['name'] == 'build' + end + test_stage = graphql_data.dig('project', 'pipeline', 'stages', 'nodes').find do |stage| + stage['name'] == 'test' + end + docker_group = build_stage.dig('groups', 'nodes').first + rspec_group = test_stage.dig('groups', 'nodes').first + + expect(docker_group['name']).to eq('docker') + expect(rspec_group['name']).to eq('rspec') + + docker_jobs = docker_group.dig('jobs', 'nodes') + rspec_jobs = rspec_group.dig('jobs', 'nodes') + + expect(docker_jobs).to eq([{ 'name' => 'docker 1 2' }, { 'name' => 'docker 2 2' }]) + expect(rspec_jobs).to eq([{ 'name' => 'rspec 1 2' }, { 'name' => 'rspec 2 2' }]) + end + end +end diff --git a/spec/requests/api/graphql/ci/stages_spec.rb b/spec/requests/api/graphql/ci/stages_spec.rb new file mode 100644 index 00000000000..cd48a24b9c8 --- /dev/null +++ b/spec/requests/api/graphql/ci/stages_spec.rb @@ -0,0 +1,46 @@ +# frozen_string_literal: true +require 'spec_helper' + +RSpec.describe 'Query.project.pipeline.stages' do + include GraphqlHelpers + + let(:project) { create(:project, :repository, :public) } + let(:user) { create(:user) } + let(:pipeline) { create(:ci_pipeline, project: project, user: user) } + let(:stage_graphql_data) { graphql_data['project']['pipeline']['stages'] } + + let(:params) { {} } + + let(:fields) do + <<~QUERY + nodes { + #{all_graphql_fields_for('CiStage')} + } + QUERY + end + + let(:query) do + %( + query { + project(fullPath: "#{project.full_path}") { + pipeline(iid: "#{pipeline.iid}") { + stages { + #{fields} + } + } + } + } + ) + end + + before do + create(:ci_stage_entity, pipeline: pipeline, name: 'deploy') + post_graphql(query, current_user: user) + end + + it_behaves_like 'a working graphql query' + + it 'returns the stage of a pipeline' do + expect(stage_graphql_data['nodes'].first['name']).to eq('deploy') + end +end |