Simplify checking attributes in GraphQL specs

Since we're obtaining titles and usernames in the response, it's easier
to compare them to titles and usernames we manually set.

Furthermore, this way we avoid many useless assignments.
This commit is contained in:
Javi Martín
2019-09-23 19:11:32 +02:00
parent bd795be80e
commit 3af958bc92

View File

@@ -133,13 +133,13 @@ describe "Consul Schema" do
describe "Proposals" do describe "Proposals" do
it "does not include hidden proposals" do it "does not include hidden proposals" do
visible_proposal = create(:proposal) create(:proposal, title: "Visible")
hidden_proposal = create(:proposal, :hidden) create(:proposal, :hidden, title: "Hidden")
response = execute("{ proposals { edges { node { title } } } }") response = execute("{ proposals { edges { node { title } } } }")
received_titles = extract_fields(response, "proposals", "title") received_titles = extract_fields(response, "proposals", "title")
expect(received_titles).to match_array [visible_proposal.title] expect(received_titles).to match_array ["Visible"]
end end
it "includes proposals of authors even if public activity is set to false" do it "includes proposals of authors even if public activity is set to false" do
@@ -156,13 +156,13 @@ describe "Consul Schema" do
end end
it "does not link author if public activity is set to false" do it "does not link author if public activity is set to false" do
visible_author = create(:user, :with_proposal, public_activity: true) create(:user, :with_proposal, username: "public", public_activity: true)
hidden_author = create(:user, :with_proposal, public_activity: false) create(:user, :with_proposal, username: "private", public_activity: false)
response = execute("{ proposals { edges { node { public_author { username } } } } }") response = execute("{ proposals { edges { node { public_author { username } } } } }")
received_authors = extract_fields(response, "proposals", "public_author.username") received_authors = extract_fields(response, "proposals", "public_author.username")
expect(received_authors).to match_array [visible_author.username] expect(received_authors).to match_array ["public"]
end end
it "only returns date and hour for created_at" do it "only returns date and hour for created_at" do
@@ -201,13 +201,13 @@ describe "Consul Schema" do
describe "Debates" do describe "Debates" do
it "does not include hidden debates" do it "does not include hidden debates" do
visible_debate = create(:debate) create(:debate, title: "Visible")
hidden_debate = create(:debate, :hidden) create(:debate, :hidden, title: "Hidden")
response = execute("{ debates { edges { node { title } } } }") response = execute("{ debates { edges { node { title } } } }")
received_titles = extract_fields(response, "debates", "title") received_titles = extract_fields(response, "debates", "title")
expect(received_titles).to match_array [visible_debate.title] expect(received_titles).to match_array ["Visible"]
end end
it "includes debates of authors even if public activity is set to false" do it "includes debates of authors even if public activity is set to false" do
@@ -224,13 +224,13 @@ describe "Consul Schema" do
end end
it "does not link author if public activity is set to false" do it "does not link author if public activity is set to false" do
visible_author = create(:user, :with_debate, public_activity: true) create(:user, :with_debate, username: "public", public_activity: true)
hidden_author = create(:user, :with_debate, public_activity: false) create(:user, :with_debate, username: "private", public_activity: false)
response = execute("{ debates { edges { node { public_author { username } } } } }") response = execute("{ debates { edges { node { public_author { username } } } } }")
received_authors = extract_fields(response, "debates", "public_author.username") received_authors = extract_fields(response, "debates", "public_author.username")
expect(received_authors).to match_array [visible_author.username] expect(received_authors).to match_array ["public"]
end end
it "only returns date and hour for created_at" do it "only returns date and hour for created_at" do
@@ -284,62 +284,62 @@ describe "Consul Schema" do
end end
it "does not link author if public activity is set to false" do it "does not link author if public activity is set to false" do
visible_author = create(:user, :with_comment, public_activity: true) create(:user, :with_comment, username: "public", public_activity: true)
hidden_author = create(:user, :with_comment, public_activity: false) create(:user, :with_comment, username: "private", public_activity: false)
response = execute("{ comments { edges { node { public_author { username } } } } }") response = execute("{ comments { edges { node { public_author { username } } } } }")
received_authors = extract_fields(response, "comments", "public_author.username") received_authors = extract_fields(response, "comments", "public_author.username")
expect(received_authors).to match_array [visible_author.username] expect(received_authors).to match_array ["public"]
end end
it "does not include hidden comments" do it "does not include hidden comments" do
visible_comment = create(:comment) create(:comment, body: "Visible")
hidden_comment = create(:comment, :hidden) create(:comment, :hidden, body: "Hidden")
response = execute("{ comments { edges { node { body } } } }") response = execute("{ comments { edges { node { body } } } }")
received_comments = extract_fields(response, "comments", "body") received_comments = extract_fields(response, "comments", "body")
expect(received_comments).to match_array [visible_comment.body] expect(received_comments).to match_array ["Visible"]
end end
it "does not include comments from hidden proposals" do it "does not include comments from hidden proposals" do
visible_proposal = create(:proposal) visible_proposal = create(:proposal)
hidden_proposal = create(:proposal, :hidden) hidden_proposal = create(:proposal, :hidden)
visible_proposal_comment = create(:comment, commentable: visible_proposal) create(:comment, commentable: visible_proposal, body: "I can see the proposal")
hidden_proposal_comment = create(:comment, commentable: hidden_proposal) create(:comment, commentable: hidden_proposal, body: "Someone hid the proposal!")
response = execute("{ comments { edges { node { body } } } }") response = execute("{ comments { edges { node { body } } } }")
received_comments = extract_fields(response, "comments", "body") received_comments = extract_fields(response, "comments", "body")
expect(received_comments).to match_array [visible_proposal_comment.body] expect(received_comments).to match_array ["I can see the proposal"]
end end
it "does not include comments from hidden debates" do it "does not include comments from hidden debates" do
visible_debate = create(:debate) visible_debate = create(:debate)
hidden_debate = create(:debate, :hidden) hidden_debate = create(:debate, :hidden)
visible_debate_comment = create(:comment, commentable: visible_debate) create(:comment, commentable: visible_debate, body: "I can see the debate")
hidden_debate_comment = create(:comment, commentable: hidden_debate) create(:comment, commentable: hidden_debate, body: "Someone hid the debate!")
response = execute("{ comments { edges { node { body } } } }") response = execute("{ comments { edges { node { body } } } }")
received_comments = extract_fields(response, "comments", "body") received_comments = extract_fields(response, "comments", "body")
expect(received_comments).to match_array [visible_debate_comment.body] expect(received_comments).to match_array ["I can see the debate"]
end end
it "does not include comments from hidden polls" do it "does not include comments from hidden polls" do
visible_poll = create(:poll) visible_poll = create(:poll)
hidden_poll = create(:poll, :hidden) hidden_poll = create(:poll, :hidden)
visible_poll_comment = create(:comment, commentable: visible_poll) create(:comment, commentable: visible_poll, body: "I can see the poll")
hidden_poll_comment = create(:comment, commentable: hidden_poll) create(:comment, commentable: hidden_poll, body: "This poll is hidden!")
response = execute("{ comments { edges { node { body } } } }") response = execute("{ comments { edges { node { body } } } }")
received_comments = extract_fields(response, "comments", "body") received_comments = extract_fields(response, "comments", "body")
expect(received_comments).to match_array [visible_poll_comment.body] expect(received_comments).to match_array ["I can see the poll"]
end end
it "does not include comments of debates that are not public" do it "does not include comments of debates that are not public" do
@@ -386,13 +386,13 @@ describe "Consul Schema" do
end end
it "does not include valuation comments" do it "does not include valuation comments" do
visible_comment = create(:comment) create(:comment, body: "Regular comment")
valuation_comment = create(:comment, :valuation) create(:comment, :valuation, body: "Valuation comment")
response = execute("{ comments { edges { node { body } } } }") response = execute("{ comments { edges { node { body } } } }")
received_comments = extract_fields(response, "comments", "body") received_comments = extract_fields(response, "comments", "body")
expect(received_comments).not_to include(valuation_comment.body) expect(received_comments).not_to include "Valuation comment"
end end
end end
@@ -413,13 +413,13 @@ describe "Consul Schema" do
visible_proposal = create(:proposal) visible_proposal = create(:proposal)
hidden_proposal = create(:proposal, :hidden) hidden_proposal = create(:proposal, :hidden)
visible_proposal_notification = create(:proposal_notification, proposal: visible_proposal) create(:proposal_notification, proposal: visible_proposal, title: "I can see the proposal")
hidden_proposal_notification = create(:proposal_notification, proposal: hidden_proposal) create(:proposal_notification, proposal: hidden_proposal, title: "Someone hid the proposal!")
response = execute("{ proposal_notifications { edges { node { title } } } }") response = execute("{ proposal_notifications { edges { node { title } } } }")
received_notifications = extract_fields(response, "proposal_notifications", "title") received_notifications = extract_fields(response, "proposal_notifications", "title")
expect(received_notifications).to match_array [visible_proposal_notification.title] expect(received_notifications).to match_array ["I can see the proposal"]
end end
it "does not include proposal notifications for proposals that are not public" do it "does not include proposal notifications for proposals that are not public" do
@@ -444,16 +444,16 @@ describe "Consul Schema" do
end end
it "only links proposal if public" do it "only links proposal if public" do
visible_proposal = create(:proposal) visible_proposal = create(:proposal, title: "Visible")
hidden_proposal = create(:proposal, :hidden) hidden_proposal = create(:proposal, :hidden, title: "Hidden")
visible_proposal_notification = create(:proposal_notification, proposal: visible_proposal) create(:proposal_notification, proposal: visible_proposal)
hidden_proposal_notification = create(:proposal_notification, proposal: hidden_proposal) create(:proposal_notification, proposal: hidden_proposal)
response = execute("{ proposal_notifications { edges { node { proposal { title } } } } }") response = execute("{ proposal_notifications { edges { node { proposal { title } } } } }")
received_proposals = extract_fields(response, "proposal_notifications", "proposal.title") received_proposals = extract_fields(response, "proposal_notifications", "proposal.title")
expect(received_proposals).to match_array [visible_proposal.title] expect(received_proposals).to match_array ["Visible"]
end end
end end