diff --git a/app/jobs/resolution_proofing_job.rb b/app/jobs/resolution_proofing_job.rb index 9934d67d4e2..55c85d9ce3b 100644 --- a/app/jobs/resolution_proofing_job.rb +++ b/app/jobs/resolution_proofing_job.rb @@ -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) diff --git a/app/services/proofing/aamva/proofer.rb b/app/services/proofing/aamva/proofer.rb index 4da13c490e7..5f9e855944c 100644 --- a/app/services/proofing/aamva/proofer.rb +++ b/app/services/proofing/aamva/proofer.rb @@ -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 diff --git a/app/services/proofing/aamva/result.rb b/app/services/proofing/aamva/result.rb deleted file mode 100644 index bb324578d3a..00000000000 --- a/app/services/proofing/aamva/result.rb +++ /dev/null @@ -1,89 +0,0 @@ -module Proofing - module Aamva - class Result - attr_reader :verification_response - - delegate( - :success?, - to: :verification_response, - ) - - def initialize(verification_response) - raise ArgumentError unless verification_response.instance_of? Response::VerificationResponse - @verification_response = verification_response - end - - def errors - return @errors if defined? @errors - - @errors = {} - 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] ||= [] - @errors[attribute_key].push('UNVERIFIED') if v_result == false - @errors[attribute_key].push('MISSING') if v_result.nil? - end - @errors - end - - def transaction_id - verification_response.transaction_locator_id - end - - def exception - nil - end - - def timed_out? - false - end - - def vendor_name - 'aamva:state_id' - end - - def verified_attributes - 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 to_h - { - exception: exception, - errors: errors, - success: success?, - timed_out: timed_out?, - transaction_id: transaction_id, - vendor_name: vendor_name, - verified_attributes: verified_attributes.to_a, - } - end - - private - - def address_verified?(results) - results[:address1] && - results[:city] && - results[:state] && - results[:zipcode] - end - end - end -end diff --git a/app/services/proofing/aamva/result_with_exception.rb b/app/services/proofing/aamva/result_with_exception.rb deleted file mode 100644 index 2c0de467dd4..00000000000 --- a/app/services/proofing/aamva/result_with_exception.rb +++ /dev/null @@ -1,34 +0,0 @@ -module Proofing - module Aamva - class ResultWithException - attr_reader :exception, :vendor_name - - def initialize(exception, vendor_name:) - @exception = exception - @vendor_name = vendor_name - end - - def success? - false - end - - def errors - {} - end - - def timed_out? - exception.is_a?(Proofing::TimeoutError) - end - - def to_h - { - success: success?, - errors: errors, - exception: exception, - timed_out: timed_out?, - vendor_name: vendor_name, - } - end - end - end -end diff --git a/app/services/proofing/aamva/unsupported_jurisdiction_result.rb b/app/services/proofing/aamva/unsupported_jurisdiction_result.rb deleted file mode 100644 index ee6d90a703d..00000000000 --- a/app/services/proofing/aamva/unsupported_jurisdiction_result.rb +++ /dev/null @@ -1,40 +0,0 @@ -module Proofing - module Aamva - class UnsupportedJurisdictionResult - def client - Proofing::Aamva::Proofer.to_s - end - - def errors - {} - end - - def exception - nil - end - - def success? - true - end - - def timed_out? - false - end - - def transaction_id - '' - end - - def to_h - { - errors: errors, - exception: exception, - success: success?, - timed_out: timed_out?, - vendor_name: 'UnsupportedJurisdiction', - transaction_id: transaction_id, - } - end - end - end -end diff --git a/app/services/proofing/mock/state_id_mock_client.rb b/app/services/proofing/mock/state_id_mock_client.rb index 4541ae6fa5c..568751708d9 100644 --- a/app/services/proofing/mock/state_id_mock_client.rb +++ b/app/services/proofing/mock/state_id_mock_client.rb @@ -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 @@ -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 diff --git a/app/services/proofing/state_id_result.rb b/app/services/proofing/state_id_result.rb new file mode 100644 index 00000000000..138a7546c5b --- /dev/null +++ b/app/services/proofing/state_id_result.rb @@ -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 diff --git a/spec/jobs/resolution_proofing_job_spec.rb b/spec/jobs/resolution_proofing_job_spec.rb index eeaed028b2b..637d881bf08 100644 --- a/spec/jobs/resolution_proofing_job_spec.rb +++ b/spec/jobs/resolution_proofing_job_spec.rb @@ -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') diff --git a/spec/services/proofing/mock/state_id_mock_client_spec.rb b/spec/services/proofing/mock/state_id_mock_client_spec.rb index 4adb8ddfa89..4e854404030 100644 --- a/spec/services/proofing/mock/state_id_mock_client_spec.rb +++ b/spec/services/proofing/mock/state_id_mock_client_spec.rb @@ -21,6 +21,7 @@ timed_out: false, transaction_id: transaction_id, vendor_name: 'StateIdMock', + verified_attributes: [], ) end end @@ -43,6 +44,7 @@ timed_out: false, transaction_id: transaction_id, vendor_name: 'StateIdMock', + verified_attributes: [], ) end end @@ -63,6 +65,7 @@ timed_out: true, transaction_id: transaction_id, vendor_name: 'StateIdMock', + verified_attributes: [], ) end end