Skip to content

LG-7832: Transliterate name, address, and city for USPS API (w/ FF)#7935

Merged
NavaTim merged 15 commits intomainfrom
tbradley/lg-7832-transliterate-usps-api-integration
Mar 7, 2023
Merged

LG-7832: Transliterate name, address, and city for USPS API (w/ FF)#7935
NavaTim merged 15 commits intomainfrom
tbradley/lg-7832-transliterate-usps-api-integration

Conversation

@NavaTim
Copy link
Contributor

@NavaTim NavaTim commented Mar 6, 2023

🎫 Ticket

🛠 Summary of changes

  • Transliterate the fields when sending them to USPS

📜 Testing Plan

Provide a checklist of steps to confirm the changes.

  • Finish IPP flow using details that need transliterated
  • Verify that info is sent to USPS in a transliterated form
  • Verify that Login stores non-transliterated info

changelog: Improvements, In-Person Proofing, USPS API Transliteration
@NavaTim NavaTim requested a review from zachmargolis March 6, 2023 22:57
stub_request_token
stub_request_enroll
allow(IdentityConfig.store).to receive(:usps_mock_fallback).and_return(usps_mock_fallback)
allow(UspsInPersonProofing::Transliterator).to receive(:new).and_return(transliterator)
Copy link
Contributor

Choose a reason for hiding this comment

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

in general I dislike stubbing .new, it's really broad. A rule I use is "don't stub what you don't own"

so a workaround would be that the enrollment helper has a memoized transliterator property that we stub in instead

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried using a memoized transliterator, and that didn't work well with tests at all. Really I prefer constructor injection (because I have had issues with both this approach and the property approach), but considered it out-of-scope to refactor for that here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would still stub the transliterator method rather than .new even if we're not memoizing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

transliterator function stubbed. I generally prefer to avoid stubbing any part of the subject, but I'll make an exception here.

@NavaTim NavaTim requested a review from zachmargolis March 7, 2023 00:29
end

def transliterator
Transliterator.new
Copy link
Contributor

Choose a reason for hiding this comment

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

this is stateless, so we could micro-optimize and save a few allocations by memoizing

or, we could probably just make transliterate a static method?

Suggested change
Transliterator.new
@transliterator ||= Transliterator.new

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is exactly what I tried before, and it caused the mock to be preserved between tests (and therefore the tests failed). I also don't think this micro-optimization has a high payoff.

Copy link
Contributor

Choose a reason for hiding this comment

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

oh I just saw that there's a class << self around all of this, no wonder there was test pollution. It's probably time to maybe split this class up and maybe maybe it stateful (ex InPersonEnroller.new(user).create_enrollment vs generic Helper), but that's definitely outside the scope of this PR

NavaTim and others added 3 commits March 6, 2023 18:12
Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
changed?: value != transliterated,
original: value,
transliterated: transliterated,
unsupported_chars: unsupported_chars,
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make more sense for unsupported_chars to be a boolean? Are we going to refer to the array values to update the characters in the transliterate/en.yml file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does it make more sense for unsupported_chars to be a boolean?

No, we need to the list of characters to generate the error message required by the story.

Are we going to refer to the array values to update the characters in the transliterate/en.yml file?

No. Monitoring transliteration in-detail is out-of-scope, and the characters could in some cases amount to additional recorded PII.

@NavaTim NavaTim requested a review from zachmargolis March 7, 2023 17:43
Copy link
Contributor

@zachmargolis zachmargolis left a comment

Choose a reason for hiding this comment

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

couple last small comments and this LGTM

let(:usps_ipp_transliteration_enabled) { true }

it 'creates usps enrollment while using transliteration' do
mock_proofer = double(UspsInPersonProofing::Mock::Proofer.class)
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto for the .class here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

enrollment.update(unique_id: nil)
proofer = UspsInPersonProofing::Mock::Proofer.new
mock = double
mock_proofer = double(UspsInPersonProofing::Mock::Proofer.class)
Copy link
Contributor

Choose a reason for hiding this comment

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

another .class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

NavaTim and others added 6 commits March 7, 2023 11:46
@NavaTim NavaTim merged commit c4500c4 into main Mar 7, 2023
@NavaTim NavaTim deleted the tbradley/lg-7832-transliterate-usps-api-integration branch March 7, 2023 20:39
@jmdembe jmdembe mentioned this pull request Mar 9, 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.

3 participants