2016-11-19 16:34:48 -06:00
|
|
|
# frozen_string_literal: true
|
|
|
|
require 'test_helper'
|
|
|
|
|
|
|
|
module Admin
|
|
|
|
class VoteControllerTest < ActionDispatch::IntegrationTest
|
2016-11-30 18:55:27 -06:00
|
|
|
include ActiveJob::TestHelper
|
|
|
|
|
2016-11-19 16:34:48 -06:00
|
|
|
test "reviewer can up vote henry" do
|
2017-02-27 13:41:46 -06:00
|
|
|
auth_user users(:reviewer2)
|
2016-11-19 16:34:48 -06:00
|
|
|
henry = candidates(:henry)
|
|
|
|
|
|
|
|
assert_difference("Candidate.find(#{henry.id}).votes.yea.count", 1) do
|
|
|
|
get admin_up_vote_url(henry.test_hash)
|
|
|
|
end
|
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
|
|
|
|
test "reviewer can down vote henry" do
|
2017-02-27 13:41:46 -06:00
|
|
|
auth_user users(:reviewer2)
|
2016-11-19 16:34:48 -06:00
|
|
|
henry = candidates(:henry)
|
|
|
|
|
|
|
|
assert_difference("Candidate.find(#{henry.id}).votes.nay.count", 1) do
|
|
|
|
get admin_down_vote_url(henry.test_hash)
|
|
|
|
end
|
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
|
|
|
|
test "reviewer can change vote on henry" do
|
2017-02-27 13:41:46 -06:00
|
|
|
auth_user users(:reviewer2)
|
2016-11-19 16:34:48 -06:00
|
|
|
henry = candidates(:henry)
|
|
|
|
get admin_up_vote_url(henry.test_hash)
|
|
|
|
|
2016-11-20 09:51:46 -06:00
|
|
|
assert_difference("Candidate.find(#{henry.id}).votes.yea.count", -1) do
|
|
|
|
assert_difference("Candidate.find(#{henry.id}).votes.nay.count", 1) do
|
|
|
|
get admin_down_vote_url(henry.test_hash)
|
|
|
|
end
|
2016-11-19 16:34:48 -06:00
|
|
|
end
|
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
|
|
|
|
test "manager can approve henry" do
|
|
|
|
auth_user users(:manager)
|
|
|
|
henry = candidates(:henry)
|
|
|
|
get admin_approve_vote_url(henry.test_hash)
|
|
|
|
|
|
|
|
assert_equal 1, henry.votes.approved.count
|
2016-11-30 18:55:27 -06:00
|
|
|
assert_equal 'approved', Candidate.find(henry.to_i).review_status, xhr: true
|
2016-11-19 16:34:48 -06:00
|
|
|
assert_response :success
|
2016-11-30 18:55:27 -06:00
|
|
|
data = JSON.parse(response.body)
|
|
|
|
assert_match 'requested', data["message"]
|
2016-11-19 16:34:48 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "manager can decline henry" do
|
|
|
|
auth_user users(:manager)
|
|
|
|
henry = candidates(:henry)
|
2016-11-30 18:55:27 -06:00
|
|
|
get admin_decline_vote_url(henry.test_hash), xhr: true
|
2016-11-19 16:34:48 -06:00
|
|
|
|
|
|
|
assert_equal 1, henry.votes.rejected.count
|
|
|
|
assert_equal 'declined', Candidate.find(henry.to_i).review_status
|
|
|
|
assert_response :success
|
2016-11-30 18:55:27 -06:00
|
|
|
data = JSON.parse(response.body)
|
|
|
|
assert_match 'declined', data["message"]
|
|
|
|
end
|
|
|
|
|
|
|
|
test "should queue up a notification when manager approves henry" do
|
|
|
|
auth_user users(:manager)
|
|
|
|
henry = candidates(:henry)
|
|
|
|
assert_enqueued_jobs 1 do
|
|
|
|
get admin_approve_vote_url(henry.test_hash), xhr: true
|
|
|
|
end
|
|
|
|
assert_response :success
|
|
|
|
data = JSON.parse(response.body)
|
|
|
|
assert_match 'requested', data["message"]
|
2016-11-19 16:34:48 -06:00
|
|
|
end
|
2017-02-27 13:41:46 -06:00
|
|
|
|
|
|
|
test "reviewer can only vote after commenting" do
|
|
|
|
auth_user users(:reviewer)
|
|
|
|
henry = candidates(:henry)
|
|
|
|
|
|
|
|
assert_difference("Candidate.find(#{henry.id}).votes.yea.count", 0) do
|
|
|
|
get admin_up_vote_url(henry.test_hash)
|
|
|
|
end
|
|
|
|
|
|
|
|
post admin_create_comment_url(test_hash: henry.test_hash),
|
|
|
|
params: { quiz_comment: { message: 'this is a comment to vote' } }
|
|
|
|
|
|
|
|
assert_difference("Candidate.find(#{henry.id}).votes.yea.count", 1) do
|
|
|
|
get admin_up_vote_url(henry.test_hash)
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_response :success
|
|
|
|
end
|
2016-11-19 16:34:48 -06:00
|
|
|
end
|
|
|
|
end
|