-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
dcafb2b
commit 3ce587e
Showing
10 changed files
with
264 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class SendReferenceRequestReminderToTeacherJob < ApplicationJob | ||
def perform | ||
SendReferenceRequestReminderToTeacher.call | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
app/services/send_reference_request_reminder_to_teacher.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
# | ||
class SendReferenceRequestReminderToTeacher | ||
include ServicePattern | ||
|
||
def call | ||
reference_requests = | ||
ReferenceRequest.where(expired_at: nil, received_at: nil) | ||
teachers_to_receive_reminder_email = Set.new | ||
|
||
reference_requests.each do |reference_request| | ||
if reference_request.should_display_teacher_reference_reminder_text? | ||
teacher = reference_request.assessment.application_form.teacher | ||
teachers_to_receive_reminder_email.add(teacher) | ||
end | ||
end | ||
teachers_to_receive_reminder_email.each do |teacher| | ||
TeacherMailer.with(teacher:).references_reminder.deliver_later | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Dear <%= application_form_full_name(@application_form) %> | ||
|
||
We’re still waiting for a response from one or more of the references you provided to verify your work history. | ||
|
||
<% if @teacher.reminder_emails.count == 0 %> | ||
We contacted your references on <%= @application_form.work_histories.first.reference_request.requested_at.to_date.to_fs(:long_ordinal_uk) %> but have not received a response from: | ||
<% elsif @teacher.reminder_emails.count == 1 %> | ||
The following references have just 2 weeks to respond to the reference request. | ||
<% end %> | ||
|
||
<% @reference_requests.each do |reference_request| %> | ||
<%= reference_request.contact_name + ". " + reference_request.work_history.school_name %> | ||
<% end %> | ||
|
||
|
||
They need to respond by <%= @reference_requests.first.expires_at.to_date.to_fs(:long_ordinal_uk) %>. If your references do not respond, and, as a result, we cannot verify your work history, we may not be able to award you QTS. You should contact your reference to remind them about the request. | ||
|
||
<%= render "shared/teacher_mailer/footer" %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
spec/services/send_reference_request_reminder_to_teach_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe SendReferenceRequestReminderToTeacher do | ||
describe "#call" do | ||
subject(:call) { described_class.call } | ||
|
||
shared_examples "doesn't send an email" do | ||
it "doesn't send any email" do | ||
expect { call }.to_not have_enqueued_mail | ||
end | ||
end | ||
|
||
shared_examples "sends a reference request reminder to teacher email" do | ||
it "sends an email" do | ||
expect { call }.to have_enqueued_mail( | ||
TeacherMailer, | ||
:references_reminder, | ||
).with(params: { teacher: }, args: []) | ||
end | ||
end | ||
|
||
shared_examples "first reminder email" do |shared_example| | ||
context "when no previous reminder has been sent" do | ||
include_examples shared_example | ||
end | ||
|
||
context "when a previous reminder has been sent" do | ||
before { reference_request.reminder_emails.create } | ||
include_examples "doesn't send an email" | ||
end | ||
|
||
context "when two previous reminders have been sent" do | ||
before { 2.times { reference_request.reminder_emails.create } } | ||
include_examples "doesn't send an email" | ||
end | ||
end | ||
|
||
shared_examples "second reminder email" do |shared_example| | ||
context "when no previous reminder has been sent" do | ||
include_examples shared_example | ||
end | ||
|
||
context "when one previous reminder has been sent" do | ||
before { reference_request.reminder_emails.create } | ||
include_examples shared_example | ||
end | ||
|
||
context "when two previous reminders have been sent" do | ||
before { 2.times { reference_request.reminder_emails.create } } | ||
include_examples "doesn't send an email" | ||
end | ||
end | ||
|
||
context "with a requested reference request" do | ||
let(:application_form) do | ||
create( | ||
:application_form, | ||
:submitted, | ||
:old_regs, | ||
region:, | ||
teacher_id: teacher.id, | ||
) | ||
end | ||
let(:assessment) { create(:assessment, application_form:) } | ||
let(:region) { create(:region, :in_country, country_code: "FR") } | ||
let(:work_history) { reference_request.work_history } | ||
let(:teacher) { create(:teacher) } | ||
|
||
let(:reference_request) do | ||
create( | ||
:reference_request, | ||
requested_at: reference_requested_at, | ||
assessment:, | ||
) | ||
end | ||
|
||
context "with less than four weeks remaining" do | ||
let(:reference_requested_at) { (6.weeks - 27.days).ago } | ||
include_examples "first reminder email", | ||
"sends a reference request reminder to teacher email" | ||
end | ||
|
||
context "with less than two weeks remaining" do | ||
let(:reference_requested_at) { (6.weeks - 13.days).ago } | ||
include_examples "second reminder email", | ||
"sends a reference request reminder to teacher email" | ||
end | ||
end | ||
|
||
context "with a received reference request" do | ||
let(:reference_request) do | ||
create(:reference_request, :received, requested_at: Time.zone.now) | ||
end | ||
include_examples "doesn't send an email" | ||
end | ||
|
||
context "with an expired reference request" do | ||
let(:reference_request) do | ||
create(:reference_request, :expired, requested_at: Time.zone.now) | ||
end | ||
include_examples "doesn't send an email" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters