refactored approval system - now with comments
This commit is contained in:
@ -5,6 +5,24 @@ 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
|
||||
|
||||
test "reviewer can up vote henry" do
|
||||
auth_user users(:reviewer2)
|
||||
henry = candidates(:henry)
|
||||
@ -38,57 +56,19 @@ module Admin
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "manager can approve henry" do
|
||||
test "manager can approve henry and notify recruiter" do
|
||||
auth_user users(:manager)
|
||||
henry = candidates(:henry)
|
||||
get admin_approve_vote_url(henry.test_hash)
|
||||
|
||||
assert_equal 1, henry.votes.approved.count
|
||||
assert_equal 'approved', Candidate.find(henry.to_i).review_status, xhr: true
|
||||
assert_response :success
|
||||
data = JSON.parse(response.body)
|
||||
assert_match 'requested', data["message"]
|
||||
end
|
||||
|
||||
test "manager can decline henry" do
|
||||
auth_user users(:manager)
|
||||
henry = candidates(:henry)
|
||||
get admin_decline_vote_url(henry.test_hash), xhr: true
|
||||
|
||||
assert_equal 1, henry.votes.rejected.count
|
||||
assert_equal 'declined', Candidate.find(henry.to_i).review_status
|
||||
assert_response :success
|
||||
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
|
||||
post admin_interview_url(henry.test_hash), params: {
|
||||
review_status: 'approved',
|
||||
review_comments: 'ipsum'
|
||||
}
|
||||
end
|
||||
assert_response :success
|
||||
data = JSON.parse(response.body)
|
||||
assert_match 'requested', data["message"]
|
||||
end
|
||||
|
||||
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
|
||||
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
|
||||
end
|
||||
end
|
||||
|
Reference in New Issue
Block a user