skill-assessment-app/test/controllers/admin/vote_controller_test.rb

86 lines
2.6 KiB
Ruby
Raw Normal View History

2016-11-19 16:34:48 -06:00
# frozen_string_literal: true
require 'test_helper'
module Admin
class VoteControllerTest < ActionDispatch::IntegrationTest
include ActiveJob::TestHelper
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
test "reviewer can up vote henry" do
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
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
auth_user users(:reviewer2)
2016-11-19 16:34:48 -06:00
henry = candidates(:henry)
get admin_up_vote_url(henry.test_hash)
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 and notify recruiter" do
2016-11-19 16:34:48 -06:00
auth_user users(:manager)
henry = candidates(:henry)
assert_enqueued_jobs 1 do
post admin_interview_url(henry.test_hash), params: {
review_status: 'approved',
review_comments: 'ipsum'
}
end
assert_equal 'approved', Candidate.find(henry.to_i).review_status
assert_equal 'ipsum', Candidate.find(henry.to_i).review_comments
assert_redirected_to admin_result_url(henry.test_hash)
end
2017-03-07 16:35:59 -06:00
test "approve fails without comment" do
auth_user users(:manager)
henry = candidates(:henry)
assert_enqueued_jobs 0 do
post admin_interview_url(henry.test_hash), params: { review_status: 'approved' }
end
assert_match 'comment', flash[:error]
assert_redirected_to admin_result_url(henry.test_hash)
end
2016-11-19 16:34:48 -06:00
end
end