diff --git a/app/controllers/admin/vote_controller.rb b/app/controllers/admin/vote_controller.rb index 3a39bb2..45cbd4e 100644 --- a/app/controllers/admin/vote_controller.rb +++ b/app/controllers/admin/vote_controller.rb @@ -32,27 +32,31 @@ module Admin def approve @candidate = Candidate.find_by(test_hash: params[:test_hash]) authorize ReviewerVote.find_by(user_id: current_user.id, candidate_id: @candidate.id) - current_user.approve_candidate(@candidate) - results = { - message: "Interview requested!", - requestCopy: "Requested", - declineCopy: "Decline Interview" - } - render json: results.to_json + if current_user.approve_candidate(@candidate) + RecruiterMailer.interview_requested(@candidate).deliver_later + results = { + message: "Interview requested!", + requestCopy: "Requested", + declineCopy: "Decline Interview" + } + render json: results.to_json + end end def decline @candidate = Candidate.find_by(test_hash: params[:test_hash]) authorize ReviewerVote.find_by(user_id: current_user.id, candidate_id: @candidate.id) - current_user.decline_candidate(@candidate) - results = { - message: "Interview declined.", - requestCopy: "Request Interview", - declineCopy: "Declined" - } - render json: results.to_json + if current_user.decline_candidate(@candidate) + RecruiterMailer.interview_declined(@candidate).deliver_later + results = { + message: "Interview declined.", + requestCopy: "Request Interview", + declineCopy: "Declined" + } + render json: results.to_json + end end end end diff --git a/app/mailers/recruiter_mailer.rb b/app/mailers/recruiter_mailer.rb index 8ef985c..8d9e66c 100644 --- a/app/mailers/recruiter_mailer.rb +++ b/app/mailers/recruiter_mailer.rb @@ -3,12 +3,28 @@ class RecruiterMailer < ApplicationMailer def candidate_created candidate @candidate = candidate - mail to: @candidate.recruiter.email, subject: "Skills Assessment Test - #{candidate.name}" + mail to: @candidate.recruiter.email, + subject: "Skills Assessment Test - #{candidate.name}" end def candidate_submitted candidate @candidate = candidate - mail to: @candidate.recruiter.email, subject: "Skills Assessment Test - #{candidate.name}" + mail to: @candidate.recruiter.email, + subject: "Skills Assessment Test - #{candidate.name}" + end + + def interview_requested candidate + @candidate = candidate + + mail to: @candidate.recruiter.email, + subject: "Skills Assesment - Interview Request for #{candidate.name}" + end + + def interview_declined candidate + @candidate = candidate + + mail to: @candidate.recruiter.email, + subject: "Skills Assesment - Interview Declined for #{candidate.name}" end end diff --git a/app/views/recruiter_mailer/interview_declined.html.inky b/app/views/recruiter_mailer/interview_declined.html.inky new file mode 100644 index 0000000..1dd0d42 --- /dev/null +++ b/app/views/recruiter_mailer/interview_declined.html.inky @@ -0,0 +1,6 @@ + + + The team has declined an interview with <%= @candidate.name %>. + Thank you + + diff --git a/app/views/recruiter_mailer/interview_declined.text.erb b/app/views/recruiter_mailer/interview_declined.text.erb new file mode 100644 index 0000000..1ef40ae --- /dev/null +++ b/app/views/recruiter_mailer/interview_declined.text.erb @@ -0,0 +1,5 @@ +PERFICIENT/digital - Skills Assessment Test + +The team has declined an interview with <%= @candidate.name %>. + +Thank you. diff --git a/app/views/recruiter_mailer/interview_requested.html.inky b/app/views/recruiter_mailer/interview_requested.html.inky new file mode 100644 index 0000000..bbaa0df --- /dev/null +++ b/app/views/recruiter_mailer/interview_requested.html.inky @@ -0,0 +1,6 @@ + + + The team has requested an interview with <%= @candidate.name %>. + Thank you + + diff --git a/app/views/recruiter_mailer/interview_requested.text.erb b/app/views/recruiter_mailer/interview_requested.text.erb new file mode 100644 index 0000000..ca5d7f3 --- /dev/null +++ b/app/views/recruiter_mailer/interview_requested.text.erb @@ -0,0 +1,5 @@ +PERFICIENT/digital - Skills Assessment Test + +The team has requested an interview with <%= @candidate.name %>. + +Thank you. diff --git a/test/controllers/admin/vote_controller_test.rb b/test/controllers/admin/vote_controller_test.rb index f05e4e2..303f7d4 100644 --- a/test/controllers/admin/vote_controller_test.rb +++ b/test/controllers/admin/vote_controller_test.rb @@ -3,6 +3,8 @@ require 'test_helper' module Admin class VoteControllerTest < ActionDispatch::IntegrationTest + include ActiveJob::TestHelper + test "reviewer can up vote henry" do auth_user users(:reviewer) henry = candidates(:henry) @@ -42,18 +44,33 @@ module Admin 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 + 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) + 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 + end + assert_response :success + data = JSON.parse(response.body) + assert_match 'requested', data["message"] end end end diff --git a/test/mailers/previews/recruiter_mailer_preview.rb b/test/mailers/previews/recruiter_mailer_preview.rb index 9a14fb3..257f254 100644 --- a/test/mailers/previews/recruiter_mailer_preview.rb +++ b/test/mailers/previews/recruiter_mailer_preview.rb @@ -8,4 +8,12 @@ class RecruiterMailerPreview < ActionMailer::Preview def candidate_submitted RecruiterMailer.candidate_submitted Candidate.find_by(test_hash: 'OvP0ZqGKwJ0') # Dawn end + + def interview_requested + RecruiterMailer.interview_requested Candidate.find_by(test_hash: '6NjnourLE6Y') # Richard + end + + def interview_declined + RecruiterMailer.interview_declined Candidate.find_by(test_hash: 's6oFExZliYYFx') # Stacy + end end diff --git a/test/mailers/recruiter_mailer_test.rb b/test/mailers/recruiter_mailer_test.rb index 5331ca9..f51345f 100644 --- a/test/mailers/recruiter_mailer_test.rb +++ b/test/mailers/recruiter_mailer_test.rb @@ -19,4 +19,22 @@ class RecruiterMailerTest < ActionMailer::TestCase assert_equal [ENV["default_mail_from"]], mail.from assert_match candidate.name, mail.body.encoded end + + test "interview_requested" do + candidate = candidates :richard + mail = RecruiterMailer.interview_requested candidate + assert_match candidate.name, mail.subject + assert_equal [candidate.recruiter.email], mail.to + assert_equal [ENV["default_mail_from"]], mail.from + assert_match candidate.name, mail.body.encoded + end + + test "interview_declined" do + candidate = candidates :stacy + mail = RecruiterMailer.interview_declined candidate + assert_match candidate.name, mail.subject + assert_equal [candidate.recruiter.email], mail.to + assert_equal [ENV["default_mail_from"]], mail.from + assert_match candidate.name, mail.body.encoded + end end
The team has declined an interview with <%= @candidate.name %>.
Thank you
The team has requested an interview with <%= @candidate.name %>.