Improved code coverage for GraphQL resolvers specs

This commit is contained in:
Alberto Miedes Garcés
2017-01-09 10:14:31 +01:00
parent e1b3d468e5
commit 60786f17c2
3 changed files with 35 additions and 18 deletions

View File

@@ -2,13 +2,14 @@ require 'rails_helper'
describe GraphQL::RootElementResolver do
let(:comment_resolver) { GraphQL::RootElementResolver.new(Comment) }
let(:geozone_resolver) { GraphQL::RootElementResolver.new(Geozone) }
describe '#call' do
it 'resolves simple elements' do
comment = create(:comment)
arguments = { 'id' => comment.id }
result = comment_resolver.call(nil, arguments, nil)
result = comment_resolver.call(nil, {'id' => comment.id}, nil)
expect(result).to eq(comment)
end
@@ -16,20 +17,28 @@ describe GraphQL::RootElementResolver do
it 'returns nil when requested element is forbidden' do
proposal = create(:proposal, :hidden)
comment = create(:comment, commentable: proposal)
arguments = { 'id' => comment.id }
result = comment_resolver.call(nil, arguments, nil)
result = comment_resolver.call(nil, {'id' => comment.id}, nil)
expect(result).to be_nil
end
it 'returns nil when requested element does not exist' do
arguments = { 'id' => 1 }
result = comment_resolver.call(nil, arguments, nil)
result = comment_resolver.call(nil, {'id' => 1}, nil)
expect(result).to be_nil
end
it 'uses the public_for_api scope when available' do
geozone = create(:geozone)
comment = create(:comment, commentable: create(:proposal, :hidden))
geozone_result = geozone_resolver.call(nil, {'id' => geozone.id}, nil)
comment_result = comment_resolver.call(nil, {'id' => comment.id}, nil)
expect(geozone_result).to eq(geozone)
expect(comment_result).to be_nil
end
end
end