diff --git a/app/controllers/admin/journey_configurations_controller.rb b/app/controllers/admin/journey_configurations_controller.rb index 86ecc4a2c2..e79de0face 100644 --- a/app/controllers/admin/journey_configurations_controller.rb +++ b/app/controllers/admin/journey_configurations_controller.rb @@ -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 diff --git a/app/forms/reminders/personal_details_form.rb b/app/forms/reminders/personal_details_form.rb index b342de3810..12084c7d4d 100644 --- a/app/forms/reminders/personal_details_form.rb +++ b/app/forms/reminders/personal_details_form.rb @@ -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 diff --git a/app/jobs/send_reminder_email_job.rb b/app/jobs/send_reminder_email_job.rb index c8184d500c..165d30e8a5 100644 --- a/app/jobs/send_reminder_email_job.rb +++ b/app/jobs/send_reminder_email_job.rb @@ -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 diff --git a/app/jobs/send_reminder_emails_job.rb b/app/jobs/send_reminder_emails_job.rb index 7771b400fc..371f8376f6 100644 --- a/app/jobs/send_reminder_emails_job.rb +++ b/app/jobs/send_reminder_emails_job.rb @@ -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 diff --git a/app/mailers/reminder_mailer.rb b/app/mailers/reminder_mailer.rb index 7e399cd8f0..e48a712a07 100644 --- a/app/mailers/reminder_mailer.rb +++ b/app/mailers/reminder_mailer.rb @@ -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, @@ -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), @@ -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") diff --git a/app/models/reminder.rb b/app/models/reminder.rb index bf228c305c..4f59c79262 100644 --- a/app/models/reminder.rb +++ b/app/models/reminder.rb @@ -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 diff --git a/app/views/admin/journey_configurations/_ecp_reminder_warning.html.erb b/app/views/admin/journey_configurations/_ecp_reminder_warning.html.erb index 9706ebf59c..1f8e7f0908 100644 --- a/app/views/admin/journey_configurations/_ecp_reminder_warning.html.erb +++ b/app/views/admin/journey_configurations/_ecp_reminder_warning.html.erb @@ -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? %>
diff --git a/spec/features/admin/admin_configure_services_spec.rb b/spec/features/admin/admin_configure_services_spec.rb index acb7ac3549..306d607ffd 100644 --- a/spec/features/admin/admin_configure_services_spec.rb +++ b/spec/features/admin/admin_configure_services_spec.rb @@ -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) @@ -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") diff --git a/spec/jobs/send_reminder_emails_job_spec.rb b/spec/jobs/send_reminder_emails_job_spec.rb index 005c50d3c3..38cc4b4f04 100644 --- a/spec/jobs/send_reminder_emails_job_spec.rb +++ b/spec/jobs/send_reminder_emails_job_spec.rb @@ -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 @@ -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)