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: 3 additions & 1 deletion app/jobs/resolution_proofing_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ def proof_lexisnexis_then_aamva(timer:, applicant_pii:, should_proof_state_id:)
resolution_proofer.proof(applicant_pii)
end

state_id_result = Proofing::Aamva::UnsupportedJurisdictionResult.new
state_id_result = Proofing::StateIdResult.new(
success: true, errors: {}, exception: nil, vendor_name: 'UnsupportedJurisdiction',
)
if should_proof_state_id && resolution_result.success?
timer.time('state_id') do
state_id_result = state_id_proofer.proof(applicant_pii)
Expand Down
62 changes: 59 additions & 3 deletions app/services/proofing/aamva/proofer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,71 @@ def initialize(config)
def proof(applicant)
aamva_applicant =
Aamva::Applicant.from_proofer_applicant(OpenStruct.new(applicant))
response = Aamva::VerificationClient.new(
verification_response = Aamva::VerificationClient.new(
config,
).send_verification_request(
applicant: aamva_applicant,
)
Aamva::Result.new(response)
build_result_from_response(verification_response)
rescue => exception
NewRelic::Agent.notice_error(exception)
Proofing::Result.new(exception: exception)
Proofing::StateIdResult.new(
success: false, errors: {}, exception: exception, vendor_name: 'aamva:state_id',
transaction_id: nil, verified_attributes: []
)
end

private

def build_result_from_response(verification_response)
Proofing::StateIdResult.new(
success: verification_response.success?,
errors: parse_verification_errors(verification_response),
exception: nil,
vendor_name: 'aamva:state_id',
transaction_id: verification_response.transaction_locator_id,
verified_attributes: verified_attributes(verification_response),
)
end

def parse_verification_errors(verification_response)
errors = errors = Hash.new { |h, k| h[k] = [] }

return errors if verification_response.success?

verification_response.verification_results.each do |attribute, v_result|
attribute_key = attribute.to_sym
next if v_result == true
errors[attribute_key] << 'UNVERIFIED' if v_result == false
errors[attribute_key] << 'MISSING' if v_result.nil?
end
errors
end

def verified_attributes(verification_response)
attributes = Set.new
results = verification_response.verification_results

attributes.add :address if address_verified?(results)

results.delete :address1
results.delete :address2
results.delete :city
results.delete :state
results.delete :zipcode

results.each do |attribute, verified|
attributes.add attribute if verified
end

attributes
end

def address_verified?(results)
results[:address1] &&
results[:city] &&
results[:state] &&
results[:zipcode]
end
end
end
Expand Down
89 changes: 0 additions & 89 deletions app/services/proofing/aamva/result.rb

This file was deleted.

34 changes: 0 additions & 34 deletions app/services/proofing/aamva/result_with_exception.rb

This file was deleted.

40 changes: 0 additions & 40 deletions app/services/proofing/aamva/unsupported_jurisdiction_result.rb

This file was deleted.

41 changes: 13 additions & 28 deletions app/services/proofing/mock/state_id_mock_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,6 @@ class StateIdMockClient < Proofing::Base
TRANSACTION_ID = 'state-id-mock-transaction-id-456'
TRIGGER_MVA_TIMEOUT = 'mvatimeout'

StateIdMockClientResult = Struct.new(:success, :errors, :exception, keyword_init: true) do
def success?
success
end

def timed_out?
exception.is_a?(Proofing::TimeoutError)
end

def transaction_id
TRANSACTION_ID
end

def to_h
{
exception: exception,
errors: errors,
success: success,
timed_out: timed_out?,
transaction_id: transaction_id,
vendor_name: 'StateIdMock',
}
end
end

def proof(applicant)
return mva_timeout_result if applicant[:state_id_number].downcase == TRIGGER_MVA_TIMEOUT

Expand All @@ -50,26 +25,36 @@ def proof(applicant)

return unverifiable_result(errors) if errors.any?

StateIdMockClientResult.new(success: true, errors: {}, exception: nil)
StateIdResult.new(
success: true,
errors: {},
exception: nil,
vendor_name: 'StateIdMock',
transaction_id: TRANSACTION_ID,
)
end

private

def mva_timeout_result
StateIdMockClientResult.new(
StateIdResult.new(
success: false,
errors: {},
exception: Proofing::TimeoutError.new(
'ExceptionId: 0047, ExceptionText: MVA did not respond in a timely fashion',
),
vendor_name: 'StateIdMock',
transaction_id: TRANSACTION_ID,
)
end

def unverifiable_result(errors)
StateIdMockClientResult.new(
StateIdResult.new(
success: false,
errors: errors,
exception: nil,
vendor_name: 'StateIdMock',
transaction_id: TRANSACTION_ID,
)
end

Expand Down
41 changes: 41 additions & 0 deletions app/services/proofing/state_id_result.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
module Proofing
class StateIdResult
attr_reader :success, :errors, :exception, :vendor_name, :transaction_id, :verified_attributes

def initialize(
success:,
errors:,
exception:,
vendor_name:,
transaction_id: '',
verified_attributes: []
)
@success = success
@errors = errors
@exception = exception
@vendor_name = vendor_name
@transaction_id = transaction_id
@verified_attributes = verified_attributes
end

def success?
success
end

def timed_out?
exception.is_a?(Proofing::TimeoutError)
end

def to_h
{
success: success?,
errors: errors,
exception: exception,
timed_out: timed_out?,
transaction_id: transaction_id,
vendor_name: vendor_name,
verified_attributes: verified_attributes,
}
end
end
end
2 changes: 1 addition & 1 deletion spec/jobs/resolution_proofing_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
expect(result_context_stages_state_id[:success]).to eq(true)
expect(result_context_stages_state_id[:timed_out]).to eq(false)
expect(result_context_stages_state_id[:transaction_id]).to eq('')
expect(result_context_stages_state_id[:verified_attributes]).to eq(nil)
expect(result_context_stages_state_id[:verified_attributes]).to eq([])

# result[:context][:stages][:threatmetrix]
expect(result_context_stages_threatmetrix[:client]).to eq('DdpMock')
Expand Down
3 changes: 3 additions & 0 deletions spec/services/proofing/mock/state_id_mock_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
timed_out: false,
transaction_id: transaction_id,
vendor_name: 'StateIdMock',
verified_attributes: [],
)
end
end
Expand All @@ -43,6 +44,7 @@
timed_out: false,
transaction_id: transaction_id,
vendor_name: 'StateIdMock',
verified_attributes: [],
)
end
end
Expand All @@ -63,6 +65,7 @@
timed_out: true,
transaction_id: transaction_id,
vendor_name: 'StateIdMock',
verified_attributes: [],
)
end
end
Expand Down