Skip to content

Commit

Permalink
Add resend referee email feature
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thomasleese committed Mar 27, 2024
1 parent 5ed0891 commit 72cc763
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,29 @@ def update_verify_failed
if @form.save
redirect_to [
:assessor_interface,
requestable.application_form,
requestable.assessment,
application_form,
assessment,
:reference_requests,
]
else
render :edit_verify_failed, status: :unprocessable_entity
end
end

def resend_email
if reference_request.requested? && !reference_request.received?
RefereeMailer.with(reference_request:).reference_requested.deliver_later
end

redirect_to [
:verify,
:assessor_interface,
application_form,
assessment,
reference_request,
]
end

private

def set_individual_variables
Expand Down
4 changes: 4 additions & 0 deletions app/policies/assessor_interface/reference_request_policy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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" %>

Expand Down Expand Up @@ -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: "Send email to referee") do %>
<%= govuk_warning_text(text: "Only use this if contact has been made with the referee.") %>
<%= govuk_button_link_to "Resend initial reference request email", [:resend_email, :assessor_interface, @application_form, @assessment, @reference_request] %>
<p class="govuk-body">Reminders are sent automatically 4 weeks and 2 weeks before the reference goes overdue.</p>
<% end %>
<% end %>

<% if @reference_request.expired? %>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 0 additions & 6 deletions spec/factories/assessments.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down
32 changes: 0 additions & 32 deletions spec/factories/reference_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
74 changes: 69 additions & 5 deletions spec/system/assessor_interface/verifying_references_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 72cc763

Please sign in to comment.