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
4 changes: 4 additions & 0 deletions app/services/usps_in_person_proofing/mock/fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ def self.internal_server_error_response
load_response_fixture('internal_server_error_response.json')
end

def self.request_expired_token_response
load_response_fixture('request_expired_token_response.json')
end

def self.request_token_response
load_response_fixture('request_token_response.json')
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"token_type": "Bearer",
"access_token": "==BAAyMP2ZHGOIeTd17YomIf7XjZUL4G93dboY1pTsuTJN0s9BwMYvOcIS9B3gRvloK2sroi9uFXdXrFuly7==",
"expires_in": 0
}
15 changes: 10 additions & 5 deletions app/services/usps_in_person_proofing/proofer.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module UspsInPersonProofing
class Proofer
AUTH_TOKEN_CACHE_KEY = :usps_ippaas_api_auth_token
AUTH_TOKEN_REFRESH_THRESHOLD = 5

# Makes HTTP request to get nearby in-person proofing facilities
# Requires address, city, state and zip code.
Expand All @@ -18,11 +19,11 @@ def request_facilities(location)
zipCode: location.zip_code,
}.to_json

facilities = parse_facilities(
faraday.post(url, body, dynamic_headers) do |req|
req.options.context = { service_name: 'usps_facilities' }
end.body,
)
response = faraday.post(url, body, dynamic_headers) do |req|
req.options.context = { service_name: 'usps_facilities' }
end.body

facilities = parse_facilities(response)
dedupe_facilities(facilities)
end

Expand Down Expand Up @@ -153,6 +154,10 @@ def faraday
# already cached.
# @return [Hash] Headers to add to USPS requests
def dynamic_headers
token_remaining_time = Rails.cache.redis.ttl(AUTH_TOKEN_CACHE_KEY)
if token_remaining_time != -2 && token_remaining_time <= AUTH_TOKEN_REFRESH_THRESHOLD
retrieve_token!
end
{
'Authorization' => token,
'RequestID' => request_id,
Expand Down
3 changes: 3 additions & 0 deletions spec/controllers/idv/review_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,9 @@ def show

context 'user picked phone confirmation' do
before do
allow(Rails).to receive(:cache).and_return(
ActiveSupport::Cache::RedisCacheStore.new(url: IdentityConfig.store.redis_throttle_url),
)
idv_session.address_verification_mechanism = 'phone'
idv_session.vendor_phone_confirmation = true
idv_session.user_phone_confirmation = true
Expand Down
4 changes: 3 additions & 1 deletion spec/jobs/get_usps_proofing_results_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@
RSpec.shared_examples 'enrollment_encountering_an_error_that_has_a_nil_response' do |error_type:|
it 'logs that response is not present' do
expect(NewRelic::Agent).to receive(:notice_error).with(instance_of(error_type))

job.perform(Time.zone.now)

expect(job_analytics).to have_logged_event(
Expand All @@ -147,6 +146,9 @@
let(:job_analytics) { FakeAnalytics.new }

before do
allow(Rails).to receive(:cache).and_return(
ActiveSupport::Cache::RedisCacheStore.new(url: IdentityConfig.store.redis_throttle_url),
)
ActiveJob::Base.queue_adapter = :test
allow(job).to receive(:analytics).and_return(job_analytics)
allow(IdentityConfig.store).to receive(:get_usps_proofing_results_job_reprocess_delay_minutes).
Expand Down
3 changes: 3 additions & 0 deletions spec/lib/tasks/dev_rake_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@
describe 'dev:random_in_person_users' do
before(:each) do
allow(IdentityConfig.store).to receive(:usps_mock_fallback).and_return(false)
allow(Rails).to receive(:cache).and_return(
ActiveSupport::Cache::RedisCacheStore.new(url: IdentityConfig.store.redis_throttle_url),
)
ENV['VERIFIED'] = nil
Rake::Task['dev:random_in_person_users'].reenable
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
end

context 'an establishing enrollment record exists for the user' do
before do
allow(Rails).to receive(:cache).and_return(
ActiveSupport::Cache::RedisCacheStore.new(url: IdentityConfig.store.redis_throttle_url),
)
end
it 'updates the existing enrollment record' do
expect(user.in_person_enrollments.length).to eq(1)

Expand Down
Loading