-
Notifications
You must be signed in to change notification settings - Fork 166
LG-9168: Set up public mock address search and usps location search endpoints #8869
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
15 commits
Select commit
Hold shift + click to select a range
d178e71
changelog: Internal, In-Person Proofing, Set up mock address and usps…
allthesignals d08c35e
Allow the public endpoints
allthesignals 4cf3dd5
Add feature flag protection
allthesignals dc56792
Split up controllers to more closely match what we need in future
allthesignals bffa064
Duplicate controller details
allthesignals 90c48e5
Lint
allthesignals 65f63b5
Rename feature flag; permit options verb
allthesignals 2afe349
Test shell
allthesignals fed13ee
Failing spec
allthesignals 214c78a
Fix tests
allthesignals a9c1afa
Update spec/controllers/idv/in_person/public/address_search_controlle…
allthesignals 8337c47
Update spec/controllers/idv/in_person/public/usps_locations_controlle…
allthesignals 763092e
Test matches for consistency
allthesignals f90ee0c
Merge branch 'main' into wmg/9168-mock-endpoints
allthesignals f75504f
rename public route
allthesignals 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
33 changes: 33 additions & 0 deletions
33
app/controllers/idv/in_person/public/address_search_controller.rb
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,33 @@ | ||
| module Idv | ||
| module InPerson | ||
| module Public | ||
| class AddressSearchController < ApplicationController | ||
| include RenderConditionConcern | ||
|
|
||
| check_or_render_not_found -> { enabled? } | ||
|
|
||
| skip_forgery_protection | ||
|
|
||
| def index | ||
| addresses = geocoder.find_address_candidates(SingleLine: params[:address]).slice(0, 1) | ||
|
|
||
| render json: addresses.to_json | ||
| end | ||
|
|
||
| def options | ||
| head :ok | ||
| end | ||
|
|
||
| protected | ||
|
|
||
| def geocoder | ||
| ArcgisApi::Mock::Geocoder.new | ||
| end | ||
|
|
||
| def enabled? | ||
| IdentityConfig.store.in_person_public_address_search_enabled | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
47 changes: 47 additions & 0 deletions
47
app/controllers/idv/in_person/public/usps_locations_controller.rb
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,47 @@ | ||
| module Idv | ||
| module InPerson | ||
| module Public | ||
| class UspsLocationsController < ApplicationController | ||
| include RenderConditionConcern | ||
|
|
||
| check_or_render_not_found -> { enabled? } | ||
|
|
||
| skip_forgery_protection | ||
|
|
||
| def index | ||
| candidate = UspsInPersonProofing::Applicant.new( | ||
| address: search_params['street_address'], | ||
| city: search_params['city'], state: search_params['state'], | ||
| zip_code: search_params['zip_code'] | ||
| ) | ||
| locations = proofer.request_facilities(candidate) | ||
|
|
||
| render json: locations.to_json | ||
| end | ||
|
|
||
| def options | ||
| head :ok | ||
| end | ||
|
|
||
| protected | ||
|
|
||
| def proofer | ||
| UspsInPersonProofing::Mock::Proofer.new | ||
| end | ||
|
|
||
| def enabled? | ||
| IdentityConfig.store.in_person_public_address_search_enabled | ||
| end | ||
|
|
||
| def search_params | ||
| params.require(:address).permit( | ||
| :street_address, | ||
| :city, | ||
| :state, | ||
| :zip_code, | ||
| ) | ||
| end | ||
| end | ||
| 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
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
36 changes: 36 additions & 0 deletions
36
spec/controllers/idv/in_person/public/address_search_controller_spec.rb
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,36 @@ | ||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe Idv::InPerson::Public::AddressSearchController do | ||
| include Rails.application.routes.url_helpers | ||
|
|
||
| describe '#index' do | ||
| subject(:action) do | ||
| post :index, params: { address: '100 main' } | ||
| end | ||
|
|
||
| context 'with feature flag off' do | ||
| before do | ||
| allow(IdentityConfig.store).to receive(:in_person_public_address_search_enabled). | ||
| and_return(false) | ||
| end | ||
|
|
||
| it 'is a 400' do | ||
| action | ||
|
|
||
| expect(response).to be_not_found | ||
| end | ||
| end | ||
|
|
||
| context 'with feature flag on' do | ||
| before do | ||
| allow(IdentityConfig.store).to receive(:in_person_public_address_search_enabled). | ||
| and_return(true) | ||
| end | ||
|
|
||
| it 'is successful and has a response' do | ||
| action | ||
| expect(response).to be_ok | ||
| end | ||
| end | ||
| end | ||
| end | ||
45 changes: 45 additions & 0 deletions
45
spec/controllers/idv/in_person/public/usps_locations_controller_spec.rb
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,45 @@ | ||
| require 'rails_helper' | ||
|
|
||
| RSpec.describe Idv::InPerson::Public::UspsLocationsController do | ||
| include Rails.application.routes.url_helpers | ||
|
|
||
| describe '#index' do | ||
| subject(:action) do | ||
| post :index, | ||
| params: { | ||
| address: { | ||
| address: '87060 Colby Radial, Stephenmouth, OK 73339-7909', | ||
| zip_code: '73339', | ||
| state: 'OK', | ||
| city: 'Stephenmouth', | ||
| street_address: '87060 Colby Radial', | ||
| }, | ||
| } | ||
| end | ||
|
|
||
| context 'with feature flag on' do | ||
| before do | ||
| allow(IdentityConfig.store).to receive(:in_person_public_address_search_enabled). | ||
| and_return(true) | ||
| end | ||
|
|
||
| it 'is successful and has a response' do | ||
| action | ||
| expect(response).to be_ok | ||
| end | ||
| end | ||
|
|
||
| context 'with feature flag off' do | ||
| before do | ||
| allow(IdentityConfig.store).to receive(:in_person_public_address_search_enabled). | ||
| and_return(false) | ||
| end | ||
|
|
||
| it 'is a 400' do | ||
| action | ||
|
|
||
| expect(response).to be_not_found | ||
| end | ||
| 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.
Struggling to get the test to work with this stub... it seems to recognize the routes when I change the default value of this config variable. However, it doesn't recognize routes when I try to stub over the default:
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.
I think you need to call
Rails.application.reload_routes!before/after to reload the specs. We've had lots of issues with test pollution with this in the past, so I'd be carefulThere 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.
Yeah, I think the preference is to use
check_or_render_not_foundto avoid that, ex:identity-idp/app/controllers/idv/in_person/ready_to_verify_controller.rb
Line 8 in 9a6deb8
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.
I see. I think we cannot test when the flag is off if we wrap the actual routes in routes.rb with a feature flag (looking here for precedent).
The ready_to_verify_controller maps to routes that are not hidden behind a feature flag in routes...
I'll change this around and see what you think.