Skip to content

Commit

Permalink
opening service reminder emails consider journey
Browse files Browse the repository at this point in the history
- this is still currently limited to additional payments
- there is guard for the above
- but can be extended allow for other journeys
- this change is based on PR #3175
  • Loading branch information
asmega committed Nov 29, 2024
1 parent 827753a commit f9ec57d
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 21 deletions.
4 changes: 2 additions & 2 deletions app/controllers/admin/journey_configurations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def journey_configuration_params
end

def send_reminders
return unless journey_configuration.open_for_submissions && journey_configuration.additional_payments?
return unless journey_configuration.open_for_submissions

SendReminderEmailsJob.perform_later
SendReminderEmailsJob.perform_later(journey_configuration.journey)
end
end
end
3 changes: 2 additions & 1 deletion app/forms/reminders/personal_details_form.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def next_academic_year
def reminder
@reminder ||= Reminder.new(
full_name: reminder_full_name,
email_address: reminder_email_address
email_address: reminder_email_address,
journey_class: journey.to_s
)
end

Expand Down
3 changes: 3 additions & 0 deletions app/jobs/send_reminder_email_job.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
class SendReminderEmailJob < ApplicationJob
def perform(reminder)
# TODO: Remove when the template is updated to support other journeys
return unless reminder.journey == Journeys::AdditionalPaymentsForTeaching

ReminderMailer.reminder(reminder).deliver_now
reminder.update!(email_sent_at: Time.now)
end
Expand Down
10 changes: 2 additions & 8 deletions app/jobs/send_reminder_emails_job.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
class SendReminderEmailsJob < ApplicationJob
def perform
reminders.find_each(batch_size: 100) do |reminder|
def perform(journey)
Reminder.to_be_sent.by_journey(journey).find_each(batch_size: 100) do |reminder|
SendReminderEmailJob.perform_later(reminder)
end
end

private

def reminders
@reminders ||= Reminder.to_be_sent
end
end
8 changes: 6 additions & 2 deletions app/mailers/reminder_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def email_verification(reminder, one_time_password, journey_name)
@one_time_password = one_time_password
@display_name = reminder.full_name
@subject = "Please verify your reminder email"
support_email_address = translate("additional_payments.support_email_address")
support_email_address = translate(:support_email_address, scope: reminder.journey::I18N_NAMESPACE)
personalisation = {
email_subject: @subject,
first_name: @display_name,
Expand All @@ -24,7 +24,7 @@ def email_verification(reminder, one_time_password, journey_name)

def reminder_set(reminder)
@reminder = reminder
support_email_address = translate("additional_payments.support_email_address")
support_email_address = translate(:support_email_address, scope: reminder.journey::I18N_NAMESPACE)

personalisation = {
first_name: extract_first_name(@reminder.full_name),
Expand All @@ -35,6 +35,10 @@ def reminder_set(reminder)
send_mail(REMINDER_SET_NOTIFY_TEMPLATE_ID, personalisation)
end

# TODO: This template only accommodates LUP/ECP claims currently. Needs to
# be changed to support other policies otherwise claimants will receive the
# wrong information. Also most of the personalisations are not used in the
# template.
def reminder(reminder)
@reminder = reminder
support_email_address = translate("additional_payments.support_email_address")
Expand Down
5 changes: 5 additions & 0 deletions app/models/reminder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ class Reminder < ApplicationRecord

scope :email_verified, -> { where(email_verified: true) }
scope :not_yet_sent, -> { where(email_sent_at: nil) }
scope :by_journey, ->(journey) { where(journey_class: journey.to_s) }
scope :inside_academic_year, -> { where(itt_academic_year: AcademicYear.current.to_s) }
scope :to_be_sent, -> { email_verified.not_yet_sent.inside_academic_year }

def journey
journey_class.constantize
end

def send_year
itt_academic_year.start_year
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% if journey_configuration.additional_payments? && Reminder.to_be_sent.any? %>
<% if Reminder.to_be_sent.by_journey(journey_configuration.journey).any? %>
<div class="govuk-radios__conditional govuk-radios__conditional--hidden" id="reminders-warning-message">
<div class="govuk-form-group">
<div class="govuk-warning-text" id="ecp-reminder-count-warning">
Expand Down
4 changes: 2 additions & 2 deletions spec/features/admin/admin_configure_services_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

within_fieldset("Service status") { choose("Open") }

expect { click_on "Save" }.to_not enqueue_job(SendReminderEmailsJob)
expect { click_on "Save" }.to enqueue_job(SendReminderEmailsJob).with { |arg| expect(arg).to eql(Journeys::TeacherStudentLoanReimbursement) }

expect(current_path).to eq(admin_journey_configurations_path)

Expand Down Expand Up @@ -113,7 +113,7 @@
end

select "2023/2024", from: "Accepting claims for academic year"
expect { click_on "Save" }.to_not enqueue_job(SendReminderEmailsJob)
expect { click_on "Save" }.to enqueue_job(SendReminderEmailsJob).with { |arg| expect(arg).to eql(journey_configuration.journey) }

within(find("tr[data-policy-configuration-routing-name=\"#{journey_configuration.routing_name}\"]")) do
expect(page).to have_content("2023/2024")
Expand Down
20 changes: 15 additions & 5 deletions spec/jobs/send_reminder_emails_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,22 @@

RSpec.describe SendReminderEmailsJob do
let(:count) { [*1..5].sample }
let(:reminders) { create_list(:reminder, count, email_verified: true, itt_academic_year: AcademicYear.current) }
let(:reminders) do
create_list(
:reminder,
count,
email_verified: true,
itt_academic_year: AcademicYear.current,
journey_class: Journeys::AdditionalPaymentsForTeaching.to_s
)
end

before do
# these should not send
create(:reminder, email_verified: false)
create(:reminder, email_verified: true, email_sent_at: Time.now)
create(:reminder, email_verified: true, itt_academic_year: AcademicYear.next)
create(:reminder, email_verified: false, journey_class: Journeys::AdditionalPaymentsForTeaching.to_s)
create(:reminder, email_verified: true, email_sent_at: Time.now, journey_class: Journeys::AdditionalPaymentsForTeaching.to_s)
create(:reminder, email_verified: true, itt_academic_year: AcademicYear.next, journey_class: Journeys::AdditionalPaymentsForTeaching.to_s)
create(:reminder, email_verified: true, itt_academic_year: AcademicYear.current, journey_class: Journeys::FurtherEducationPayments.to_s)
end

describe "#perform" do
Expand All @@ -22,7 +32,7 @@
# perform job
expect {
perform_enqueued_jobs do
subject.perform
subject.perform(Journeys::AdditionalPaymentsForTeaching.to_s)
end
}.to change { ActionMailer::Base.deliveries.count }.by(count)

Expand Down

0 comments on commit f9ec57d

Please sign in to comment.