Commit 7be1f084 authored by Lin Jen-Shin's avatar Lin Jen-Shin

Add tests for BaseResolver and update accordingly

parent 91e9e50a
# 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
...@@ -16,9 +16,17 @@ describe Resolvers::MergeRequestsResolver do ...@@ -16,9 +16,17 @@ describe Resolvers::MergeRequestsResolver do
let(:other_iid) { other_merge_request.iid } let(:other_iid) { other_merge_request.iid }
describe '#resolve' do 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 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 end
expect(result).to contain_exactly(merge_request_1, merge_request_2) expect(result).to contain_exactly(merge_request_1, merge_request_2)
...@@ -26,22 +34,28 @@ describe Resolvers::MergeRequestsResolver do ...@@ -26,22 +34,28 @@ describe Resolvers::MergeRequestsResolver do
it 'can batch-resolve merge requests from different projects' do it 'can batch-resolve merge requests from different projects' do
result = batch(max_queries: 3) do result = batch(max_queries: 3) do
resolve_mr(project, iid_1) + resolve_mr(project, iid: iid_1) +
resolve_mr(project, iid_2) + resolve_mr(project, iid: iid_2) +
resolve_mr(other_project, other_iid) resolve_mr(other_project, iid: other_iid)
end end
expect(result).to contain_exactly(merge_request_1, merge_request_2, other_merge_request) expect(result).to contain_exactly(merge_request_1, merge_request_2, other_merge_request)
end end
it 'resolves an unknown iid to nil' do it 'resolves an unknown iid to be empty' do
result = batch { resolve_mr(project, -1) } 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 expect(result).to be_empty
end end
end end
def resolve_mr(project, iid) def resolve_mr(project, args)
resolve(described_class, obj: project, args: { iid: iid }) resolve(described_class, obj: project, args: args)
end end
end end
...@@ -6,12 +6,17 @@ describe GitlabSchema.types['Project'] do ...@@ -6,12 +6,17 @@ describe GitlabSchema.types['Project'] do
it { expect(described_class.graphql_name).to eq('Project') } it { expect(described_class.graphql_name).to eq('Project') }
describe 'nested merge request' do describe 'nested merge request' do
it { expect(described_class).to have_graphql_field(:merge_requests) }
it { expect(described_class).to have_graphql_field(:merge_request) } it { expect(described_class).to have_graphql_field(:merge_request) }
it 'authorizes the merge request' do it 'authorizes the merge request' do
expect(described_class.fields['mergeRequest']) expect(described_class.fields['mergeRequest'])
.to require_graphql_authorizations(:read_merge_request) .to require_graphql_authorizations(:read_merge_request)
end end
it 'authorizes the merge requests' do
skip
end
end end
describe 'nested issues' do describe 'nested issues' do
......
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