From e74f7163b68597a12eef75908c6036fce6f4fd3c Mon Sep 17 00:00:00 2001 From: Thomas Leese Date: Wed, 27 Mar 2024 08:10:37 +0000 Subject: [PATCH] Add resend referee email feature This adds a new feature when verifying references that allows users to resend the initial reference requested email without needing to change the email address. --- .../reference_requests_controller.rb | 20 ++++- .../reference_request_policy.rb | 4 + .../reference_requests/edit_verify.html.erb | 7 ++ config/routes.rb | 1 + spec/factories/assessments.rb | 6 -- spec/factories/reference_requests.rb | 32 -------- .../reference_request_policy_spec.rb | 6 ++ .../verify_reference_request.rb | 5 ++ .../verifying_references_spec.rb | 74 +++++++++++++++++-- 9 files changed, 110 insertions(+), 45 deletions(-) diff --git a/app/controllers/assessor_interface/reference_requests_controller.rb b/app/controllers/assessor_interface/reference_requests_controller.rb index 8bcfecfb6d..7d417ba419 100644 --- a/app/controllers/assessor_interface/reference_requests_controller.rb +++ b/app/controllers/assessor_interface/reference_requests_controller.rb @@ -5,6 +5,7 @@ class ReferenceRequestsController < BaseController include HistoryTrackable before_action :set_individual_variables, except: :index + skip_before_action :track_history, only: :resend_email define_history_origin :index @@ -99,8 +100,8 @@ def update_verify_failed if @form.save redirect_to [ :assessor_interface, - requestable.application_form, - requestable.assessment, + application_form, + assessment, :reference_requests, ] else @@ -108,6 +109,21 @@ def update_verify_failed end end + def resend_email + if reference_request.requested? && !reference_request.received? + RefereeMailer.with(reference_request:).reference_requested.deliver_later + flash[:info] = "The reference requested email has been resent." + end + + redirect_to [ + :verify, + :assessor_interface, + application_form, + assessment, + reference_request, + ] + end + private def set_individual_variables diff --git a/app/policies/assessor_interface/reference_request_policy.rb b/app/policies/assessor_interface/reference_request_policy.rb index d3e673f953..3faee75252 100644 --- a/app/policies/assessor_interface/reference_request_policy.rb +++ b/app/policies/assessor_interface/reference_request_policy.rb @@ -25,4 +25,8 @@ def update_verify_failed? end alias_method :edit_verify_failed?, :update_verify_failed? + + def resend_email? + user.assess_permission || user.verify_permission + end end diff --git a/app/views/assessor_interface/reference_requests/edit_verify.html.erb b/app/views/assessor_interface/reference_requests/edit_verify.html.erb index f891ced85c..eb13f30c7d 100644 --- a/app/views/assessor_interface/reference_requests/edit_verify.html.erb +++ b/app/views/assessor_interface/reference_requests/edit_verify.html.erb @@ -1,6 +1,7 @@ <% work_history = @reference_request.work_history %> <% can_edit_work_history = policy([:assessor_interface, work_history]).edit? %> <% can_update_verify_reference_request = @assessment.verify? && policy([:assessor_interface, @reference_request]).update_verify? %> +<% can_resend_email_reference_request = @assessment.verify? && policy([:assessor_interface, @reference_request]).resend_email? %> <% title = can_update_verify_reference_request ? "Review reference" : "View reference" %> @@ -55,6 +56,12 @@ <% end %> <%= render "shared/reference_request_summary", reference_request: @reference_request, changeable: false %> + <% elsif @reference_request.requested? && can_resend_email_reference_request %> + <%= govuk_details(summary_text: "Resend email to referee") do %> + <%= govuk_warning_text(text: "Only use this if a request has been made to resend the reference.") %> + <%= govuk_button_link_to "Resend reference request email", [:resend_email, :assessor_interface, @application_form, @assessment, @reference_request] %> +

Reminders are sent automatically 4 weeks and 2 weeks before the reference goes overdue.

+ <% end %> <% end %> <% if @reference_request.expired? %> diff --git a/config/routes.rb b/config/routes.rb index 9051b5d2be..ab707b1d34 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -190,6 +190,7 @@ post "verify", to: "reference_requests#update_verify" get "verify-failed", to: "reference_requests#edit_verify_failed" post "verify-failed", to: "reference_requests#update_verify_failed" + get "resend-email", to: "reference_requests#resend_email" end end end diff --git a/spec/factories/assessments.rb b/spec/factories/assessments.rb index ec2e91e61f..010d8525c7 100644 --- a/spec/factories/assessments.rb +++ b/spec/factories/assessments.rb @@ -105,12 +105,6 @@ end end - trait :with_received_professional_standing_request do - after(:create) do |assessment, _evaluator| - create(:professional_standing_request, :received, assessment:) - end - end - trait :with_reference_requests do after(:create) do |assessment, _evaluator| assessment.application_form.work_histories.each do |work_history| diff --git a/spec/factories/reference_requests.rb b/spec/factories/reference_requests.rb index 4c2de47a36..00d016c012 100644 --- a/spec/factories/reference_requests.rb +++ b/spec/factories/reference_requests.rb @@ -139,37 +139,5 @@ additional_information_response { Faker::Lorem.sentence } end - - trait :responses_invalid do - contact_response { false } - contact_name { Faker::Name.name } - contact_job { Faker::Job.title } - contact_comment { Faker::Lorem.sentence } - dates_response { false } - dates_comment { Faker::Lorem.sentence } - hours_response { false } - hours_comment { Faker::Lorem.sentence } - children_response { false } - children_comment { Faker::Lorem.sentence } - lessons_response { false } - lessons_comment { Faker::Lorem.sentence } - reports_response { false } - reports_comment { Faker::Lorem.sentence } - misconduct_response { true } - misconduct_comment { Faker::Lorem.sentence } - satisfied_response { false } - satisfied_comment { Faker::Lorem.sentence } - end - - trait :responses_valid do - contact_response { true } - dates_response { true } - hours_response { true } - children_response { true } - lessons_response { true } - reports_response { true } - misconduct_response { false } - satisfied_response { true } - end end end diff --git a/spec/policies/assessor_interface/reference_request_policy_spec.rb b/spec/policies/assessor_interface/reference_request_policy_spec.rb index 5d09a92d77..d8ce26440f 100644 --- a/spec/policies/assessor_interface/reference_request_policy_spec.rb +++ b/spec/policies/assessor_interface/reference_request_policy_spec.rb @@ -62,6 +62,12 @@ it_behaves_like "a policy method requiring the verify permission" end + describe "#resend_email?" do + subject(:resend_email?) { policy.resend_email? } + it_behaves_like "a policy method requiring the assess permission" + it_behaves_like "a policy method requiring the verify permission" + end + describe "#destroy?" do subject(:destroy?) { policy.destroy? } it_behaves_like "a policy method without permission" diff --git a/spec/support/autoload/page_objects/assessor_interface/verify_reference_request.rb b/spec/support/autoload/page_objects/assessor_interface/verify_reference_request.rb index 3b41e26ade..5bf2e0a0c7 100644 --- a/spec/support/autoload/page_objects/assessor_interface/verify_reference_request.rb +++ b/spec/support/autoload/page_objects/assessor_interface/verify_reference_request.rb @@ -13,6 +13,11 @@ class VerifyReferenceRequest < VerifyRequestablePage elements :keys, ".govuk-summary-list__key" elements :values, ".govuk-summary-list__value" end + + section :send_email_details, ".govuk-details" do + element :summary, ".govuk-details__summary" + element :button, ".govuk-button" + end end end end diff --git a/spec/system/assessor_interface/verifying_references_spec.rb b/spec/system/assessor_interface/verifying_references_spec.rb index 0c0efa5b68..050d97211f 100644 --- a/spec/system/assessor_interface/verifying_references_spec.rb +++ b/spec/system/assessor_interface/verifying_references_spec.rb @@ -9,7 +9,38 @@ given_there_is_an_application_form_with_reference_request end + it "resend emails" do + when_i_visit_the(:assessor_application_page, reference:) + and_i_click_verify_references + then_i_see_the( + :assessor_reference_requests_page, + reference:, + assessment_id:, + ) + and_the_reference_request_status_is("WAITING ON") + + when_i_click_on_the_reference_request + then_i_see_the( + :assessor_verify_reference_request_page, + reference:, + assessment_id:, + id: reference_request.id, + ) + and_i_can_resend_the_email + + when_i_click_on_resend_email_summary + and_i_click_on_send_email_button + then_i_see_the( + :assessor_verify_reference_request_page, + reference:, + assessment_id:, + id: reference_request.id, + ) + end + it "verify received" do + given_the_reference_request_is_received + when_i_visit_the(:assessor_application_page, reference:) and_i_click_verify_references then_i_see_the( @@ -27,6 +58,7 @@ id: reference_request.id, ) and_i_see_the_reference_summary + and_i_cant_resend_the_email and_i_submit_yes_on_the_verify_form then_i_see_the( :assessor_reference_requests_page, @@ -80,6 +112,7 @@ assessment_id:, id: reference_request.id, ) + and_i_can_resend_the_email and_i_submit_yes_on_the_verify_form then_i_see_the( :assessor_verify_failed_reference_request_page, @@ -104,8 +137,12 @@ def given_there_is_an_application_form_with_reference_request application_form end + def given_the_reference_request_is_received + reference_request.received! + end + def given_the_reference_request_is_overdue - reference_request.update!(expired_at: Time.zone.now, received_at: nil) + reference_request.expired! end def and_i_click_verify_references @@ -180,7 +217,19 @@ def and_i_see_the_reference_summary ).to eq("Yes") expect( assessor_verify_reference_request_page.responses.values[10].text, - ).to eq(reference_request.additional_information_response) + ).to eq("None provided") + end + + def and_i_cant_resend_the_email + expect(assessor_verify_reference_request_page).to_not have_css( + ".govuk-details", + ) + end + + def and_i_can_resend_the_email + expect( + assessor_verify_reference_request_page.send_email_details, + ).to be_visible end def and_i_submit_yes_on_the_verify_form @@ -212,6 +261,14 @@ def then_i_see_the_verify_references_task_is_completed ).to eq("COMPLETED") end + def when_i_click_on_resend_email_summary + assessor_verify_reference_request_page.send_email_details.summary.click + end + + def and_i_click_on_send_email_button + assessor_verify_reference_request_page.send_email_details.button.click + end + def reference_request_task_item assessor_reference_requests_page.task_list.sections.first.items.first end @@ -237,17 +294,24 @@ def application_form assessment = create( :assessment, - :with_received_professional_standing_request, + :with_professional_standing_request, :verify, application_form:, ) create(:assessment_section, :passed, assessment:) create( :reference_request, - :received, - :responses_valid, + :requested, assessment:, work_history:, + contact_response: true, + dates_response: true, + hours_response: true, + children_response: true, + lessons_response: true, + reports_response: true, + misconduct_response: false, + satisfied_response: true, ) application_form end