Skip to content

Commit

Permalink
Post-Deadline notification (#4475)
Browse files Browse the repository at this point in the history
* Post-Deadline notification
  • Loading branch information
rickreyhsig committed Apr 12, 2024
1 parent cccdde0 commit d17e150
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 1 deletion.
28 changes: 28 additions & 0 deletions app/models/state_file/automated_message/post_deadline_reminder.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module StateFile::AutomatedMessage
class PostDeadlineReminder < BaseAutomatedMessage

def self.name
'messages.state_file.post_deadline_reminder'.freeze
end

def self.after_transition_notification?
false
end

def self.send_only_once?
true
end

def sms_body(**args)
I18n.t("messages.state_file.post_deadline_reminder.sms", **args)
end

def email_subject(**args)
I18n.t("messages.state_file.post_deadline_reminder.email.subject", **args)
end

def email_body(**args)
I18n.t("messages.state_file.post_deadline_reminder.email.body", **args)
end
end
end
38 changes: 38 additions & 0 deletions app/services/state_file/send_post_deadline_reminder_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module StateFile
class SendPostDeadlineReminderService
BATCH_SIZE = 10
HOURS_AGO = 24

def self.run
cutoff_time_ago = HOURS_AGO.hours.ago
intakes_to_notify = []

ApplicationRecord::STATE_INTAKE_CLASS_NAMES.each do |base_class|
class_object = base_class.constantize
intakes_to_notify += class_object.left_joins(:efile_submissions)
.where(efile_submissions: { id: nil })
.where.not(email_address: nil)
.where.not(email_address_verified_at: nil)
.where(unsubscribed_from_email: false)
.where("#{base_class.underscore.pluralize}.message_tracker #> '{messages.state_file.post_deadline_reminder}' IS NULL")
.select do |intake|
if intake.message_tracker.present? && intake.message_tracker["messages.state_file.finish_return"]
finish_return_msg_sent_time = Date.parse(intake.message_tracker["messages.state_file.finish_return"])
finish_return_msg_sent_time < cutoff_time_ago
else
true
end
end
end

intakes_to_notify.each_slice(BATCH_SIZE) do |batch|
batch.each do |intake|
StateFile::MessagingService.new(
message: StateFile::AutomatedMessage::PostDeadlineReminder,
intake: intake
).send_message
end
end
end
end
end
7 changes: 7 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1610,6 +1610,13 @@ en:
Hello - Thank you for using FileYourStateTaxes! Any issues you may have experienced while using our tool have now been resolved. To continue filing your state taxes, log in here: %{login_link}
Questions? Reply to this text.
post_deadline_reminder:
email:
body: "Hi %{primary_first_name},\n\nYou haven't submitted your state tax return yet. As a reminder, state taxes are due by April 15. Make sure to submit your state tax return by April 15 in order to avoid late filing fees from %{state_name}. \n\nGo to fileyourstatetaxes.org/en/us/login-options to finish them now.\n\nNeed help? Reply to this email.\n\nBest,\nThe FileYourStateTaxes team\n"
subject: Make sure to finish filing your state taxes as soon as possible.
sms: |
Hi %{primary_first_name} - You haven't submitted your state tax return yet. Make sure to submit your state taxes by April 15 in order to avoid late filing fees. Go to fileyourstatetaxes.org/en/us/login-options to finish them now.
Need help? Reply to this text.
pre_deadline_reminder:
email:
body: "Hi %{primary_first_name},\n\nYou haven't submitted your state tax return yet. As a reminder, state taxes are due by April 15. Make sure to submit your state tax return by April 15 in order to avoid late filing fees from %{state_name}. \n\nGo to fileyourstatetaxes.org/en/us/login-options to finish them now.\n\nNeed help? Reply to this email.\n\nBest,\nThe FileYourStateTaxes team\n"
Expand Down
14 changes: 14 additions & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1584,6 +1584,20 @@ es:
Hola, ¡Gracias por usar FileYourStateTaxes! Todos los problemas que hayas experimentado al usar nuestra herramienta han sido resueltos. Para continuar presentando tus impuestos estatales, inicia sesión aquí: %{login_link}
¿Preguntas? Responde a este mensaje.
post_deadline_reminder:
email:
body: |
Hola %{primary_first_name},
Aún no has presentado tu declaración de impuestos estatales. Como recordatorio, los impuestos estatales vencieron el 15 de abril. Asegúrate de presentar tu declaración de impuestos estatales antes del 15 de abril para evitar multas por presentación tardía en %{state_name}.
FileYourStateTaxes cerrará sus servicios para el año el 25 de abril.
Ve a fileyourstatetaxes.org/es/us/login-options para terminarlos ahora.
¿Necesitas ayuda? Responde a este correo electrónico.
Saludos,
El equipo de FileYourStateTaxes
subject: "¡No olvides terminar de presentar tu declaración de impuestos estatales lo antes posible!"
sms: |
Hola %{primary_first_name} - Aún no has presentado tu declaración de impuestos estatales. Asegúrate de presentar tus impuestos estatales antes del 15 de abril para evitar multas por presentación tardía. Ve a fileyourstatetaxes.org/es/us/login-options para terminarlos ahora. FileYourStateTaxes cerrará sus servicios para el año el 25 de abril.
¿Necesitas ayuda? Responde a este mensaje de texto.
pre_deadline_reminder:
email:
body: "Hola %{primary_first_name}, \n\nAún no has presentado tu declaración de impuestos estatales. Asegúrate de presentar tus impuestos estatales antes del 15 de abril para evitar multas por presentación tardía de %{state_name}. \n\nVe a fileyourstatetaxes.org/en/us/login-options para terminarlos ahora.\n\n¿Necesitas ayuda? Responde a este mensaje de texto.\n\nAtentamente,\nEl equipo de FileYourStateTaxes\n"
Expand Down
1 change: 1 addition & 0 deletions crontab
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
*/10 * * * * bundle exec rake efile:poll_and_get_acknowledgments
0 17 * * * bundle exec rake state_file:reminder_to_finish_state_return
0 21 13 4 * bundle exec rake state_file:pre_deadline_reminder
0 21 16 4 * bundle exec rake state_file:post_deadline_reminder
7 changes: 6 additions & 1 deletion lib/tasks/state_file.rake
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,14 @@ namespace :state_file do
task reminder_to_finish_state_return: :environment do
StateFile::ReminderToFinishStateReturnService.run
end

task pre_deadline_reminder: :environment do
return unless DateTime.now.year == 2024
StateFile::SendPreDeadlineReminderService.run
end

task post_deadline_reminder: :environment do
return unless DateTime.now.year == 2024
StateFile::SendPostDeadlineReminderService.run
end
end
66 changes: 66 additions & 0 deletions spec/tasks/send_post_deadline_reminder_service_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# frozen_string_literal: true
require 'rails_helper'

describe 'state_file:post_deadline_reminder' do
before(:context) do
Rails.application.load_tasks
end

context 'Sends the notification to all state-filing' do
let!(:az_intake) { create :state_file_az_intake, email_address: 'test@example.com', email_address_verified_at: 1.minute.ago, created_at: 25.hours.ago }
let!(:ny_intake) { create :state_file_ny_intake, email_address: 'test+01@example.com', email_address_verified_at: 1.minute.ago, created_at: 25.hours.ago }
let!(:submitted_intake) { create :state_file_ny_intake, email_address: 'test+01@example.com', email_address_verified_at: 1.minute.ago }
let!(:efile_submission) { create :efile_submission, :for_state, data_source: submitted_intake }

it 'intakes without submissions & without reminders' do
messaging_service = spy('StateFile::MessagingService')
allow(StateFile::MessagingService).to receive(:new).and_return(messaging_service)

Rake::Task['state_file:post_deadline_reminder'].execute

expect(StateFile::MessagingService).to have_received(:new).exactly(2).times
end
end

context 'Sends the notification to intakes that have' do
let!(:intake_with_reminder) {
create :state_file_az_intake, email_address: "test@example.com",
email_address_verified_at: 1.hour.ago, created_at: 25.hours.ago
}

before do
allow_any_instance_of(StateFileNyIntake).to receive(:message_tracker).and_return((Time.now - 25.hours).utc.to_s)
end

it 'the reminder_notification sent more than 24 hours ago' do
messaging_service = spy('StateFile::MessagingService')
allow(StateFile::MessagingService).to receive(:new).and_return(messaging_service)

Rake::Task['state_file:post_deadline_reminder'].execute

expect(StateFile::MessagingService).to have_received(:new).exactly(1).times
end
end

context 'Does NOT send the notification to' do
let!(:intake_with_reminder) {
create :state_file_az_intake, email_address: "test@example.com",
email_address_verified_at: 1.hour.ago, created_at: 25.hours.ago
}

before do
allow_any_instance_of(StateFileAzIntake).to receive(:message_tracker).and_return(
{ "messages.state_file.finish_return" => (Time.now - 2.hours).utc.to_s }
)
end

it 'intakes that have the reminder_notification sent less than 24 hours ago' do
messaging_service = spy('StateFile::MessagingService')
allow(StateFile::MessagingService).to receive(:new).and_return(messaging_service)

Rake::Task['state_file:post_deadline_reminder'].execute

expect(StateFile::MessagingService).to have_received(:new).exactly(0).times
end
end
end

0 comments on commit d17e150

Please sign in to comment.