-
Notifications
You must be signed in to change notification settings - Fork 166
Enqueue a letter every day to a designated receiver (LG-3939) #4558
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1725855
Enqueue a letter every day to a designated receiver (LG-3939)
zachmargolis c69f1d3
Review feedback: use profile_id = -1
zachmargolis 2b4a73d
lint
zachmargolis 4d0a96b
Remove TODO, use blank issuer
zachmargolis 8d5e7aa
Simplify profile linking logic
zachmargolis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Mails a letter to the designated receiver | ||
| class UspsDailyTestSender | ||
| def run | ||
| if valid_designated_receiver_pii? | ||
| UspsConfirmationMaker.new( | ||
| pii: designated_receiver_pii, | ||
| issuer: nil, | ||
| profile_id: -1, # profile_id can't be null on UspsConfirmationCode | ||
| otp: otp_from_date, | ||
| ).perform | ||
| else | ||
| raise 'missing valid designated receiver pii' | ||
| end | ||
| rescue => err | ||
| NewRelic::Agent.notice_error(err) | ||
| end | ||
|
|
||
| # @return [String] 10-digit OTP from the date | ||
| # @example | ||
| # "JAN20_2020" | ||
| def otp_from_date(date = Time.zone.today) | ||
| date.strftime('%b%d_%Y').upcase | ||
| end | ||
|
|
||
| # @return [Hash] | ||
| def designated_receiver_pii | ||
| @designated_receiver_pii ||= JSON.parse( | ||
| AppConfig.env.gpo_designated_receiver_pii, | ||
| symbolize_names: true, | ||
| ) | ||
| end | ||
|
|
||
| def valid_designated_receiver_pii? | ||
| %i[first_name last_name address1 city state zipcode].all? do |key| | ||
| designated_receiver_pii[key].present? | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,9 +6,11 @@ | |
| name: 'Send GPO letter', | ||
| interval: 24 * 60 * 60, | ||
| timeout: 300, | ||
| callback: lambda { | ||
| callback: lambda do | ||
| UspsDailyTestSender.new.run | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seemed easier to add this step to the existing daily job, rather than worry about race conditions across multiple daily jobs? I did add the top-level rescue to minimize the chances that this job will break the actual upload run |
||
|
|
||
| UspsConfirmationUploader.new.run unless CalendarService.weekend_or_holiday?(Time.zone.today) | ||
| }, | ||
| end, | ||
| ) | ||
|
|
||
| # Send account deletion confirmation notifications | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe UspsDailyTestSender do | ||
| subject(:sender) { UspsDailyTestSender.new } | ||
|
|
||
| let(:designated_receiver_pii) do | ||
| { | ||
| first_name: 'Emmy', | ||
| last_name: 'Examperson', | ||
| address1: '123 Main St', | ||
| city: 'Washington', | ||
| state: 'DC', | ||
| zipcode: '20001', | ||
| } | ||
| end | ||
|
|
||
| before do | ||
| allow(AppConfig.env).to receive(:gpo_designated_receiver_pii). | ||
| and_return(designated_receiver_pii.to_json) | ||
| end | ||
|
|
||
| describe '#run' do | ||
| it 'creates a USPS confirmation and code for the current date' do | ||
| expect { sender.run }. | ||
| to(change { UspsConfirmation.count }.by(1).and(change { UspsConfirmationCode.count }.by(1))) | ||
|
|
||
| usps_confirmation_code = UspsConfirmationCode.find_by( | ||
| otp_fingerprint: Pii::Fingerprinter.fingerprint(sender.otp_from_date), | ||
| ) | ||
| expect(usps_confirmation_code).to_not be_nil | ||
| expect(usps_confirmation_code.profile_id).to eq(-1) | ||
| end | ||
|
|
||
| context 'when the designed receiver PII is missing' do | ||
| let(:designated_receiver_pii) { '' } | ||
|
|
||
| it 'does not create usps records' do | ||
| expect { sender.run }. | ||
| to(change { UspsConfirmation.count }.by(0). | ||
| and(change { UspsConfirmationCode.count }.by(0))) | ||
| end | ||
|
|
||
| it 'does not blow up (so the calling job can continue normally) and notifies NewRelic' do | ||
| expect(NewRelic::Agent).to receive(:notice_error) | ||
|
|
||
| expect { sender.run }.to_not raise_error | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe '#designated_receiver_pii' do | ||
| it 'parses PII from the application config' do | ||
| expect(sender.designated_receiver_pii).to eq(designated_receiver_pii) | ||
| end | ||
| end | ||
|
|
||
| describe '#otp_from_date' do | ||
| it 'formats the date as a 10-digit OTP' do | ||
| expect(sender.otp_from_date(Date.new(2020, 1, 1))).to eq('JAN01_2020') | ||
| expect(sender.otp_from_date(Date.new(2021, 7, 15))).to eq('JUL15_2021') | ||
| end | ||
| end | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to make sure we go over this with privacy / security before we add PII to app config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got confirmation in Slack: https://gsa-tts.slack.com/archives/CA7NE63SB/p1609870443330800?thread_ts=1609866962.327800&cid=CA7NE63SB