Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add resend referee email feature #2099

Merged
merged 1 commit into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -99,15 +100,36 @@ 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?
DeliverEmail.call(
application_form:,
mailer: RefereeMailer,
action: :reference_requested,
reference_request:,
)

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
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 @@ -34,16 +35,20 @@
end
end

if can_edit_work_history
summary_list.with_row do |row|
row.with_key { "Job title of reference" }
row.with_value { work_history.contact_job }
summary_list.with_row do |row|
row.with_key { "Job title of reference" }
row.with_value { work_history.contact_job }

if can_edit_work_history
row.with_action(text: "Change", href: [:edit, :assessor_interface, @application_form, work_history])
end
end

summary_list.with_row do |row|
row.with_key { "Email address of reference" }
row.with_value { work_history.contact_email }

summary_list.with_row do |row|
row.with_key { "Email address of reference" }
row.with_value { work_history.contact_email }
if can_edit_work_history
row.with_action(text: "Change", href: [:edit, :assessor_interface, @application_form, work_history])
end
end
Expand All @@ -55,6 +60,18 @@
<% 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 reference request email") do %>
<%= govuk_warning_text(text: "Only resend reference requests if you have been asked to do so.") %>

<% if (timeline_event = @application_form.timeline_events.email_sent.where(mailer_class_name: "RefereeMailer", mailer_action_name: "reference_requested").order(created_at: :desc).first) %>
<p class="govuk-body">This email was last sent on <%= timeline_event.created_at.to_fs(:date_and_time) %></p>
<% end %>

<%= govuk_button_link_to "Resend reference request email", [:resend_email, :assessor_interface, @application_form, @assessment, @reference_request] %>

<p class="govuk-body">Resending this email will not affect the original reminder schedule. Reminders will be sent automatically 2 weeks and 4 weeks after the original reference request email was sent.</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
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
63 changes: 60 additions & 3 deletions spec/system/assessor_interface/verifying_references_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,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 @@ -26,6 +57,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 @@ -79,6 +111,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 @@ -103,8 +136,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 @@ -179,7 +216,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 @@ -211,6 +260,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 Down Expand Up @@ -242,7 +299,7 @@ def application_form
)
create(:assessment_section, :passed, assessment:)
create(
:received_reference_request,
:requested_reference_request,
assessment:,
work_history:,
contact_response: true,
Expand Down
Loading