Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 10 additions & 7 deletions app/services/gpo_reminder_sender.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ class GpoReminderSender
LOCAL_DATABASE_TIMEOUT = 60_000

def send_emails(for_letters_sent_before)
letter_eligible_range =
reminder_eligible_range =
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a better name.

IdentityConfig.store.usps_confirmation_max_days.days.ago..for_letters_sent_before

profiles_due_for_reminder(letter_eligible_range).each do |profile|
profiles_due_for_reminder(for_letters_sent_before).each do |profile|
profile.gpo_confirmation_codes.all.each do |gpo_code|
next if gpo_code.reminder_sent_at
next unless letter_eligible_range.cover?(gpo_code.created_at)
next unless reminder_eligible_range.cover?(gpo_code.created_at)

# Only email the user if we have an eligible code.
# Unlikely to have multiple codes since we only allow one letter/day
Expand All @@ -22,17 +21,21 @@ def send_emails(for_letters_sent_before)

private

def profiles_due_for_reminder(letter_eligible_range)
def profiles_due_for_reminder(for_letters_sent_before)
ActiveRecord::Base.transaction do
ActiveRecord::Base.connection.execute(
"SET LOCAL statement_timeout = #{LOCAL_DATABASE_TIMEOUT}",
)

profile_eligible_range =
(IdentityConfig.store.usps_confirmation_max_days +
IdentityConfig.store.gpo_max_profile_age_to_send_letter_in_days).
days.ago..for_letters_sent_before
Profile.joins(:gpo_confirmation_codes).
where(
gpo_verification_pending_at: letter_eligible_range,
gpo_verification_pending_at: profile_eligible_range,
gpo_confirmation_codes: { reminder_sent_at: nil },
deactivation_reason: [nil, :in_person_verification_pending],
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought this was here because a user might have a GPO letter for in-person proofing; is this not possible?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sonia confirmed that that flag is deprecated and no longer used.

deactivation_reason: nil,
)
end
end
Expand Down
21 changes: 14 additions & 7 deletions spec/services/gpo_reminder_sender_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
let(:time_due_for_reminder) { Time.zone.now - wait_for_reminder }
let(:time_not_yet_due) { time_due_for_reminder + 1.day }
let(:time_yesterday) { Time.zone.now - 1.day }
let(:time_code_expires) { (IdentityConfig.store.usps_confirmation_max_days + 1).days.ago }

def set_reminder_sent_at(to_time)
gpo_confirmation_code.update(
Expand Down Expand Up @@ -79,6 +80,18 @@ def set_reminder_sent_at(to_time)
include_examples 'sends no emails'
end

context 'when a user has very old gpo code and remindable gpo code' do
let(:code_sent_at) { time_code_expires }

before do
reminder_timestamp = time_due_for_reminder - 2.days
new_confirmation_code = create(:gpo_confirmation_code, created_at: reminder_timestamp)
user.gpo_verification_pending_profile.gpo_confirmation_codes << new_confirmation_code
end

include_examples 'sends emails', expected_number_of_emails: 1
end

context 'when a user has requested two letters' do
let(:code_sent_at) { time_due_for_reminder - 2.days }
before do
Expand Down Expand Up @@ -176,13 +189,7 @@ def set_reminder_sent_at(to_time)
end

context 'when a user is due for a reminder from too long ago' do
let(:max_age_to_send_letter_in_days) { 42 }
let(:code_sent_at) { (max_age_to_send_letter_in_days + 1).days.ago }

before do
allow(IdentityConfig.store).to receive(:usps_confirmation_max_days).
and_return(max_age_to_send_letter_in_days)
end
let(:code_sent_at) { time_code_expires }

include_examples 'sends no emails'
end
Expand Down