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
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,26 @@ def index
)
locations = proofer.request_facilities(candidate, false)

render json: locations.to_json
render json: localized_locations(locations).to_json
end

def options
head :ok
end

protected
private

def proofer
@proofer ||= UspsInPersonProofing::EnrollmentHelper.usps_proofer
end

def localized_locations(locations)
return nil if locations.nil?
locations.map do |location|
UspsInPersonProofing::EnrollmentHelper.localized_location(location)
end
end

def enabled?
IdentityConfig.store.in_person_public_address_search_enabled
end
Expand Down
15 changes: 11 additions & 4 deletions app/controllers/idv/in_person/usps_locations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ def index
zip_code: search_params['zip_code']
)
is_enhanced_ipp = resolved_authn_context_result.enhanced_ipp?
response = proofer.request_facilities(candidate, is_enhanced_ipp)
if response.length > 0
locations = proofer.request_facilities(candidate, is_enhanced_ipp)
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.

@rutvigupta-design I'm including screenshots for you to look at.

French
Screenshot 2024-06-28 at 16 52 25

Spanish
Screenshot 2024-06-28 at 16 53 18

Chinese
Screenshot 2024-06-28 at 16 54 03

Copy link
Copy Markdown

@rutvigupta-design rutvigupta-design Jun 28, 2024

Choose a reason for hiding this comment

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

@eileen-nava the results LGTM but is there something strange going on in the H3 with all the languages? I don't think "lkn, lkn" in French, "kn, lkn" in Spanish, and "poj, ojpoj" should be there?

Screen Shot 2024-06-28 at 4 31 22 PM Screen Shot 2024-06-28 at 4 31 16 PM Screen Shot 2024-06-28 at 4 27 46 PM

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 think those are test values for the address/city fields in the search form

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ahh, okay that makes sense, thanks for clarifying! This LGTM then!

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.

@rutvigupta-design Mitchell is correct, I typed in nonsense values for a test address. Thanks for reviewing the PR! 🙏🏻

if locations.length > 0
analytics.idv_in_person_locations_searched(
success: true,
result_total: response.length,
result_total: locations.length,
)
else
analytics.idv_in_person_locations_searched(
success: false, errors: 'No USPS locations found',
)
end
render json: response.to_json
render json: localized_locations(locations).to_json
end

# save the Post Office location the user selected to an enrollment
Expand All @@ -64,6 +64,13 @@ def add_proofing_component
update(document_check: Idp::Constants::Vendors::USPS)
end

def localized_locations(locations)
return nil if locations.nil?
locations.map do |location|
EnrollmentHelper.localized_location(location)
end
Comment thread
mitchellhenke marked this conversation as resolved.
Outdated
end

def handle_error(err)
remapped_error = case err
when ActionController::InvalidAuthenticityToken,
Expand Down
4 changes: 3 additions & 1 deletion app/javascript/packs/document-capture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ interface AppRootData {
howToVerifyURL: string;
previousStepUrl: string;
docAuthSelfieDesktopTestMode: string;
locationsUrl: string;
}

const appRoot = document.getElementById('document-capture-form')!;
Expand Down Expand Up @@ -107,6 +108,7 @@ const {
howToVerifyUrl,
previousStepUrl,
docAuthSelfieDesktopTestMode,
locationsUrl: locationsURL,
} = appRoot.dataset as DOMStringMap & AppRootData;

let parsedUsStatesTerritories = [];
Expand All @@ -122,7 +124,7 @@ const App = composeComponents(
{
value: {
inPersonURL,
locationsURL: new URL('/verify/in_person/usps_locations', window.location.href).toString(),
locationsURL,
addressSearchURL: new URL('/api/addresses', window.location.href).toString(),
inPersonOutageMessageEnabled: inPersonOutageMessageEnabled === 'true',
inPersonOutageExpectedUpdateDate,
Expand Down
14 changes: 1 addition & 13 deletions app/presenters/idv/in_person/ready_to_verify_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def formatted_due_date
def selected_location_hours(prefix)
return unless selected_location_details
hours = selected_location_details["#{prefix}_hours"]
return localized_hours(hours) if hours
UspsInPersonProofing::EnrollmentHelper.localized_hours(hours) if hours
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.

👏🏻 Nice refactor, I like the idea of moving this to the EnrollmentHelper.

end

def service_provider
Expand Down Expand Up @@ -107,18 +107,6 @@ def format_outage_date(date)
I18n.l(date.to_date, format: :short)
end

def localized_hours(hours)
case hours
when 'Closed'
I18n.t('in_person_proofing.body.barcode.retail_hours_closed')
else
hours.
split(' - '). # Hyphen
map { |time| Time.zone.parse(time).strftime(I18n.t('time.formats.event_time')) }.
join(' – ') # Endash
end
end

def sp_return_url_resolver
SpReturnUrlResolver.new(service_provider: service_provider)
end
Expand Down
34 changes: 34 additions & 0 deletions app/services/usps_in_person_proofing/enrollment_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,40 @@ def usps_proofer
end
end

def localized_location(location)
{
address: location.address,
city: location.city,
distance: location.distance,
name: location.name,
saturday_hours: EnrollmentHelper.localized_hours(location.saturday_hours),
state: location.state,
sunday_hours: EnrollmentHelper.localized_hours(location.sunday_hours),
weekday_hours: EnrollmentHelper.localized_hours(location.weekday_hours),
zip_code_4: location.zip_code_4,
zip_code_5: location.zip_code_5,
is_pilot: location.is_pilot,
}
end

def localized_hours(hours)
if hours == 'Closed'
I18n.t('in_person_proofing.body.barcode.retail_hours_closed')
elsif hours.include?(' - ') # Hyphen
hours.
split(' - '). # Hyphen
map { |time| Time.zone.parse(time).strftime(I18n.t('time.formats.event_time')) }.
Comment thread
mitchellhenke marked this conversation as resolved.
Outdated
join(' – ') # Endash
elsif hours.include?(' – ') # Endash
hours.
split(' – '). # Endash
map { |time| Time.zone.parse(time).strftime(I18n.t('time.formats.event_time')) }.
join(' – ') # Endash
else
hours
end
end

private

SECONDARY_ID_ADDRESS_MAP = {
Expand Down
1 change: 1 addition & 0 deletions app/views/idv/shared/_document_capture.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
skip_doc_auth_from_handoff: skip_doc_auth_from_handoff,
how_to_verify_url: idv_how_to_verify_url,
previous_step_url: @previous_step_url,
locations_url: idv_in_person_usps_locations_url,
} %>
<%= simple_form_for(
:doc_auth,
Expand Down
51 changes: 42 additions & 9 deletions spec/controllers/idv/in_person/usps_locations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
let(:user) { create(:user) }
let(:sp) { nil }
let(:in_person_proofing_enabled) { true }
let(:empty_locations) { [] }
let(:address) do
UspsInPersonProofing::Applicant.new(
address: '1600 Pennsylvania Ave',
Expand Down Expand Up @@ -39,10 +38,12 @@
end

describe '#index' do
let(:locale) { nil }
let(:proofer) { double('Proofer') }
let(:locations) do
[
{ address: '3118 WASHINGTON BLVD',
UspsInPersonProofing::PostOffice.new(
address: '3118 WASHINGTON BLVD',
city: 'ARLINGTON',
distance: '6.02 mi',
name: 'ARLINGTON',
Expand All @@ -51,8 +52,10 @@
sunday_hours: 'Closed',
weekday_hours: '9:00 AM - 5:00 PM',
zip_code_4: '9998',
zip_code_5: '22201' },
{ address: '4005 WISCONSIN AVE NW',
zip_code_5: '22201',
),
UspsInPersonProofing::PostOffice.new(
address: '4005 WISCONSIN AVE NW',
city: 'WASHINGTON',
distance: '6.59 mi',
name: 'FRIENDSHIP',
Expand All @@ -61,8 +64,10 @@
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',
zip_code_5: '20016',
),
UspsInPersonProofing::PostOffice.new(
address: '6900 WISCONSIN AVE STE 100',
city: 'CHEVY CHASE',
distance: '8.99 mi',
name: 'BETHESDA',
Expand All @@ -71,11 +76,13 @@
sunday_hours: 'Closed',
weekday_hours: '9:00 AM - 5:00 PM',
zip_code_4: '9996',
zip_code_5: '20815' },
zip_code_5: '20815',
),
]
end
subject(:response) do
post :index, params: { address: { street_address: '1600 Pennsylvania Ave',
post :index, params: { locale: locale,
address: { street_address: '1600 Pennsylvania Ave',
city: 'Washington',
state: 'DC',
zip_code: '20500' } }
Expand Down Expand Up @@ -129,7 +136,7 @@
context 'no addresses found by usps' do
before do
allow(proofer).to receive(:request_facilities).with(address, false).
and_return(empty_locations)
and_return([])
end

it 'logs analytics with error when successful response is empty' do
Expand Down Expand Up @@ -165,6 +172,32 @@
response_status_code: nil,
)
end

context 'with non-English locale' do
let(:locale) { 'fr' }

it 'returns content in selected locale' do
json = response.body

expect(json).to include(
I18n.t('in_person_proofing.body.barcode.retail_hours_closed', locale: locale),
)
I18n.locale = locale
facilities = JSON.parse(json)

facilities.zip(locations).each do |facility, location|
expect(facility['weekday_hours']).to eq(
UspsInPersonProofing::EnrollmentHelper.localized_hours(location[:weekday_hours]),
)
expect(facility['saturday_hours']).to eq(
UspsInPersonProofing::EnrollmentHelper.localized_hours(location[:saturday_hours]),
)
expect(facility['sunday_hours']).to eq(
UspsInPersonProofing::EnrollmentHelper.localized_hours(location[:sunday_hours]),
)
end
end
end
end

context 'with a timeout from Faraday' do
Expand Down