Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions app/controllers/idv/in_person/public/address_search_controller.rb
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 app/controllers/idv/in_person/public/usps_locations_controller.rb
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
4 changes: 4 additions & 0 deletions config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ class Application < Rails::Application
origins IdentityCors.allowed_origins_static_sites
resource '/api/analytics-events', headers: :any, methods: [:get]
resource '/api/country-support', headers: :any, methods: [:get]
if IdentityConfig.store.in_person_public_address_search_enabled
resource '/api/address_search', headers: :any, methods: %i[post options]
resource '/api/usps_locations', headers: :any, methods: %i[post options]
end
end
end

Expand Down
1 change: 1 addition & 0 deletions config/application.yml.default
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ idv_tmx_test_csp_disabled_emails: '[]'
idv_tmx_test_js_disabled_emails: '[]'
idv_sp_required: false
in_person_capture_secondary_id_enabled: false
in_person_public_address_search_enabled: false
in_person_doc_auth_button_enabled: true
in_person_email_reminder_early_benchmark_in_days: 11
in_person_email_reminder_final_benchmark_in_days: 1
Expand Down
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
get '/api/openid_connect/userinfo' => 'openid_connect/user_info#show'
post '/api/risc/security_events' => 'risc/security_events#create'

post '/api/address_search' => 'idv/in_person/public/address_search#index'
match '/api/address_search' => 'idv/in_person/public/address_search#options', via: :options
post '/api/usps_locations' => 'idv/in_person/public/usps_locations#index'
match '/api/usps_locations' => 'idv/in_person/public/usps_locations#options', via: :options

namespace :api do
namespace :internal do
get '/sessions' => 'sessions#show'
Expand Down
1 change: 1 addition & 0 deletions lib/identity_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ def self.build_store(config_map)
config.add(:in_person_email_reminder_final_benchmark_in_days, type: :integer)
config.add(:in_person_email_reminder_late_benchmark_in_days, type: :integer)
config.add(:in_person_proofing_enabled, type: :boolean)
config.add(:in_person_public_address_search_enabled, type: :boolean)
config.add(:in_person_enrollment_validity_in_days, type: :integer)
config.add(:in_person_enrollments_ready_job_email_body_pattern, type: :string)
config.add(:in_person_enrollments_ready_job_cron, type: :string)
Expand Down
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)
Comment on lines +13 to +14
Copy link
Copy Markdown
Contributor Author

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:

    ActionController::UrlGenerationError:
       No route matches {:action=>"index", :address=>"100 main", :controller=>"idv/in_person/public/address_search", :host=>"www.example.com"}

Copy link
Copy Markdown
Contributor

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 careful

Copy link
Copy Markdown
Contributor

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_found to avoid that, ex:

check_or_render_not_found -> { IdentityConfig.store.in_person_proofing_enabled }

Copy link
Copy Markdown
Contributor Author

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.

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
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