diff options
author | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-06-26 18:31:05 +0200 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2018-07-04 10:53:39 +0200 |
commit | 04b046587fe609cd889f3fa518f08299abc61267 (patch) | |
tree | 634fc7d5e2a416950868700a82c171ff4f54239b /spec/graphql | |
parent | cd5789415b6e561564073693243e890e79596ed2 (diff) | |
download | gitlab-ce-04b046587fe609cd889f3fa518f08299abc61267.tar.gz |
Add pipeline lists to GraphQL
This adds Keyset pagination to GraphQL lists. PoC for that is
pipelines on merge requests and projects.
When paginating a list, the base-64 encoded id of the ordering
field (in most cases the primary key) can be passed in the `before` or
`after` GraphQL argument.
Diffstat (limited to 'spec/graphql')
-rw-r--r-- | spec/graphql/gitlab_schema_spec.rb | 6 | ||||
-rw-r--r-- | spec/graphql/resolvers/concerns/resolves_pipelines_spec.rb | 52 | ||||
-rw-r--r-- | spec/graphql/resolvers/merge_request_pipelines_resolver_spec.rb | 30 | ||||
-rw-r--r-- | spec/graphql/resolvers/project_pipelines_resolver_spec.rb | 22 | ||||
-rw-r--r-- | spec/graphql/types/ci/pipeline_type_spec.rb | 7 | ||||
-rw-r--r-- | spec/graphql/types/merge_request_type_spec.rb | 13 | ||||
-rw-r--r-- | spec/graphql/types/project_type_spec.rb | 2 |
7 files changed, 131 insertions, 1 deletions
diff --git a/spec/graphql/gitlab_schema_spec.rb b/spec/graphql/gitlab_schema_spec.rb index b892f6b44ed..515bbe78cb7 100644 --- a/spec/graphql/gitlab_schema_spec.rb +++ b/spec/graphql/gitlab_schema_spec.rb @@ -27,6 +27,12 @@ describe GitlabSchema do expect(described_class.query).to eq(::Types::QueryType.to_graphql) end + it 'paginates active record relations using `Gitlab::Graphql::Connections::KeysetConnection`' do + connection = GraphQL::Relay::BaseConnection::CONNECTION_IMPLEMENTATIONS[ActiveRecord::Relation.name] + + expect(connection).to eq(Gitlab::Graphql::Connections::KeysetConnection) + end + def field_instrumenters described_class.instrumenters[:field] end diff --git a/spec/graphql/resolvers/concerns/resolves_pipelines_spec.rb b/spec/graphql/resolvers/concerns/resolves_pipelines_spec.rb new file mode 100644 index 00000000000..ea7159eacf9 --- /dev/null +++ b/spec/graphql/resolvers/concerns/resolves_pipelines_spec.rb @@ -0,0 +1,52 @@ +require 'spec_helper' + +describe ResolvesPipelines do + include GraphqlHelpers + + subject(:resolver) do + Class.new(Resolvers::BaseResolver) do + include ResolvesPipelines + + def resolve(**args) + resolve_pipelines(object, args) + end + end + end + + let(:current_user) { create(:user) } + set(:project) { create(:project, :private) } + set(:pipeline) { create(:ci_pipeline, project: project) } + set(:failed_pipeline) { create(:ci_pipeline, :failed, project: project) } + set(:ref_pipeline) { create(:ci_pipeline, project: project, ref: 'awesome-feature') } + set(:sha_pipeline) { create(:ci_pipeline, project: project, sha: 'deadbeef') } + + before do + project.add_developer(current_user) + end + + it { is_expected.to have_graphql_arguments(:status, :ref, :sha) } + + it 'finds all pipelines' do + expect(resolve_pipelines).to contain_exactly(pipeline, failed_pipeline, ref_pipeline, sha_pipeline) + end + + it 'allows filtering by status' do + expect(resolve_pipelines(status: 'failed')).to contain_exactly(failed_pipeline) + end + + it 'allows filtering by ref' do + expect(resolve_pipelines(ref: 'awesome-feature')).to contain_exactly(ref_pipeline) + end + + it 'allows filtering by sha' do + expect(resolve_pipelines(sha: 'deadbeef')).to contain_exactly(sha_pipeline) + end + + it 'does not return any pipelines if the user does not have access' do + expect(resolve_pipelines({}, {})).to be_empty + end + + def resolve_pipelines(args = {}, context = { current_user: current_user }) + resolve(resolver, obj: project, args: args, ctx: context) + end +end diff --git a/spec/graphql/resolvers/merge_request_pipelines_resolver_spec.rb b/spec/graphql/resolvers/merge_request_pipelines_resolver_spec.rb new file mode 100644 index 00000000000..09b17bf6fc9 --- /dev/null +++ b/spec/graphql/resolvers/merge_request_pipelines_resolver_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper' + +describe Resolvers::MergeRequestPipelinesResolver do + include GraphqlHelpers + + set(:merge_request) { create(:merge_request) } + set(:pipeline) do + create( + :ci_pipeline, + project: merge_request.source_project, + ref: merge_request.source_branch, + sha: merge_request.diff_head_sha + ) + end + set(:other_project_pipeline) { create(:ci_pipeline, project: merge_request.source_project) } + set(:other_pipeline) { create(:ci_pipeline) } + let(:current_user) { create(:user) } + + before do + merge_request.project.add_developer(current_user) + end + + def resolve_pipelines + resolve(described_class, obj: merge_request, ctx: { current_user: current_user }) + end + + it 'resolves only MRs for the passed merge request' do + expect(resolve_pipelines).to contain_exactly(pipeline) + end +end diff --git a/spec/graphql/resolvers/project_pipelines_resolver_spec.rb b/spec/graphql/resolvers/project_pipelines_resolver_spec.rb new file mode 100644 index 00000000000..407ca2f9d78 --- /dev/null +++ b/spec/graphql/resolvers/project_pipelines_resolver_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper' + +describe Resolvers::ProjectPipelinesResolver do + include GraphqlHelpers + + set(:project) { create(:project) } + set(:pipeline) { create(:ci_pipeline, project: project) } + set(:other_pipeline) { create(:ci_pipeline) } + let(:current_user) { create(:user) } + + before do + project.add_developer(current_user) + end + + def resolve_pipelines + resolve(described_class, obj: project, ctx: { current_user: current_user }) + end + + it 'resolves only MRs for the passed merge request' do + expect(resolve_pipelines).to contain_exactly(pipeline) + end +end diff --git a/spec/graphql/types/ci/pipeline_type_spec.rb b/spec/graphql/types/ci/pipeline_type_spec.rb new file mode 100644 index 00000000000..ec1c689a4be --- /dev/null +++ b/spec/graphql/types/ci/pipeline_type_spec.rb @@ -0,0 +1,7 @@ +require 'spec_helper' + +describe Types::Ci::PipelineType do + it { expect(described_class.graphql_name).to eq('Pipeline') } + + it { expect(described_class).to expose_permissions_using(Types::PermissionTypes::Ci::Pipeline) } +end diff --git a/spec/graphql/types/merge_request_type_spec.rb b/spec/graphql/types/merge_request_type_spec.rb index 6e57122867a..c369953e3ea 100644 --- a/spec/graphql/types/merge_request_type_spec.rb +++ b/spec/graphql/types/merge_request_type_spec.rb @@ -1,5 +1,16 @@ require 'spec_helper' -describe Types::MergeRequestType do +describe GitlabSchema.types['MergeRequest'] do it { expect(described_class).to expose_permissions_using(Types::PermissionTypes::MergeRequest) } + + describe 'head pipeline' do + it 'has a head pipeline field' do + expect(described_class).to have_graphql_field(:head_pipeline) + end + + it 'authorizes the field' do + expect(described_class.fields['headPipeline']) + .to require_graphql_authorizations(:read_pipeline) + end + end end diff --git a/spec/graphql/types/project_type_spec.rb b/spec/graphql/types/project_type_spec.rb index 7b5bc335511..49606c397b9 100644 --- a/spec/graphql/types/project_type_spec.rb +++ b/spec/graphql/types/project_type_spec.rb @@ -13,4 +13,6 @@ describe GitlabSchema.types['Project'] do .to require_graphql_authorizations(:read_merge_request) end end + + it { is_expected.to have_graphql_field(:pipelines) } end |