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/address_result.rb b/app/services/proofing/address_result.rb new file mode 100644 index 00000000000..d30decbc9b9 --- /dev/null +++ b/app/services/proofing/address_result.rb @@ -0,0 +1,41 @@ +module Proofing + class AddressResult + attr_reader :success, :errors, :exception, :vendor_name, :transaction_id, :reference + + def initialize( + success:, + errors:, + exception:, + vendor_name:, + transaction_id: '', + reference: '' + ) + @success = success + @errors = errors + @exception = exception + @vendor_name = vendor_name + @transaction_id = transaction_id + @reference = reference + end + + def success? + success + end + + def timed_out? + exception.is_a?(Proofing::TimeoutError) + end + + def to_h + { + exception: exception, + errors: errors, + success: success?, + timed_out: timed_out?, + transaction_id: transaction_id, + reference: reference, + vendor_name: vendor_name, + } + end + end +end diff --git a/app/services/proofing/lexis_nexis/phone_finder/proofer.rb b/app/services/proofing/lexis_nexis/phone_finder/proofer.rb index cb6302b5ad8..269b6b2d1bf 100644 --- a/app/services/proofing/lexis_nexis/phone_finder/proofer.rb +++ b/app/services/proofing/lexis_nexis/phone_finder/proofer.rb @@ -10,10 +10,36 @@ def initialize(config) def proof(applicant) response = VerificationRequest.new(config: config, applicant: applicant).send - return Proofing::LexisNexis::PhoneFinder::Result.new(response) + return build_result_from_response(response) rescue => exception NewRelic::Agent.notice_error(exception) - ResultWithException.new(exception, vendor_name: 'lexisnexis:phone_finder') + AddressResult.new( + success: false, + errors: {}, + exception: exception, + vendor_name: 'lexisnexis:phone_finder', + ) + end + + private + + def build_result_from_response(verification_response) + AddressResult.new( + success: verification_response.verification_status == 'passed', + errors: parse_verification_errors(verification_response), + exception: nil, + vendor_name: 'lexisnexis:phone_finder', + transaction_id: verification_response.conversation_id, + reference: verification_response.reference, + ) + end + + def parse_verification_errors(verification_response) + errors = Hash.new { |h, k| h[k] = [] } + verification_response.verification_errors.each do |key, value| + errors[key] << value + end + errors end end end diff --git a/app/services/proofing/lexis_nexis/phone_finder/result.rb b/app/services/proofing/lexis_nexis/phone_finder/result.rb deleted file mode 100644 index a41bf82ff37..00000000000 --- a/app/services/proofing/lexis_nexis/phone_finder/result.rb +++ /dev/null @@ -1,58 +0,0 @@ -module Proofing - module LexisNexis - module PhoneFinder - class Result - attr_reader :verification_response - - delegate( - :reference, - :verification_status, - :verification_errors, - to: :verification_response, - ) - - def initialize(verification_response) - @verification_response = verification_response - end - - def errors - return @errors if defined?(@errors) - - @errors = {} - verification_errors.each do |key, value| - @errors[key] ||= [] - @errors[key].push(value) - end - @errors - end - - def exception - nil - end - - def success? - verification_response.verification_status == 'passed' - end - - def timed_out? - false - end - - def transaction_id - verification_response.conversation_id - end - - def to_h - { - exception: exception, - errors: errors, - success: success?, - timed_out: timed_out?, - transaction_id: transaction_id, - vendor_name: 'lexisnexis:phone_finder', - } - end - end - end - end -end diff --git a/app/services/proofing/lexis_nexis/result_with_exception.rb b/app/services/proofing/lexis_nexis/result_with_exception.rb deleted file mode 100644 index 5ce2ca0d49e..00000000000 --- a/app/services/proofing/lexis_nexis/result_with_exception.rb +++ /dev/null @@ -1,38 +0,0 @@ -module Proofing - module LexisNexis - 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 transaction_id - nil - 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/mock/address_mock_client.rb b/app/services/proofing/mock/address_mock_client.rb index 028e7d8161d..be7fe7d8f49 100644 --- a/app/services/proofing/mock/address_mock_client.rb +++ b/app/services/proofing/mock/address_mock_client.rb @@ -6,27 +6,6 @@ class AddressMockClient FAILED_TO_CONTACT_PHONE_NUMBER = '7035555999' TRANSACTION_ID = 'address-mock-transaction-id-123' - AddressMockClientResult = Struct.new(:success, :errors, :exception, keyword_init: true) do - def success? - success - end - - def transaction_id - TRANSACTION_ID - end - - def to_h - { - exception: exception, - errors: errors, - success: success, - timed_out: exception.is_a?(Proofing::TimeoutError), - transaction_id: transaction_id, - vendor_name: 'AddressMock', - } - end - end - def proof(applicant) plain_phone = applicant[:phone].gsub(/\D/, '').delete_prefix('1') if plain_phone == UNVERIFIABLE_PHONE_NUMBER @@ -36,14 +15,14 @@ def proof(applicant) elsif plain_phone == PROOFER_TIMEOUT_PHONE_NUMBER timeout_result else - AddressMockClientResult.new(success: true, errors: {}, exception: nil) + address_result(success: true, errors: {}, exception: nil) end end private def unverifiable_phone_result - AddressMockClientResult.new( + address_result( success: false, errors: { phone: ['The phone number could not be verified.'] }, exception: nil, @@ -51,7 +30,7 @@ def unverifiable_phone_result end def failed_to_contact_vendor_result - AddressMockClientResult.new( + address_result( success: false, errors: {}, exception: RuntimeError.new('Failed to contact proofing vendor'), @@ -59,12 +38,22 @@ def failed_to_contact_vendor_result end def timeout_result - AddressMockClientResult.new( + address_result( success: false, errors: {}, exception: Proofing::TimeoutError.new('address mock timeout'), ) end + + def address_result(success:, errors:, exception:) + AddressResult.new( + success: success, + errors: errors, + exception: exception, + transaction_id: TRANSACTION_ID, + vendor_name: 'AddressMock', + ) + end end end end diff --git a/spec/controllers/idv/phone_controller_spec.rb b/spec/controllers/idv/phone_controller_spec.rb index 2f0510d47b1..2d55898a532 100644 --- a/spec/controllers/idv/phone_controller_spec.rb +++ b/spec/controllers/idv/phone_controller_spec.rb @@ -327,6 +327,7 @@ exception: nil, timed_out: false, transaction_id: 'address-mock-transaction-id-123', + reference: '', }, } @@ -381,6 +382,7 @@ exception: nil, timed_out: false, transaction_id: 'address-mock-transaction-id-123', + reference: '', }, } diff --git a/spec/features/idv/analytics_spec.rb b/spec/features/idv/analytics_spec.rb index 7f818b956fd..a3de7c77b89 100644 --- a/spec/features/idv/analytics_spec.rb +++ b/spec/features/idv/analytics_spec.rb @@ -33,7 +33,7 @@ 'IdV: doc auth optional verify_wait submitted' => { success: true, errors: {}, address_edited: false, proofing_results: { exception: nil, transaction_id: 'resolution-mock-transaction-id-123', reference: 'aaa-bbb-ccc', timed_out: false, context: { should_proof_state_id: true, stages: { resolution: { client: 'ResolutionMock', errors: {}, exception: nil, success: true, timed_out: false, transaction_id: 'resolution-mock-transaction-id-123', reference: 'aaa-bbb-ccc' }, state_id: { client: 'StateIdMock', errors: {}, success: true, timed_out: false, exception: nil, transaction_id: 'state-id-mock-transaction-id-456', state: 'MT', state_id_jurisdiction: 'ND' } } } }, ssn_is_unique: true, step: 'verify_wait_step_show' }, 'IdV: phone of record visited' => {}, 'IdV: phone confirmation form' => { success: true, errors: {}, phone_type: :mobile, types: [:fixed_or_mobile], carrier: 'Test Mobile Carrier', country_code: 'US', area_code: '202' }, - 'IdV: phone confirmation vendor' => { success: true, errors: {}, vendor: { exception: nil, vendor_name: 'AddressMock', transaction_id: 'address-mock-transaction-id-123', timed_out: false }, new_phone_added: false }, + 'IdV: phone confirmation vendor' => { success: true, errors: {}, vendor: { exception: nil, vendor_name: 'AddressMock', transaction_id: 'address-mock-transaction-id-123', timed_out: false, reference: '' }, new_phone_added: false }, 'IdV: final resolution' => { success: true }, 'IdV: personal key visited' => {}, 'IdV: personal key submitted' => {}, @@ -101,7 +101,7 @@ 'IdV: in person proofing optional verify_wait submitted' => { success: true, step: 'verify_wait_step_show', address_edited: false, ssn_is_unique: true }, 'IdV: phone of record visited' => {}, 'IdV: phone confirmation form' => { success: true, errors: {}, phone_type: :mobile, types: [:fixed_or_mobile], carrier: 'Test Mobile Carrier', country_code: 'US', area_code: '202' }, - 'IdV: phone confirmation vendor' => { success: true, errors: {}, vendor: { exception: nil, vendor_name: 'AddressMock', transaction_id: 'address-mock-transaction-id-123', timed_out: false }, new_phone_added: false }, + 'IdV: phone confirmation vendor' => { success: true, errors: {}, vendor: { exception: nil, vendor_name: 'AddressMock', transaction_id: 'address-mock-transaction-id-123', timed_out: false, reference: '' }, new_phone_added: false }, 'IdV: Phone OTP delivery Selection Visited' => {}, 'IdV: Phone OTP Delivery Selection Submitted' => { success: true, otp_delivery_preference: 'sms' }, 'IdV: phone confirmation otp sent' => { success: true, otp_delivery_preference: :sms, country_code: 'US', area_code: '202' }, diff --git a/spec/services/idv/phone_step_spec.rb b/spec/services/idv/phone_step_spec.rb index 42e004100b4..21273dfddd1 100644 --- a/spec/services/idv/phone_step_spec.rb +++ b/spec/services/idv/phone_step_spec.rb @@ -59,6 +59,7 @@ exception: nil, timed_out: false, transaction_id: 'address-mock-transaction-id-123', + reference: '', }, } @@ -92,6 +93,7 @@ exception: nil, timed_out: false, transaction_id: 'address-mock-transaction-id-123', + reference: '', }, } diff --git a/spec/services/proofing/lexis_nexis/phone_finder/result_spec.rb b/spec/services/proofing/lexis_nexis/phone_finder/result_spec.rb deleted file mode 100644 index 25eec56f3fa..00000000000 --- a/spec/services/proofing/lexis_nexis/phone_finder/result_spec.rb +++ /dev/null @@ -1,50 +0,0 @@ -require 'rails_helper' - -describe Proofing::LexisNexis::PhoneFinder::Result do - let(:response_body) { LexisNexisFixtures.instant_verify_success_response_json } - let(:response_status) { 200 } - let(:http_response) do - Faraday::Response.new(response_body: response_body, status: response_status) - end - let(:verification_response) do - Proofing::LexisNexis::Response.new(http_response) - end - - subject { described_class.new(verification_response) } - - it 'renders LexisNexis metadata' do - # expected values originate in the fixture - expect(subject.reference).to eq('Reference1') - expect(subject.transaction_id).to eq('123456') - end - - context 'successful response' do - it 'returns a successful verified result' do - expect(subject.success?).to eq(true) - expect(subject.verification_errors).to eq({}) - end - end - - context 'failed to match response' do - let(:response_body) { LexisNexisFixtures.phone_finder_fail_response_json } - - it 'returns a failed to match verified result' do - expect(subject.success?).to eq(false) - expect(subject.verification_errors).to include( - :base, - :PhoneFinder, - ) - end - end - - context 'error response' do - let(:response_body) { LexisNexisFixtures.instant_verify_error_response_json } - - it 'returns an error result' do - expect(subject.success?).to eq(false) - expect(subject.verification_errors).to match( - base: a_string_including('invalid_transaction_initiate'), - ) - end - end -end diff --git a/spec/services/proofing/lexis_nexis/result_with_exception_spec.rb b/spec/services/proofing/lexis_nexis/result_with_exception_spec.rb deleted file mode 100644 index 610cbb7fc6a..00000000000 --- a/spec/services/proofing/lexis_nexis/result_with_exception_spec.rb +++ /dev/null @@ -1,33 +0,0 @@ -require 'rails_helper' - -RSpec.describe Proofing::LexisNexis::ResultWithException do - let(:exception) { StandardError.new('test message') } - - subject { described_class.new(exception, vendor_name: 'test-vendor') } - - describe '#timed_out?' do - context 'with a timeout error' do - let(:exception) { Proofing::TimeoutError.new('hi') } - - it { expect(subject.timed_out?).to eq(true) } - end - - context 'with a error that is not a timeout error' do - let(:exception) { StandardError.new('test message') } - - it { expect(subject.timed_out?).to eq(false) } - end - end - - describe '#to_h' do - it 'returns a hash verion of the result' do - expect(subject.to_h).to eq( - success: false, - errors: {}, - exception: exception, - timed_out: false, - vendor_name: 'test-vendor', - ) - end - end -end diff --git a/spec/services/proofing/mock/address_mock_client_spec.rb b/spec/services/proofing/mock/address_mock_client_spec.rb index 30f903f3739..40b8345e439 100644 --- a/spec/services/proofing/mock/address_mock_client_spec.rb +++ b/spec/services/proofing/mock/address_mock_client_spec.rb @@ -17,6 +17,7 @@ exception: nil, timed_out: false, transaction_id: transaction_id, + reference: '', vendor_name: 'AddressMock', ) end @@ -34,6 +35,7 @@ exception: nil, timed_out: false, transaction_id: transaction_id, + reference: '', vendor_name: 'AddressMock', ) end @@ -51,6 +53,7 @@ exception: RuntimeError.new('Failed to contact proofing vendor'), timed_out: false, transaction_id: transaction_id, + reference: '', vendor_name: 'AddressMock', ) end @@ -68,6 +71,7 @@ exception: Proofing::TimeoutError.new('address mock timeout'), timed_out: true, transaction_id: transaction_id, + reference: '', vendor_name: 'AddressMock', ) end