-
Notifications
You must be signed in to change notification settings - Fork 167
LG-7925 Backend pings USPS API for IPP locations #7386
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
Changes from all commits
f5a7ded
4831283
18baade
44804bd
8d981c1
d80f0e6
80d35af
24b2a47
1971368
d1cba60
d43dab4
35a4fd4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,19 @@ | |
| let(:user) { create(:user) } | ||
| let(:sp) { nil } | ||
| let(:in_person_proofing_enabled) { true } | ||
| let(:arcgis_search_enabled) { true } | ||
| let(:address) do | ||
| UspsInPersonProofing::Applicant.new( | ||
| address: '1600 Pennsylvania Ave', | ||
| city: 'Washington', state: 'DC', zip_code: '20500' | ||
| ) | ||
| end | ||
| let(:fake_address) do | ||
| UspsInPersonProofing::Applicant.new( | ||
| address: '742 Evergreen Terrace', | ||
| city: 'Springfield', state: 'MO', zip_code: '89011' | ||
| ) | ||
| end | ||
| let(:selected_location) do | ||
| { | ||
| usps_location: { | ||
|
|
@@ -25,53 +38,131 @@ | |
| stub_sign_in(user) if user | ||
| allow(IdentityConfig.store).to receive(:in_person_proofing_enabled). | ||
| and_return(in_person_proofing_enabled) | ||
| allow(IdentityConfig.store).to receive(:arcgis_search_enabled). | ||
| and_return(arcgis_search_enabled) | ||
| allow(controller).to receive(:current_sp).and_return(sp) | ||
| end | ||
|
|
||
| describe '#index' do | ||
| let(:proofer) { double('Proofer') } | ||
| let(:locations) do | ||
| [ | ||
| { address: '3118 WASHINGTON BLVD', | ||
| city: 'ARLINGTON', | ||
| distance: '6.02 mi', | ||
| name: 'ARLINGTON', | ||
| phone: '703-993-0072', | ||
| saturday_hours: '9:00 AM - 1:00 PM', | ||
| state: 'VA', | ||
| sunday_hours: 'Closed', | ||
| weekday_hours: '9:00 AM - 5:00 PM', | ||
| zip_code_4: '9998', | ||
| zip_code_5: '22201' }, | ||
| { address: '4005 WISCONSIN AVE NW', | ||
| city: 'WASHINGTON', | ||
| distance: '6.59 mi', | ||
| name: 'FRIENDSHIP', | ||
| phone: '202-842-3332', | ||
| saturday_hours: '8:00 AM - 4:00 PM', | ||
| state: 'DC', | ||
| sunday_hours: '10:00 AM - 4:00 PM', | ||
| weekday_hours: '8:00 AM - 6:00 PM', | ||
| zip_code_4: '9997', | ||
| zip_code_5: '20016' }, | ||
| { address: '6900 WISCONSIN AVE STE 100', | ||
| city: 'CHEVY CHASE', | ||
| distance: '8.99 mi', | ||
| name: 'BETHESDA', | ||
| phone: '301-941-2670', | ||
| saturday_hours: '9:00 AM - 4:00 PM', | ||
| state: 'MD', | ||
| sunday_hours: 'Closed', | ||
| weekday_hours: '9:00 AM - 5:00 PM', | ||
| zip_code_4: '9996', | ||
| zip_code_5: '20815' }, | ||
| ] | ||
| end | ||
| let(:pilot_locations) do | ||
| [ | ||
| { name: 'Location 1' }, | ||
| { name: 'Location 2' }, | ||
| { name: 'Location 3' }, | ||
| { name: 'Location 4' }, | ||
| ] | ||
| end | ||
| subject(:response) { get :index } | ||
| subject(:response) do | ||
| post :index, params: { address: { street_address: '1600 Pennsylvania Ave', | ||
| city: 'Washington', | ||
| state: 'DC', zip_code: '20500' } } | ||
| end | ||
|
|
||
| before do | ||
| allow(UspsInPersonProofing::Proofer).to receive(:new).and_return(proofer) | ||
| end | ||
|
|
||
| context 'with successful fetch' do | ||
| before do | ||
| allow(proofer).to receive(:request_pilot_facilities).and_return(locations) | ||
| context 'with arcgis search enabled' do | ||
| context 'with a nil address in params' do | ||
| before do | ||
| allow(proofer).to receive(:request_pilot_facilities).and_return(pilot_locations) | ||
| end | ||
|
|
||
| subject(:response) do | ||
| post :index, params: { address: nil } | ||
| end | ||
|
|
||
| it 'returns the pilot locations' do | ||
| json = response.body | ||
| facilities = JSON.parse(json) | ||
| expect(facilities.length).to eq 4 | ||
| end | ||
| end | ||
|
|
||
| it 'gets successful pilot response' do | ||
| response = get :index | ||
| json = response.body | ||
| facilities = JSON.parse(json) | ||
| expect(facilities.length).to eq 4 | ||
| context 'with successful fetch' do | ||
| before do | ||
| allow(proofer).to receive(:request_facilities).with(address).and_return(locations) | ||
|
Contributor
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. non-blocking observation: one pattern I've learned about from zach is to wrap an "external" class like this in a method and stub that method instead: https://github.com/18F/identity-idp/blob/main/app/controllers/idv/in_person/address_search_controller.rb#L22-L24. So, you could have a
Contributor
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. zach agrees!
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. I implemented this change in the controller. I haven't changed the test setup, but can do so tomorrow. I'm logging off for the day, but I am also considering mocking the proofer. Sheldon suggested this refactor, and noted this method in the
Contributor
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. zach also likes mocking the proofer, esp useful for lower envs that said, I'm wondering if it would be ok to use "real" arcgis in a lower env, like we use real SMS and real voice so people can acually use the app
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. Good question. I'll bring this up during the next PO search check-in meeting.
Contributor
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. i think it's probably fine. i suspect voice and SMS billing is done on a credit system? we're using GSA's hosted service, and it isn't constrained in that way. open to other angles, though!
Contributor
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. Another thought: if the idea is to have addresses that are close to PO locations... and in mock world the PO locations are fake, maybe it does make sense to have a fake here? So that it can return things that the mock USPS service recognizes? I could go either way on this
Contributor
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. I misunderstood! I think that makes sense, for the local environment. |
||
| end | ||
|
|
||
| it 'returns a successful response' do | ||
| json = response.body | ||
| facilities = JSON.parse(json) | ||
| expect(facilities.length).to eq 3 | ||
| end | ||
| end | ||
| end | ||
|
|
||
| context 'with unsuccessful fetch' do | ||
| before do | ||
| exception = Faraday::ConnectionFailed.new('error') | ||
| allow(proofer).to receive(:request_pilot_facilities).and_raise(exception) | ||
| context 'with unsuccessful fetch' do | ||
| before do | ||
| exception = Faraday::ConnectionFailed.new('error') | ||
| allow(proofer).to receive(:request_facilities).with(fake_address).and_raise(exception) | ||
| end | ||
|
|
||
| it 'gets an empty response' do | ||
| response = post :index, | ||
| params: { address: { street_address: '742 Evergreen Terrace', | ||
| city: 'Springfield', | ||
| state: 'MO', zip_code: '89011' } } | ||
| json = response.body | ||
| facilities = JSON.parse(json) | ||
| expect(facilities.length).to eq 0 | ||
| end | ||
| end | ||
| end | ||
|
|
||
| it 'gets an empty pilot response' do | ||
| response = get :index | ||
| json = response.body | ||
| facilities = JSON.parse(json) | ||
| expect(facilities.length).to eq 0 | ||
| context 'with arcgis search disabled' do | ||
| let(:arcgis_search_enabled) { false } | ||
| context 'with successful fetch' do | ||
| before do | ||
| allow(proofer).to receive(:request_pilot_facilities).and_return(pilot_locations) | ||
| end | ||
|
|
||
| it 'returns a successful response' do | ||
| json = response.body | ||
| facilities = JSON.parse(json) | ||
| expect(facilities.length).to eq 4 | ||
| end | ||
| end | ||
| end | ||
|
|
||
| context 'with feature disabled' do | ||
| context 'with in person proofing disabled' do | ||
| let(:in_person_proofing_enabled) { false } | ||
|
|
||
| it 'renders 404' do | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
Now that this switch from post to get has been deployed, it should be safe to remove this