Wrote specs for QueryType creation

This commit is contained in:
Alberto Miedes Garcés
2017-01-08 12:45:48 +01:00
parent 7027164867
commit b9d2bc2801
3 changed files with 72 additions and 37 deletions

View File

@@ -1,7 +1,40 @@
require 'rails_helper'
describe GraphQL::TypeCreator do
let(:type_creator) { GraphQL::TypeCreator.new({}) }
let(:api_type_definitions) { {} }
let(:type_creator) { GraphQL::TypeCreator.new(api_type_definitions) }
describe "::query_type" do
let(:api_type_definitions) do
{
ProposalNotification => { fields: { title: 'string' } },
Proposal => { fields: { id: 'integer', title: 'string' } }
}
end
let(:query_type) { type_creator.query_type }
it 'has fields to retrieve single objects whose model fields included an ID' do
field = query_type.fields['proposal']
proposal_type = type_creator.created_types[Proposal]
expect(field).to be_a(GraphQL::Field)
expect(field.type).to eq(proposal_type)
expect(field.name).to eq('proposal')
end
it 'does not have fields to retrieve single objects whose model fields did not include an ID' do
expect(query_type.fields['proposal_notification']).to be_nil
end
it "has connections to retrieve collections of objects" do
connection = query_type.fields['proposals']
proposal_type = type_creator.created_types[Proposal]
expect(connection).to be_a(GraphQL::Field)
expect(connection.type).to eq(proposal_type.connection_type)
expect(connection.name).to eq('proposals')
end
end
describe "::create_type" do
it "creates fields for Int attributes" do