api_test.rb
2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
require_relative '../test_helper'
require_relative '../../../../test/unit/api/test_helper'
class APITest < ActiveSupport::TestCase
def setup
login_api
end
should 'return proposal ranking' do
begin
Environment.default.enable_plugin(VotePlugin)
rescue
puts 'VotePlugin not enabled'
return
end
discussion = fast_create(ProposalsDiscussionPlugin::Discussion, :profile_id => user.person.id)
topic = fast_create(ProposalsDiscussionPlugin::Topic, :profile_id => user.person.id, :parent_id => discussion.id)
proposal1 = fast_create(ProposalsDiscussionPlugin::Proposal, :profile_id => user.person.id, :parent_id => topic.id)
proposal2 = fast_create(ProposalsDiscussionPlugin::Proposal, :profile_id => user.person.id, :parent_id => topic.id)
proposal3 = fast_create(ProposalsDiscussionPlugin::Proposal, :profile_id => user.person.id, :parent_id => topic.id)
proposal2.update_attribute(:hits, 10)
10.times { Vote.create!(:voteable => proposal2, :voter => nil, :vote => 1) }
proposal3.update_attribute(:hits, 10)
2.times { Vote.create!(:voteable => proposal3, :voter => nil, :vote => 1) }
proposal1.update_attribute(:hits, 5)
get "/api/v1/proposals_discussion_plugin/#{topic.id}/ranking?#{params.to_query}"
json = JSON.parse(last_response.body)
assert_equal [proposal2.id, proposal3.id, proposal1.id], json['proposals'].map {|p| p['id']}
end
should 'suggest article children' do
discussion = fast_create(ProposalsDiscussionPlugin::Discussion, :profile_id => user.person.id)
topic = fast_create(ProposalsDiscussionPlugin::Topic, :profile_id => user.person.id, :parent_id => discussion.id)
params[:article] = {:name => "Proposal name", :abstract => "Proposal abstract", :type => 'ProposalsDiscussionPlugin::Proposal'}
assert_difference "ProposalsDiscussionPlugin::ProposalTask.count" do
post "/api/v1/proposals_discussion_plugin/#{topic.id}/propose?#{params.to_query}"
end
json = JSON.parse(last_response.body)
assert json['success']
end
end