Skip to content

LG-10126: send sms notification for USPS proofing result #8772

Merged
dawei-nava merged 34 commits intomainfrom
dwang/LG-10126-sms-notification-job
Jul 18, 2023
Merged

LG-10126: send sms notification for USPS proofing result #8772
dawei-nava merged 34 commits intomainfrom
dwang/LG-10126-sms-notification-job

Conversation

@dawei-nava
Copy link
Contributor

@dawei-nava dawei-nava commented Jul 13, 2023

🎫 Ticket

LG-10126: Create a job to send notification SMSs and delete phone numbers

🛠 Summary of changes

Create a job that when the result of enrollment is available and send sms notification if a notification phone is available, remind user to check result.

A new column is added to in_person_enrollments table to record when the sms notification is sent.

Job scheduled by the usps enrollment status update job.

Job is controlled by in_person_send_proofing_notifications_enabled in addition to in_person_proofing_enabled.

📜 Testing Plan

Provide a checklist of steps to confirm the changes.

  • Verify in_person_send_proofing_notifications_enabled flag is true and in_person_proofing_enable is true
  • Verify job is enqueued when enrollment status is updated by master job(GetUspsProofingResultsJob).
  • Verify sms message is sent for the enrollment when enrollment status is success or failure, or logged as skipped.
  • Verify analytics event for sms attempt(IdV: in person notification SMS send attempted) is logged

changelog: In-Person Proofing: send sms notification when proofing result is available.
changelog: User-Facing Improvements, In-Person Proofing, send sms notification when enrollment status is available.
…ification when enrollment status is available (LG-10126)
@dawei-nava dawei-nava marked this pull request as ready for review July 13, 2023 14:59
end

def notification_message(enrollment:)
proof_date = enrollment.proofed_at ? enrollment.proofed_at.strftime('%m/%d/%Y') : 'NA'
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dawei-nava dawei-nava requested review from a team and JackRyan1989 and removed request for JackRyan1989 July 14, 2023 14:14
Comment on lines 49 to 53
enrollment = InPersonEnrollment.find(
enrollment_id,
include: [:notification_phone_configuration,
:user],
)
Copy link
Contributor

Choose a reason for hiding this comment

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

This can throw an exception and prevent the following analytics call from completing if it's related to a database issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

The exception issue here was not resolved by the changes.

Comment on lines 14 to 15
if !enrollment.notification_phone_configuration.present? ||
(!enrollment.passed? && !enrollment.failed?)
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like we're excluding the expired status from consideration here. This means that we could end up retaining the phone configuration indefinitely, which is contrary to the stated goal of the story.

Copy link
Contributor

Choose a reason for hiding this comment

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

Should cancelled be considered here too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@gina-yamada , cancelled seems not sending email in get_usps_proofing_results_job

Copy link
Contributor

Choose a reason for hiding this comment

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

@dawei-nava - @gina-yamada makes a good point here. The issue isn't just whether we send a notification, but also whether we retain the phone number.

Comment on lines 14 to 15
if !enrollment.notification_phone_configuration.present? ||
(!enrollment.passed? && !enrollment.failed?)
Copy link
Contributor

Choose a reason for hiding this comment

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

@dawei-nava - @gina-yamada makes a good point here. The issue isn't just whether we send a notification, but also whether we retain the phone number.

Copy link
Contributor

@NavaTim NavaTim left a comment

Choose a reason for hiding this comment

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

Also regarding cancelled enrollments - since those aren't processed by the job, you may want to handle those with an ActiveRecord lifecycle callback instead.

@dawei-nava dawei-nava force-pushed the dwang/LG-10126-sms-notification-job branch from 2cef996 to cc10444 Compare July 17, 2023 17:17
Comment on lines 49 to 53
enrollment = InPersonEnrollment.find(
enrollment_id,
include: [:notification_phone_configuration,
:user],
)
Copy link
Contributor

Choose a reason for hiding this comment

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

The exception issue here was not resolved by the changes.

Comment on lines 42 to 52
unless enrollment.present?
enrollment = InPersonEnrollment.find_by(
{ id: enrollment_id },
include: [:notification_phone_configuration,
:user],
)
end
analytics(user: enrollment&.user).
idv_in_person_usps_proofing_results_notification_job_completed(
enrollment_code: enrollment.enrollment_code, enrollment_id: enrollment&.id,
)
Copy link
Contributor

Choose a reason for hiding this comment

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

If the enrollment isn't present by this point, then we should log the completion with a note that an error occurred. We should also avoid trying to re-fetch the enrollment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@NavaTim, this is not a refetch, since it's in final ensure block, the enrollment may not be fetched if the flags are disabled(first two lines).

Copy link
Contributor

Choose a reason for hiding this comment

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

If that's what you intend, then I recommend moving the find_by to the section where the flags are disabled. Also note that the accessor for enrollment_code here isn't using the nil-safe operator.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@NavaTim , refactor it a little bit, logging error and use safe operator.

if self.notification_sent_at && self.notification_phone_configuration
self.notification_phone_configuration.destroy
end
end
Copy link
Contributor

@gina-yamada gina-yamada Jul 17, 2023

Choose a reason for hiding this comment

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

@dawei-nava You might want to check in with @night-jellyfish. I think delete might be handled in her issue? Check in with her maybe, I could be wrong. See her PR

Update: I typed this out before standup but my comment was marked as pending. I submitted feedback after standup so you probably just got notified. During stand up it sounds like you are aware that you may have some overlap depending on the situation/case

Copy link
Contributor

Choose a reason for hiding this comment

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

@gina-yamada Only the cancellation is clearly handled in LG-10167 / main...brittany/lg-10167-delete-phone-no-when-enroll-cancelled; this or another ticket still needs to delete the phone number for other status changes.

Copy link
Contributor

@NavaTim NavaTim left a comment

Choose a reason for hiding this comment

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

I highly recommend some cleanup, but this looks ok.

Comment on lines +30 to +34
if enrollment.expired?
# no sending message for expired status
enrollment.notification_phone_configuration&.destroy
return
end
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we are now deleting expired enrollments' phone numbers in the proofing results job, this conditional is redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@NavaTim , i thought about it, since there may be a small chance to run the job manually with specific enrollment, i kept it here.

Comment on lines 1745 to 1763
# Track sms notification attempt
# @param [boolean] success sms notification successful or not
# @param [String] enrollment_code enrollment_code
# @param [String] enrollment_id enrollment_id
# @param [Hash] extra extra information
def idv_in_person_usps_proofing_results_notification_sent_attempted(
success:,
enrollment_code:,
enrollment_id:,
**extra
)
track_event(
'IdV: in person notification SMS send attempted',
success: success,
enrollment_code: enrollment_code,
enrollment_id: enrollment_id,
**extra,
)
end
Copy link
Contributor

Choose a reason for hiding this comment

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

The telephony_result field isn't documented nor required here. Note that the docblock here will be used to generate documentation for analytics.

end
end
context 'when failed to send notification' do
it 'logs sms send failre when number is opt out and enrollment not updated' do
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
it 'logs sms send failre when number is opt out and enrollment not updated' do
it 'logs sms send failure when number is opt out and enrollment not updated' do

@dawei-nava dawei-nava merged commit e4dcb61 into main Jul 18, 2023
@dawei-nava dawei-nava deleted the dwang/LG-10126-sms-notification-job branch July 18, 2023 15:00
@aduth aduth mentioned this pull request Jul 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants