Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for survey notification job #4402

Merged
merged 10 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions lib/tasks/send_survey_notifications.rake
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,24 @@ namespace :survey_notifications do
BATCH_SIZE = 10
accepted_submissions = EfileSubmission.joins(:efile_submission_transitions)
.where("efile_submission_transitions.to_state = 'accepted'")
.where("efile_submissions.data_source_type = 'StateFileAzIntake' OR efile_submissions.data_source_type = 'StateFileNyIntake'")
rickreyhsig marked this conversation as resolved.
Show resolved Hide resolved
.where.not("message_tracker #> '{messages.state_file.survey_notification}' IS NOT NULL")

accepted_submissions.each_slice(BATCH_SIZE) do |batch|
batch.each do |submission|
puts "Sending survey notification to #{submission.id}"
StateFile::MessagingService.new(
intake: submission.data_source,
submission: submission,
message: StateFile::AutomatedMessage::SurveyNotification,
body_args: { survey_link: survey_link(submission.data_source) }
).send_message
intake = submission.data_source
rickreyhsig marked this conversation as resolved.
Show resolved Hide resolved
if intake.nil?
rickreyhsig marked this conversation as resolved.
Show resolved Hide resolved
# This should only happen for non state_filing submissions which have been filtered out up top.
puts "Skipping over submission #{submission.id} without an intake."
else
puts "Sending survey notification to #{submission.id}"
StateFile::MessagingService.new(
intake: intake,
submission: submission,
message: StateFile::AutomatedMessage::SurveyNotification,
body_args: { survey_link: survey_link(intake) }
).send_message
end
end
end
end
Expand Down
13 changes: 13 additions & 0 deletions spec/tasks/send_survey_notifications_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
require 'rails_helper'

describe 'send_survey_notifications rake task' do
let!(:intake) { create :state_file_az_intake, email_address: "test@example.com", email_address_verified_at: 1.minute.ago }
let!(:efile_submission) { create :efile_submission, :for_state, :accepted, data_source: intake }
let!(:efile_submission_no_intake) { create :efile_submission, :for_state, :accepted, data_source: nil }
before(:all) do
Rails.application.load_tasks
end
it 'runs without error even when submission does not have an intake' do
rickreyhsig marked this conversation as resolved.
Show resolved Hide resolved
Rake::Task['survey_notifications:send'].execute
end
end
Loading