diff --git a/app/controllers/idv/in_person/public/address_search_controller.rb b/app/controllers/idv/in_person/public/address_search_controller.rb new file mode 100644 index 00000000000..d05efe033ef --- /dev/null +++ b/app/controllers/idv/in_person/public/address_search_controller.rb @@ -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 diff --git a/app/controllers/idv/in_person/public/usps_locations_controller.rb b/app/controllers/idv/in_person/public/usps_locations_controller.rb new file mode 100644 index 00000000000..d50959d62cc --- /dev/null +++ b/app/controllers/idv/in_person/public/usps_locations_controller.rb @@ -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 diff --git a/config/application.rb b/config/application.rb index 53137f95769..85f9cb41d01 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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 diff --git a/config/application.yml.default b/config/application.yml.default index 10c9623bf9e..1b44e3e9cc1 100644 --- a/config/application.yml.default +++ b/config/application.yml.default @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 65fb8ce61ea..12b19273c86 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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' diff --git a/lib/identity_config.rb b/lib/identity_config.rb index 1c2368a2368..946837ab0ee 100644 --- a/lib/identity_config.rb +++ b/lib/identity_config.rb @@ -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) diff --git a/spec/controllers/idv/in_person/public/address_search_controller_spec.rb b/spec/controllers/idv/in_person/public/address_search_controller_spec.rb new file mode 100644 index 00000000000..f89ee482b76 --- /dev/null +++ b/spec/controllers/idv/in_person/public/address_search_controller_spec.rb @@ -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 diff --git a/spec/controllers/idv/in_person/public/usps_locations_controller_spec.rb b/spec/controllers/idv/in_person/public/usps_locations_controller_spec.rb new file mode 100644 index 00000000000..6dc427fdf5f --- /dev/null +++ b/spec/controllers/idv/in_person/public/usps_locations_controller_spec.rb @@ -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