Rewrote tests to tackle more specific stuff
This commit is contained in:
@@ -5,16 +5,62 @@ describe ConsulSchema do
|
|||||||
let(:variables) { {} }
|
let(:variables) { {} }
|
||||||
let(:result) { ConsulSchema.execute(query_string, context: context, variables: variables) }
|
let(:result) { ConsulSchema.execute(query_string, context: context, variables: variables) }
|
||||||
|
|
||||||
describe "answers simple queries" do
|
describe "queries to single elements" do
|
||||||
let(:query_string) { "{ proposals { edges { node { title } } } }" }
|
let(:proposal) { create(:proposal, title: 'Proposal Title') }
|
||||||
let(:context) {
|
let(:query_string) { "{ proposal(id: #{proposal.id}) { id, title } }" }
|
||||||
{ proposal: create(:proposal, title: "A new proposal") }
|
|
||||||
}
|
|
||||||
|
|
||||||
it "can return proposal titles" do
|
it "returns fields of numeric type" do
|
||||||
proposals = result["data"]["proposals"]["edges"].collect { |edge| edge['node'] }
|
returned_proposal = result['data']['proposal']
|
||||||
expect(proposals.size).to eq(1)
|
expect(returned_proposal['id']).to eq(proposal.id)
|
||||||
expect(proposals.first['title']).to eq("A new proposal")
|
end
|
||||||
|
|
||||||
|
it "returns fields of String type" do
|
||||||
|
returned_proposal = result['data']['proposal']
|
||||||
|
expect(returned_proposal['title']).to eq('Proposal Title')
|
||||||
|
end
|
||||||
|
|
||||||
|
describe "supports nested queries" do
|
||||||
|
it "with :has_one associations" do
|
||||||
|
skip "I think this test isn't needed"
|
||||||
|
# TODO: the only has_one associations inside the project are in the User
|
||||||
|
# model (administrator, valuator, etc.). But since I think this data
|
||||||
|
# shouldn't be exposed to the API, there's no point in testing this.
|
||||||
|
#
|
||||||
|
# user = create(:user)
|
||||||
|
# admin = create(:administrator)
|
||||||
|
# user.administrator = admin
|
||||||
|
# query_string = "{ user(id: #{user.id}) { administrator { id } } }"
|
||||||
|
#
|
||||||
|
# result = ConsulSchema.execute(query_string, context: {}, variables: {})
|
||||||
|
# returned_admin = result['data']['user']['administrator']
|
||||||
|
#
|
||||||
|
# expect(returned_admin.id).to eq(admin.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "with :belongs_to associations" do
|
||||||
|
user = create(:user)
|
||||||
|
proposal = create(:proposal, author: user)
|
||||||
|
query_string = "{ proposal(id: #{proposal.id}) { author { username } } }"
|
||||||
|
|
||||||
|
result = ConsulSchema.execute(query_string, context: {}, variables: {})
|
||||||
|
returned_proposal = result['data']['proposal']
|
||||||
|
|
||||||
|
expect(returned_proposal['author']['username']).to eq(user.username)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "with :has_many associations" do
|
||||||
|
user = create(:user)
|
||||||
|
proposal = create(:proposal)
|
||||||
|
create(:comment, body: "Blah Blah", author: user, commentable: proposal)
|
||||||
|
create(:comment, body: "I told ya", author: user, commentable: proposal)
|
||||||
|
query_string = "{ proposal(id: #{proposal.id}) { comments { edges { node { body } } } } }"
|
||||||
|
|
||||||
|
result = ConsulSchema.execute(query_string, context: {}, variables: {})
|
||||||
|
comments = result['data']['proposal']['comments']['edges'].collect { |edge| edge['node'] }
|
||||||
|
comment_bodies = comments.collect { |comment| comment['body'] }
|
||||||
|
|
||||||
|
expect(comment_bodies).to match_array(["Blah Blah", "I told ya"])
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user