Commit 5c7c2601 authored by Scott Hampton's avatar Scott Hampton

Add spec for the test suite query

Added a spec to the pipeline_spec for graphql
queries to make sure the queries were returning
as expected.

Also made sure we were authorizing against the
pipeline instance in the resolver.
parent 0df6aa44
......@@ -5,8 +5,9 @@ module Resolvers
class TestSuiteResolver < BaseResolver
include Gitlab::Graphql::Authorize::AuthorizeResource
authorize :read_build
type ::Types::Ci::TestSuiteType, null: true
authorize :read_build
authorizes_object!
alias_method :pipeline, :object
......
......@@ -130,7 +130,7 @@ module Types
field :test_suite,
Types::Ci::TestSuiteType,
null: false,
null: true,
description: 'A specific test suite in a pipeline test report.',
resolver: Resolvers::Ci::TestSuiteResolver
......
......@@ -4692,7 +4692,7 @@ Information about pagination in a connection.
| `startedAt` | [`Time`](#time) | Timestamp when the pipeline was started. |
| `status` | [`PipelineStatusEnum!`](#pipelinestatusenum) | Status of the pipeline (CREATED, WAITING_FOR_RESOURCE, PREPARING, PENDING, RUNNING, FAILED, SUCCESS, CANCELED, SKIPPED, MANUAL, SCHEDULED). |
| `testReportSummary` | [`TestReportSummary!`](#testreportsummary) | Summary of the test report generated by the pipeline. |
| `testSuite` | [`TestSuite!`](#testsuite) | A specific test suite in a pipeline test report. |
| `testSuite` | [`TestSuite`](#testsuite) | A specific test suite in a pipeline test report. |
| `updatedAt` | [`Time!`](#time) | Timestamp of the pipeline's last activity. |
| `upstream` | [`Pipeline`](#pipeline) | Pipeline that triggered the pipeline. |
| `user` | [`User`](#user) | Pipeline user. |
......
......@@ -5,15 +5,16 @@ require 'spec_helper'
RSpec.describe Resolvers::Ci::TestSuiteResolver do
include GraphqlHelpers
let(:user) { create(:user) }
let(:project) { create(:project, :public, :repository) }
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :public, :repository) }
describe '#resolve' do
subject(:test_suite) { resolve(described_class, obj: pipeline, args: { build_ids: build_ids }) }
context 'when pipeline has builds with test reports' do
let(:main_pipeline) { create(:ci_pipeline, :with_test_reports_with_three_failures, project: project) }
let(:pipeline) { create(:ci_pipeline, :with_test_reports_with_three_failures, project: project, ref: 'new-feature') }
let_it_be(:main_pipeline) { create(:ci_pipeline, :with_test_reports_with_three_failures, project: project) }
let_it_be(:pipeline) { create(:ci_pipeline, :with_test_reports_with_three_failures, project: project, ref: 'new-feature') }
let(:suite_name) { 'test' }
let(:build_ids) { pipeline.latest_builds.pluck(:id) }
......@@ -40,7 +41,8 @@ RSpec.describe Resolvers::Ci::TestSuiteResolver do
end
context 'when pipeline has no builds that matches the given build_ids' do
let(:pipeline) { create(:ci_empty_pipeline) }
let_it_be(:pipeline) { create(:ci_empty_pipeline) }
let(:suite_name) { 'test' }
let(:build_ids) { [non_existing_record_id] }
......
......@@ -235,4 +235,51 @@ RSpec.describe 'getting pipeline information nested in a project' do
end
end
end
context 'when requesting a specific test suite' do
let_it_be(:pipeline) { create(:ci_pipeline, :with_test_reports, project: project) }
let(:suite_name) { 'test' }
let_it_be(:build_ids) { pipeline.latest_builds.pluck(:id) }
let(:variables) do
{
path: project.full_path,
pipelineIID: pipeline.iid.to_s
}
end
let(:query) do
<<~GQL
query($path: ID!, $pipelineIID: ID!, $buildIds: [ID!]!) {
project(fullPath: $path) {
pipeline(iid: $pipelineIID) {
testSuite(buildIds: $buildIds) {
name
}
}
}
}
GQL
end
it 'can request a test suite by an array of build_ids' do
vars = variables.merge(buildIds: build_ids)
post_graphql(query, current_user: current_user, variables: vars)
expect(graphql_data_at(:project, :pipeline, :testSuite, :name)).to eq(suite_name)
end
context 'when pipeline has no builds that matches the given build_ids' do
let_it_be(:build_ids) { [non_existing_record_id] }
it 'returns nil' do
vars = variables.merge(buildIds: build_ids)
post_graphql(query, current_user: current_user, variables: vars)
expect(graphql_data_at(*path, :test_suite)).to be_nil
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment