Skip to content

LG-7719: IPP PO Search: findAddressCandidates setup#7199

Merged
allthesignals merged 8 commits intomainfrom
wmg/7718-usps-location-find-candidates
Oct 25, 2022
Merged

LG-7719: IPP PO Search: findAddressCandidates setup#7199
allthesignals merged 8 commits intomainfrom
wmg/7718-usps-location-find-candidates

Conversation

@allthesignals
Copy link
Contributor

🎫 Ticket

Link to the relevant ticket.

🛠 Summary of changes

Adds a new method wrapping findAddressCandidates API endpoint.

This method accepts a "magic_key" returned from #suggest.

There are many other ways to query findAddressCandidates, and the method can be expanded to be more flexible, but this is the current path for geocoding.

📜 Testing Plan

Provide a checklist of steps to confirm the changes.

  • Automated test coverage
  • Manual checks

🚀 Notes for Deployment

Still need to add the long-lived API token to deploy environments.

@allthesignals allthesignals requested review from a team and svalexander October 24, 2022 17:24
@allthesignals allthesignals changed the title Wmg/7718 usps location find candidates IPP PO Search: findAddressCandidates setup Oct 24, 2022
@allthesignals allthesignals changed the title IPP PO Search: findAddressCandidates setup LG-7719: IPP PO Search: findAddressCandidates setup Oct 24, 2022
Copy link
Contributor

@aduth aduth left a comment

Choose a reason for hiding this comment

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

👍


response_body['candidates'].map do |candidate|
AddressCandidate.new(
address: candidate['address'],
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: Do we need to extract this property? Or is it redundant if we could construct it with the other properties (street_address, city, state, zip_code)

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'm not sure yet. It could be used for display purposes later ("10 USPS locations found near ${address}"). We could construct it with the other properties, but I'm unsure what assumptions that would be making about what ESRI includes in a full "address," etc.

The other properties that I extract here are going to be the precise input values for a later request to USPS PO Search endpoint.

Copy link
Contributor

Choose a reason for hiding this comment

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

We could always add it in the future if it turns out that we need it. I'm typically in favor of YAGNI; granted, this whole thing is technically YAGNI since the UI doesn't exist yet 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeahhh. I sorta started this backwards. But I'm starting on the UI piece next, which'll give us a bit more direction on what we ARE going to need 😂

end
end

describe '#find_address_candidates' do
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we include some error cases here? Maybe as shared_examples or helper method if we're expecting it to behave the same across the two API calls.

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'll definitely add some error cases. My first issue is that the way we deal with HTTP mocks here inhibits reusability. This might be a little more configurable with something like VCR. I'll dig around for some examples where HTTP mocks are used along with shared_examples ("webauthn setup" for example)...

Copy link
Contributor

@aduth aduth left a comment

Choose a reason for hiding this comment

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

(Meant to approve with comments)

Copy link
Contributor

@sheldon-b sheldon-b left a comment

Choose a reason for hiding this comment

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

Looks good! Left a couple minor comments

allthesignals and others added 4 commits October 25, 2022 15:51
Co-authored-by: Sheldon Bachstein <sheldon.bachstein@gsa.gov>
Co-authored-by: Sheldon Bachstein <sheldon.bachstein@gsa.gov>
Co-authored-by: Sheldon Bachstein <sheldon.bachstein@gsa.gov>
Copy link
Contributor Author

@allthesignals allthesignals Oct 25, 2022

Choose a reason for hiding this comment

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

Note:

One thing I changed up in the mapping: for the sake of simplicity, I made location into an array, which orders as [x,y], according to the GeoJSON spec as well as how ESRI/ArcGIS represents coordinates.

Copy link
Contributor

Choose a reason for hiding this comment

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

I have spent a decent amount of time with GeoJSON and always confuse myself with the nameless array syntax, could we make a Location struct with named latitude, longitude members (could also be a follow-up for a future PR where we actually drop pins on a map, but wanted to flag this now)

Copy link
Contributor Author

@allthesignals allthesignals Oct 25, 2022

Choose a reason for hiding this comment

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

Sure thing! Yeah, you're probably right. I'll go ahead and do it for this PR.

GeoJSON describes an order for coordinates: they should go, in order: [longitude, latitude, elevation]... Historically, the order of coordinates is usually “latitude, longitude”, and many people will assume that this is the case universally. Long hours have been wasted discussing which is better... applications have tended to use latitude, longitude order

So, there's widespread ambiguity there, and I've been bit by mixing it up in the past, so explicit it is...

@allthesignals allthesignals force-pushed the wmg/7718-usps-location-find-candidates branch from f0c2588 to 2d4f7ab Compare October 25, 2022 22:33
Copy link
Contributor Author

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.

@zachmargolis not sure whether this is the best way to assert for this?

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 probably fine. If you wanted to remove that long namespace, you could assert on .as_json instead of .to_h, and compare string keys:

diff --git a/spec/services/arcgis_api/geocoder_spec.rb b/spec/services/arcgis_api/geocoder_spec.rb
index 2763bca4f..9b9040256 100644
--- a/spec/services/arcgis_api/geocoder_spec.rb
+++ b/spec/services/arcgis_api/geocoder_spec.rb
@@ -40,14 +40,14 @@ RSpec.describe ArcgisApi::Geocoder do
 
       suggestions = subject.find_address_candidates('abc123')
 
-      expect(suggestions.first.to_h).to eq(
+      expect(suggestions.first.as_json).to eq(
         {
-          address: '100 Main Ave, La Grande, Oregon, 97850',
-          location: ArcgisApi::Geocoder::Location.new(longitude: -118.10754025791812, latitude: 45.328271485226445),
-          street_address: '100 Main Ave',
-          city: 'La Grande',
-          state: 'OR',
-          zip_code: '97850',
+          'address' => '100 Main Ave, La Grande, Oregon, 97850',
+          'location' => { 'longitude' => -118.10754025791812, 'latitude' => 45.328271485226445 },
+          'street_address' => '100 Main Ave',
+          'city' => 'La Grande',
+          'state' => 'OR',
+          'zip_code' => '97850',
         },
       )
     end

@allthesignals allthesignals force-pushed the wmg/7718-usps-location-find-candidates branch from 2d4f7ab to 4bee11b Compare October 25, 2022 22:59
@allthesignals allthesignals merged commit 2f37a9d into main Oct 25, 2022
@allthesignals allthesignals deleted the wmg/7718-usps-location-find-candidates branch October 25, 2022 23:32
Comment on lines +100 to +102
latitude: candidate.dig(
'location', 'y'
),
Copy link
Contributor

Choose a reason for hiding this comment

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

how come this shorter line had to break?

Suggested change
latitude: candidate.dig(
'location', 'y'
),
latitude: candidate.dig('location', 'y'),

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oof, not sure. Rubocop? I'll fix it in this future PR.

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.

4 participants