diff options
author | Lin Jen-Shin <godfat@godfat.org> | 2019-02-12 21:51:10 +0800 |
---|---|---|
committer | Lin Jen-Shin <godfat@godfat.org> | 2019-02-14 15:52:17 +0800 |
commit | 7be1f0842f281305f2c36e2b6066842d8e87875c (patch) | |
tree | c66b947afbfca033411960b10ab1647d0a6932d1 /spec/graphql/resolvers | |
parent | 91e9e50a1153021257abaa528498d7a82cc3350f (diff) | |
download | gitlab-ce-7be1f0842f281305f2c36e2b6066842d8e87875c.tar.gz |
Add tests for BaseResolver and update accordingly
Diffstat (limited to 'spec/graphql/resolvers')
-rw-r--r-- | spec/graphql/resolvers/base_resolver_spec.rb | 31 | ||||
-rw-r--r-- | spec/graphql/resolvers/merge_requests_resolver_spec.rb | 32 |
2 files changed, 54 insertions, 9 deletions
diff --git a/spec/graphql/resolvers/base_resolver_spec.rb b/spec/graphql/resolvers/base_resolver_spec.rb new file mode 100644 index 00000000000..e3a34762b62 --- /dev/null +++ b/spec/graphql/resolvers/base_resolver_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Resolvers::BaseResolver do + include GraphqlHelpers + + let(:resolver) do + Class.new(described_class) do + def resolve(**args) + [args, args] + end + end + end + + describe '.single' do + it 'returns a subclass from the resolver' do + expect(resolver.single.superclass).to eq(resolver) + end + + it 'returns the same subclass every time' do + expect(resolver.single.object_id).to eq(resolver.single.object_id) + end + + it 'returns a resolver that gives the first result from the original resolver' do + result = resolve(resolver.single, args: { test: 1 }) + + expect(result).to eq(test: 1) + end + end +end diff --git a/spec/graphql/resolvers/merge_requests_resolver_spec.rb b/spec/graphql/resolvers/merge_requests_resolver_spec.rb index 782a530e6f7..ab3c426b2cd 100644 --- a/spec/graphql/resolvers/merge_requests_resolver_spec.rb +++ b/spec/graphql/resolvers/merge_requests_resolver_spec.rb @@ -16,9 +16,17 @@ describe Resolvers::MergeRequestsResolver do let(:other_iid) { other_merge_request.iid } describe '#resolve' do - it 'batch-resolves merge requests by target project full path and IID' do + it 'batch-resolves by target project full path and individual IID' do result = batch(max_queries: 2) do - resolve_mr(project, iid_1) + resolve_mr(project, iid_2) + resolve_mr(project, iid: iid_1) + resolve_mr(project, iid: iid_2) + end + + expect(result).to contain_exactly(merge_request_1, merge_request_2) + end + + it 'batch-resolves by target project full path and IIDS' do + result = batch(max_queries: 2) do + resolve_mr(project, iids: [iid_1, iid_2]) end expect(result).to contain_exactly(merge_request_1, merge_request_2) @@ -26,22 +34,28 @@ describe Resolvers::MergeRequestsResolver do it 'can batch-resolve merge requests from different projects' do result = batch(max_queries: 3) do - resolve_mr(project, iid_1) + - resolve_mr(project, iid_2) + - resolve_mr(other_project, other_iid) + resolve_mr(project, iid: iid_1) + + resolve_mr(project, iid: iid_2) + + resolve_mr(other_project, iid: other_iid) end expect(result).to contain_exactly(merge_request_1, merge_request_2, other_merge_request) end - it 'resolves an unknown iid to nil' do - result = batch { resolve_mr(project, -1) } + it 'resolves an unknown iid to be empty' do + result = batch { resolve_mr(project, iid: -1) } + + expect(result).to be_empty + end + + it 'resolves empty iids to be empty' do + result = batch { resolve_mr(project, iids: []) } expect(result).to be_empty end end - def resolve_mr(project, iid) - resolve(described_class, obj: project, args: { iid: iid }) + def resolve_mr(project, args) + resolve(described_class, obj: project, args: args) end end |