summaryrefslogtreecommitdiff
path: root/spec/graphql/resolvers
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-11-14 12:06:30 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-11-14 12:06:30 +0000
commitd8c06be498acbfc2024c01b6b6b02d120dc499f2 (patch)
tree9e2e0852c45332d6222898676a2f6f096e600084 /spec/graphql/resolvers
parent2fa7d2ddf6a7004f89616e43b8279229af831e25 (diff)
downloadgitlab-ce-d8c06be498acbfc2024c01b6b6b02d120dc499f2.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/graphql/resolvers')
-rw-r--r--spec/graphql/resolvers/base_resolver_spec.rb24
-rw-r--r--spec/graphql/resolvers/commit_pipelines_resolver_spec.rb53
2 files changed, 77 insertions, 0 deletions
diff --git a/spec/graphql/resolvers/base_resolver_spec.rb b/spec/graphql/resolvers/base_resolver_spec.rb
index c162fdbbb47..a212bd07f35 100644
--- a/spec/graphql/resolvers/base_resolver_spec.rb
+++ b/spec/graphql/resolvers/base_resolver_spec.rb
@@ -13,6 +13,14 @@ describe Resolvers::BaseResolver do
end
end
+ let(:last_resolver) do
+ Class.new(described_class) do
+ def resolve(**args)
+ [1, 2]
+ end
+ end
+ end
+
describe '.single' do
it 'returns a subclass from the resolver' do
expect(resolver.single.superclass).to eq(resolver)
@@ -29,6 +37,22 @@ describe Resolvers::BaseResolver do
end
end
+ describe '.last' do
+ it 'returns a subclass from the resolver' do
+ expect(last_resolver.last.superclass).to eq(last_resolver)
+ end
+
+ it 'returns the same subclass every time' do
+ expect(last_resolver.last.object_id).to eq(last_resolver.last.object_id)
+ end
+
+ it 'returns a resolver that gives the last result from the original resolver' do
+ result = resolve(last_resolver.last)
+
+ expect(result).to eq(2)
+ end
+ end
+
context 'when field is a connection' do
it 'increases complexity based on arguments' do
field = Types::BaseField.new(name: 'test', type: GraphQL::STRING_TYPE.connection_type, resolver_class: described_class, null: false, max_page_size: 1)
diff --git a/spec/graphql/resolvers/commit_pipelines_resolver_spec.rb b/spec/graphql/resolvers/commit_pipelines_resolver_spec.rb
new file mode 100644
index 00000000000..93da877d714
--- /dev/null
+++ b/spec/graphql/resolvers/commit_pipelines_resolver_spec.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Resolvers::CommitPipelinesResolver do
+ include GraphqlHelpers
+
+ let_it_be(:project) { create(:project) }
+ let(:commit) { create(:commit, project: project) }
+ let_it_be(:current_user) { create(:user) }
+
+ let!(:pipeline) do
+ create(
+ :ci_pipeline,
+ project: project,
+ sha: commit.id,
+ ref: 'master',
+ status: 'success'
+ )
+ end
+ let!(:pipeline2) do
+ create(
+ :ci_pipeline,
+ project: project,
+ sha: commit.id,
+ ref: 'master',
+ status: 'failed'
+ )
+ end
+ let!(:pipeline3) do
+ create(
+ :ci_pipeline,
+ project: project,
+ sha: commit.id,
+ ref: 'my_branch',
+ status: 'failed'
+ )
+ end
+
+ before do
+ commit.project.add_developer(current_user)
+ end
+
+ def resolve_pipelines
+ resolve(described_class, obj: commit, ctx: { current_user: current_user }, args: { ref: 'master' })
+ end
+
+ it 'resolves pipelines for commit and ref' do
+ pipelines = resolve_pipelines
+
+ expect(pipelines).to eq([pipeline2, pipeline])
+ end
+end