adds poll comments to API

This commit is contained in:
Juanjo Bazán
2017-11-21 14:31:03 +01:00
parent ae71f4960b
commit 21b2a11339
3 changed files with 32 additions and 4 deletions

View File

@@ -282,15 +282,16 @@ describe 'ConsulSchema' do
end
describe 'Comments' do
it 'only returns comments from proposals and debates' do
it 'only returns comments from proposals, debates and polls' do
proposal_comment = create(:comment, commentable: create(:proposal))
debate_comment = create(:comment, commentable: create(:debate))
poll_comment = create(:comment, commentable: create(:poll))
spending_proposal_comment = build(:comment, commentable: create(:spending_proposal)).save(skip_validation: true)
response = execute('{ comments { edges { node { commentable_type } } } }')
received_commentables = extract_fields(response, 'comments', 'commentable_type')
expect(received_commentables).to match_array ['Proposal', 'Debate']
expect(received_commentables).to match_array ['Proposal', 'Debate', 'Poll']
end
it 'displays comments of authors even if public activity is set to false' do
@@ -355,6 +356,19 @@ describe 'ConsulSchema' do
expect(received_comments).to match_array [visible_debate_comment.body]
end
it 'does not include comments from hidden polls' do
visible_poll = create(:poll)
hidden_poll = create(:poll, hidden_at: Time.current)
visible_poll_comment = create(:comment, commentable: visible_poll)
hidden_poll_comment = create(:comment, commentable: hidden_poll)
response = execute('{ comments { edges { node { body } } } }')
received_comments = extract_fields(response, 'comments', 'body')
expect(received_comments).to match_array [visible_poll_comment.body]
end
it 'does not include comments of debates that are not public' do
not_public_debate = create(:debate, :hidden)
not_public_debate_comment = create(:comment, commentable: not_public_debate)
@@ -377,6 +391,17 @@ describe 'ConsulSchema' do
expect(received_comments).to_not include(not_public_proposal_comment.body)
end
it 'does not include comments of polls that are not public' do
not_public_poll = create(:poll)
not_public_poll_comment = create(:comment, commentable: not_public_poll)
allow(Comment).to receive(:public_for_api).and_return([])
response = execute('{ comments { edges { node { body } } } }')
received_comments = extract_fields(response, 'comments', 'body')
expect(received_comments).to_not include(not_public_poll_comment.body)
end
it 'only returns date and hour for created_at' do
created_at = Time.zone.parse("2017-12-31 9:30:15")
create(:comment, created_at: created_at)