Started GraphQL::TypeCreator testing
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
API_TYPE_DEFINITIONS = {
|
||||
User => %I[ id username proposals ],
|
||||
Debate => %I[ id title description author_id author created_at ],
|
||||
Proposal => %I[ id title description author_id author created_at ]
|
||||
Proposal => %I[ id title description author_id author created_at ],
|
||||
Comment => %I[ id body author_id author commentable_id commentable]
|
||||
}
|
||||
|
||||
api_types = {}
|
||||
|
||||
68
spec/lib/graphql_spec.rb
Normal file
68
spec/lib/graphql_spec.rb
Normal file
@@ -0,0 +1,68 @@
|
||||
require 'rails_helper'
|
||||
|
||||
describe GraphQL::TypeCreator do
|
||||
let!(:api_types) { {} }
|
||||
let!(:user_type) { GraphQL::TypeCreator.create(User, %I[ id ], api_types) }
|
||||
let!(:comment_type) { GraphQL::TypeCreator.create(Comment, %I[ id ], api_types) }
|
||||
let!(:debate_type) { GraphQL::TypeCreator.create(Debate, %I[ id title author ], api_types) }
|
||||
# TODO: no puedo añadir los comentarios a la field_list de Debate porque como
|
||||
# las conexiones se crean de forma lazy creo que provoca que falle la creación
|
||||
# del resto de tipos y provoca que fallen todos los tests.
|
||||
# let!(:debate_type) { GraphQL::TypeCreator.create(Debate, %I[ id title author comments ], api_types) }
|
||||
|
||||
describe "::create" do
|
||||
describe "creates fields" do
|
||||
it "for int attributes" do
|
||||
created_field = debate_type.fields['id']
|
||||
|
||||
expect(created_field).to be_a(GraphQL::Field)
|
||||
expect(created_field.type).to be_a(GraphQL::ScalarType)
|
||||
expect(created_field.type.name).to eq('Int')
|
||||
end
|
||||
|
||||
it "for string attributes" do
|
||||
created_field = debate_type.fields['title']
|
||||
|
||||
expect(created_field).to be_a(GraphQL::Field)
|
||||
expect(created_field.type).to be_a(GraphQL::ScalarType)
|
||||
expect(created_field.type.name).to eq('String')
|
||||
end
|
||||
end
|
||||
|
||||
describe "creates connections for" do
|
||||
it ":belongs_to associations" do
|
||||
connection = debate_type.fields['author']
|
||||
|
||||
# TODO: because connection types are created and added lazily to the
|
||||
# api_types hash (with that proc thing ->) I don't really know how to
|
||||
# test this.
|
||||
# connection.class shows GraphQL::Field
|
||||
# connection.inspect shows some weird info
|
||||
|
||||
expect(connection).to be_a(GraphQL::Field)
|
||||
# expect(connection.type).to be_a(api_types[User])
|
||||
expect(connection.name).to eq('author')
|
||||
end
|
||||
|
||||
it ":has_one associations" do
|
||||
skip "need to find association example that uses :has_one"
|
||||
end
|
||||
|
||||
it ":has_many associations" do
|
||||
skip "still don't know how to handle relay connections inside RSpec"
|
||||
|
||||
connection = debate_type.fields['comments']
|
||||
|
||||
# TODO: because connection types are created and added lazily to the
|
||||
# api_types hash (with that proc thing ->) I don't really know how to
|
||||
# test this.
|
||||
# connection.class shows GraphQL::Field
|
||||
# connection.inspect shows some weird info
|
||||
|
||||
expect(connection).to be_a(GraphQL::Field)
|
||||
# expect(created_connection.type).to be_a(api_types[Comment])
|
||||
expect(connection.name).to eq('comments')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user