Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
mpidcock committed Apr 13, 2024
2 parents df822e8 + 4c4228c commit c4a4011
Show file tree
Hide file tree
Showing 11 changed files with 114 additions and 22 deletions.
12 changes: 12 additions & 0 deletions app/jobs/send_reminder_apology_message_job.rb
@@ -0,0 +1,12 @@
class SendReminderApologyMessageJob < ApplicationJob
def perform(intake)
StateFile::MessagingService.new(
message: StateFile::AutomatedMessage::ReminderApology,
intake: intake
).send_message
end

def priority
PRIORITY_MEDIUM
end
end
24 changes: 24 additions & 0 deletions app/models/state_file/automated_message/reminder_apology.rb
@@ -0,0 +1,24 @@
module StateFile::AutomatedMessage
class ReminderApology < BaseAutomatedMessage

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

def self.after_transition_notification?
false
end

def self.send_only_once?
true
end

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

def email_body(**args)
I18n.t("messages.state_file.reminder_apology.email.body", **args)
end
end
end
27 changes: 12 additions & 15 deletions app/services/state_file/reminder_to_finish_state_return_service.rb
@@ -1,24 +1,21 @@
module StateFile
class ReminderToFinishStateReturnService
BATCH_SIZE = 10
HOURS_AGO = 12
def self.run
cutoff_time_ago = HOURS_AGO.hours.ago
intakes_to_notify = []
cutoff_time_ago = 12.hours.ago
batch_size = 10
intakes_with_no_submission = StateFileAzIntake.where("df_data_imported_at < ?", cutoff_time_ago)
.left_joins(:efile_submissions)
.where(efile_submissions: { id: nil })
.where.not("state_file_az_intakes.message_tracker #> '{messages.state_file.finish_return}' IS NOT NULL")

ApplicationRecord::STATE_INTAKE_CLASS_NAMES.each do |base_class|
class_object = base_class.constantize
intakes_to_notify += class_object.where("#{base_class.underscore.pluralize}.created_at < ?", cutoff_time_ago)
.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.finish_return}' IS NULL")
end
intakes_with_no_submission += StateFileNyIntake.where("df_data_imported_at < ?", cutoff_time_ago)
.left_joins(:efile_submissions)
.where(efile_submissions: { id: nil })
.where.not("state_file_ny_intakes.message_tracker #> '{messages.state_file.finish_return}' IS NOT NULL")

intakes_to_notify.each_slice(BATCH_SIZE) do |batch|
intakes_with_no_submission.each_slice(batch_size) do |batch|
batch.each do |intake|
StateFile::MessagingService.new(
message: StateFile::AutomatedMessage::FinishReturn, intake: intake
).send_message
StateFile::MessagingService.new(message: StateFile::AutomatedMessage::FinishReturn, intake: intake).send_message
end
end
end
Expand Down
15 changes: 15 additions & 0 deletions app/services/state_file/send_reminder_apology_service.rb
@@ -0,0 +1,15 @@
module StateFile
class SendReminderApologyService
def self.run

intakes = EfileSubmission.joins(:efile_submission_transitions)
.for_state_filing
.where("efile_submission_transitions.to_state = 'accepted'")
.extract_associated(:data_source)

intakes.each do |intake|
SendReminderApologyMessageJob.perform_later(intake)
end
end
end
end
14 changes: 14 additions & 0 deletions config/locales/en.yml
Expand Up @@ -1655,6 +1655,20 @@ en:
Hi %{primary_first_name} - Unfortunately, %{state_name} rejected your state tax return. Don't worry! We can help you fix and resubmit it at %{return_status_link}.
Questions? Reply to this text.
reminder_apology:
email:
body: |
Hi %{primary_first_name},
Due to an error, some FileYourStateTaxes users who had already completed their state tax returns received an email earlier today reminding them to file by April 15.
If you have received a notification that your state return was accepted, you may disregard the reminder email you may have received earlier today. You can confirm your return status by visiting fileyourstatetaxes.org/en/us/login-options and logging into your account.
We sincerely apologize for the confusion and the stress this may have caused.
Thanks,
FileYourStateTaxes
subject: Please disregard previous message from FileYourStateTaxes
still_processing:
email:
body: |
Expand Down
14 changes: 14 additions & 0 deletions config/locales/es.yml
Expand Up @@ -1623,6 +1623,20 @@ es:
Lamentablemente, %{state_name} rechazó tu declaración de impuestos estatales. ¡No te preocupes! Podemos ayudarte a corregirla y volver a enviarla en %{return_status_link}.
¿Preguntas? Responde a este mensaje.
reminder_apology:
email:
body: |
Hola %{primary_first_name},
Debido a un error, algunos usuarios de FileYourStateTaxes que ya enviaron sus declaraciones de impuestos estatales recibieron un mensaje hoy recordándoles que la fecha límite de declarar es el 15 de abril.
Si has recibido una noticia diciendo que tu declaración fue aceptada, puedes ignorar el mensaje recordatorio que hayas recibido hoy. Puedes confirmar el estatus de tu declaración visitando fileyourstatetaxes.org/es/us/login-options e ingresando a tu cuenta.
Nos disculpamos sinceramente por la confusión y el estrés que esto haya causado.
Gracias,
FileYourStateTaxes
subject: Favor de ignorar el mensaje recordatorio de FileYourStateTaxes
still_processing:
email:
body: |
Expand Down
1 change: 1 addition & 0 deletions crontab
Expand Up @@ -13,3 +13,4 @@
0 21 13 4 * bundle exec rake send_reject_resolution_reminder_notifications:send
0 21 22 4 * bundle exec rake send_reject_resolution_reminder_notifications:send
40 19 12 4 * bundle exec rake send_reject_resolution_reminder_notifications:send
0 11 14 4 * bundle exec rake state_file:send_reminder_apology_message
4 changes: 4 additions & 0 deletions lib/tasks/efile.rake
Expand Up @@ -23,4 +23,8 @@ namespace :efile do
puts("End: Found #{EfileSubmission.in_state(:failed).count} failed submissions")
exit
end

task reminder_to_finish_state_return: :environment do
StateFile::ReminderToFinishStateReturnService.run
end
end
5 changes: 5 additions & 0 deletions lib/tasks/state_file.rake
Expand Up @@ -14,4 +14,9 @@ namespace :state_file do
return unless DateTime.now.year == 2024
StateFile::SendPostDeadlineReminderService.run
end

task send_reminder_apology_message: :environment do
return unless DateTime.now.year == 2024
StateFile::SendReminderApologyService.run
end
end
Expand Up @@ -11,19 +11,25 @@
allow(state_file_messaging_service).to receive(:send_message)
end

context 'when there is a started intake from more than 12 hours ago' do
let!(:intake) { create :state_file_az_intake, created_at: (12.hours + 1.minute).ago, email_address: 'test@email.com', email_address_verified_at: Time.now }
context "when there is an incomplete intake with df transfer from exactly 12 hours ago" do
let!(:intake) do
create :state_file_az_intake,
df_data_imported_at: 12.hours.ago
end

it 'sends a message to the email associated with the intake' do
it "sends a message to the email associated with the intake" do
StateFile::ReminderToFinishStateReturnService.run
expect(StateFile::MessagingService).to have_received(:new).with(intake: intake, message: message)
expect(state_file_messaging_service).to have_received(:send_message)
end
end

context 'when there is a started intake from less than 12 hours ago' do
let(:intake) { create :state_file_az_intake, created_at: (11.hours + 59.minutes).ago }
it 'does not send a message to the email associated with the intake' do
context "when there is an incomplete intake with df transfer from less than 12 hours ago" do
let(:intake) do
create :state_file_az_intake,
df_data_imported_at: (11.hours + 59.minutes).ago
end
it "does not send a message to the email associated with the intake" do
StateFile::ReminderToFinishStateReturnService.run
expect(StateFile::MessagingService).to_not have_received(:new)
end
Expand Down
Expand Up @@ -23,7 +23,7 @@
expect(StateFile::MessagingService).to have_received(:new).exactly(2).times
end

it 'doesn\'t send the notification to an intake that has NOT been submitted' do
it "doesn't send the notification to an intake that has NOT been submitted" do
expect(StateFileNyIntake.where.not(federal_submission_id: nil).count).to eq(1)
end
end

0 comments on commit c4a4011

Please sign in to comment.