Gyamada/lg 8861 usps locations are sorted#7900
Conversation
…ties by ascending distance (users address to post office)
| end | ||
|
|
||
| def sort_by_ascending_distance(facilities) | ||
| facilities.sort_by { |f| f[:distance].delete_suffix(' mi').to_f } |
There was a problem hiding this comment.
Turns out Ruby's String#to_f is super liberal, and is happy to parse a number out of a mixed string, maybe we drop the .delete_suffix?
"5.111 mi".to_f
=> 5.111
| facilities.sort_by { |f| f[:distance].delete_suffix(' mi').to_f } | |
| facilities.sort_by { |f| f[:distance].to_f } |
and that way if USPS ever changes units or formatting, this will continue to work
There was a problem hiding this comment.
Super liberal, thanks for the knowledge! 🥳 I made this update
| previous_post_office_distance = 0 | ||
| facilities.count do |post_office| | ||
| current_distance = post_office.distance.delete_suffix(' mi').to_f | ||
| expect(previous_post_office_distance).to be <= current_distance | ||
| previous_post_office_distance = current_distance | ||
| end |
There was a problem hiding this comment.
another way to test that they're sorted would be like an each_cons:
| previous_post_office_distance = 0 | |
| facilities.count do |post_office| | |
| current_distance = post_office.distance.delete_suffix(' mi').to_f | |
| expect(previous_post_office_distance).to be <= current_distance | |
| previous_post_office_distance = current_distance | |
| end | |
| expect(facilities.count).to be > 1 | |
| facilities.each_cons(2) do |facility_a, facility_b| | |
| expect(facility_a.distance).to be <= facility_b.distance | |
| end |
There was a problem hiding this comment.
Less code and cleaner! I made this update too
|
|
||
| facilities = parse_facilities(response) | ||
| dedupe_facilities(facilities) | ||
| sorted_facilities = sort_by_ascending_distance(facilities) |
There was a problem hiding this comment.
do we maybe want to remove the dupes before sorting - so we don't have to sort unnecessary locations?
There was a problem hiding this comment.
Yes! Good eye for detail. I made this update
|
@svalexander @zachmargolis Updates have been made. Thank you both for the feedback! 🙏 Other than the ways described in my testing plan, is there a way to hit USPS api locally to test this or is the test I have written and the tinker I have done enough in your opinion? If this is enough, I can remove draft. Please resolve comments if I have fulfilled suggestions. Let me know if you'd like to see anything else changed. |
Acceptance Criteria
|
|
Shannon paired with me on this so we could test this out with data returned from the API. Working as we would expect. Merging this in! |
🎫 Ticket
LG-8861
🛠 Summary of changes
Question for invidual doing review
Current: facilities.sort_by { |f| f[:distance].delete_suffix(' mi').to_f }
Thoughts: facilities.sort_by { |s | s[:distance] ? s[:distance].delete_suffix(' mi').to_f : +1000 }
📜 Testing Plan
Provide a checklist of steps to confirm the changes.
spec/services/usps_in_person_proofing/proofer_spec.rbarcgis_search_enabledtofalseinsideconfig/application.yml. Run through flow described above (It looks like the list is coming from ipp_pilot_usps_facitilites.json. All of the distances are null and my code is not breaking.)arcgis_search_enabledtotrueinsideconfig/application.yml. Edit the location distances inrequest_faciltities_response.jsonto be out of order. Run through flow described below.Flow:
/verify/doc_auth/welcomeverify/doc_auth/document_capture#location/verify/doc_auth/document_capture#locationyou should have ordered list👀 Screenshots
Test Results for spec/services/usps_in_person_proofing/proofer_spec.rb

My branch returned 3 different failure results so I ran the pipeline on Gitlab.

run 1: 7776 examples, 1022 failures, 7 pending
run 2: 7776 examples, 1068 failures, 7 pending
run 3: 7776 examples, 1042 failures, 7 pending
Pipeline Results on GitLab