74 lines
2.2 KiB
Ruby
74 lines
2.2 KiB
Ruby
# frozen_string_literal: true
|
|
require 'test_helper'
|
|
|
|
module Admin
|
|
class CandidateControllerTest < ActionDispatch::IntegrationTest
|
|
include ActiveJob::TestHelper
|
|
|
|
test "should get new" do
|
|
auth_recruiter
|
|
get admin_new_candidate_url
|
|
assert_response :success
|
|
assert assigns(:candidate), "@candidate not present"
|
|
end
|
|
|
|
test "should get create" do
|
|
auth_recruiter
|
|
get admin_create_candidate_url
|
|
assert_response :success
|
|
end
|
|
|
|
test "should create new candidate" do
|
|
auth_recruiter
|
|
|
|
assert_enqueued_jobs 2 do
|
|
assert_difference("Candidate.count") do
|
|
post admin_create_candidate_path, params: { candidate:
|
|
{ name: 'new name', email: 'test@mailinator.com', experience: '0-3', quiz_id: quizzes(:fed).id } }
|
|
end
|
|
end
|
|
assert_redirected_to admin_candidate_path
|
|
assert flash[:success]
|
|
end
|
|
|
|
test "should fail creation with improper email format" do
|
|
auth_recruiter
|
|
|
|
assert_enqueued_jobs 0 do
|
|
assert_difference("Candidate.count", 0) do
|
|
post admin_create_candidate_path, params: { candidate:
|
|
{ name: 'new name', email: 'test@mailinatorcom', experience: '0-3', quiz_id: quizzes(:fed).id } }
|
|
end
|
|
end
|
|
assert :success
|
|
assert assigns(:candidate), "@candidate not present"
|
|
assert_match(/failed.*save/i, flash[:error])
|
|
end
|
|
|
|
test "should fail creation gracefully with empty email" do
|
|
auth_recruiter
|
|
|
|
assert_enqueued_jobs 0 do
|
|
assert_difference("Candidate.count", 0) do
|
|
post admin_create_candidate_path, params: { candidate:
|
|
{ name: 'new name', email: "", experience: '0-3', quiz_id: quizzes(:fed).id } }
|
|
end
|
|
end
|
|
assert :success
|
|
assert assigns(:candidate), "@candidate not present"
|
|
assert_match(/failed.*save/i, flash[:error])
|
|
end
|
|
|
|
test 'should queue up a welcome email [resend]' do
|
|
auth_recruiter
|
|
|
|
assert_enqueued_jobs 1 do
|
|
get admin_resend_welcome_path(id: candidates(:peggy)), xhr: true
|
|
end
|
|
assert_response :success
|
|
data = JSON.parse(response.body)
|
|
assert_match 'queued', data["message"]
|
|
end
|
|
end
|
|
end
|