Skip to content
32 changes: 7 additions & 25 deletions app/services/doc_auth/mock/doc_auth_mock_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class << self
attr_reader :response_mocks
attr_accessor :last_uploaded_front_image
attr_accessor :last_uploaded_back_image
attr_accessor :last_uploaded_selfie_image
end

def self.mock_response!(method:, response:)
Expand All @@ -23,7 +22,6 @@ def self.reset!
@response_mocks = {}
@last_uploaded_front_image = nil
@last_uploaded_back_image = nil
@last_uploaded_selfie_image = nil
end

def create_document
Expand All @@ -48,17 +46,16 @@ def post_back_image(image:, instance_id:)
DocAuth::Response.new(success: true)
end

def post_selfie(image:, instance_id:)
return mocked_response_for_method(__method__) if method_mocked?(__method__)

self.class.last_uploaded_selfie_image = image
DocAuth::Response.new(success: true)
def post_selfie
raise NotImplementedError, 'Remove when same method is removed from Acuant'
end

# NOTE: remove selfie_image and liveness_checking_enabled args
# when they are no longer expected by the front-end and specs
def post_images(
front_image:,
back_image:,
selfie_image:,
selfie_image: nil,
liveness_checking_enabled: nil,
image_source: nil,
user_uuid: nil,
Expand All @@ -77,10 +74,10 @@ def post_images(
back_image_response = post_back_image(image: back_image, instance_id: instance_id)
return back_image_response unless back_image_response.success?

process_results(instance_id, liveness_checking_enabled, selfie_image)
get_results(instance_id: instance_id)
end

def get_results(instance_id:, liveness_enabled:)
def get_results(instance_id:)
return mocked_response_for_method(__method__) if method_mocked?(__method__)

overriden_config = config.dup.tap do |c|
Expand All @@ -92,27 +89,12 @@ def get_results(instance_id:, liveness_enabled:)
ResultResponse.new(
self.class.last_uploaded_back_image,
overriden_config,
liveness_enabled,
)
end
# rubocop:enable Lint/UnusedMethodArgument

private

def process_results(instance_id, liveness_checking_enabled, selfie_image)
results_response = get_results(
instance_id: instance_id,
liveness_enabled: liveness_checking_enabled,
)
return results_response unless results_response.success?

if liveness_checking_enabled
post_selfie(image: selfie_image, instance_id: instance_id).merge(results_response)
else
results_response
end
end

def method_mocked?(method_name)
mocked_response_for_method(method_name).present?
end
Expand Down
6 changes: 2 additions & 4 deletions app/services/doc_auth/mock/result_response.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
module DocAuth
module Mock
class ResultResponse < DocAuth::Response
attr_reader :uploaded_file, :config, :liveness_enabled
attr_reader :uploaded_file, :config

def initialize(uploaded_file, config, liveness_enabled)
def initialize(uploaded_file, config)
@uploaded_file = uploaded_file.to_s
@config = config
@liveness_enabled = liveness_enabled
super(
success: success?,
errors: errors,
Expand Down Expand Up @@ -163,7 +162,6 @@ def create_response_info(
},
alert_failure_count: failed&.count.to_i,
image_metrics: merged_image_metrics,
liveness_enabled: liveness_enabled,
portrait_match_results: { FaceMatchResult: liveness_result },
}
end
Expand Down
13 changes: 1 addition & 12 deletions spec/services/doc_auth/mock/dock_auth_mock_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,7 @@
instance_id: instance_id,
image: DocAuthImageFixtures.document_back_image,
)
get_results_response = client.get_results(instance_id: instance_id, liveness_enabled: false)

selfie_response = client.post_selfie(
instance_id: instance_id,
image: DocAuthImageFixtures.selfie_image,
)
get_results_response = client.get_results(instance_id: instance_id)

expect(create_document_response.success?).to eq(true)
expect(create_document_response.instance_id).to_not be_blank
Expand All @@ -53,9 +48,6 @@
state_id_issued: '2019-12-31',
phone: nil,
)

expect(selfie_response.success?).to eq(true)
expect(selfie_response.attention_with_barcode?).to eq(false)
end

it 'if the document is a YAML file it returns the PII from the YAML file' do
Expand Down Expand Up @@ -87,7 +79,6 @@
)
get_results_response = client.get_results(
instance_id: create_document_response.instance_id,
liveness_enabled: false,
)

expect(get_results_response.pii_from_doc).to eq(
Expand Down Expand Up @@ -132,7 +123,6 @@
post_images_response = client.post_images(
front_image: DocAuthImageFixtures.document_front_image,
back_image: DocAuthImageFixtures.document_back_image,
selfie_image: nil,
)

expect(post_images_response.success?).to eq(false)
Expand All @@ -145,7 +135,6 @@
post_images_response = client.post_images(
front_image: DocAuthImageFixtures.document_front_image,
back_image: DocAuthImageFixtures.document_back_image,
selfie_image: nil,
image_source: DocAuth::ImageSources::UNKNOWN,
)

Expand Down
64 changes: 57 additions & 7 deletions spec/services/doc_auth/mock/result_response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
glare_threshold: 40,
warn_notifier: warn_notifier,
)
described_class.new(input, config, false)
described_class.new(input, config)
end

context 'with an image file' do
Expand Down Expand Up @@ -254,28 +254,78 @@
glare_threshold: 40,
},
)
described_class.new(input, config, true)
described_class.new(input, config)
end

let(:input) do
<<~YAML
doc_auth_result: Passed
liveness_result: Fail
document:
type: license
first_name: Susan
last_name: Smith
middle_name: Q
address1: 1 Microsoft Way
address2: Apt 3
city: Bayside
state: NY
zipcode: '11364'
dob: 10/06/1938
phone: +1 314-555-1212
state_id_number: '123456789'
state_id_type: drivers_license
state_id_jurisdiction: 'NY'
YAML
end

it 'returns a passed result' do
expect(response.success?).to eq(true)
expect(response.errors).to eq({})
expect(response.exception).to eq(nil)
expect(response.pii_from_doc).to eq(
first_name: 'Susan',
middle_name: 'Q',
last_name: 'Smith',
phone: '+1 314-555-1212',
address1: '1 Microsoft Way',
address2: 'Apt 3',
city: 'Bayside',
state: 'NY',
state_id_jurisdiction: 'NY',
state_id_number: '123456789',
zipcode: '11364',
dob: '1938-10-06',
state_id_type: 'drivers_license',
type: 'license',
)
expect(response.attention_with_barcode?).to eq(false)
expect(response.extra).to eq(
doc_auth_result: DocAuth::Acuant::ResultCodes::PASSED.name,
billed: true,
)
end
end

context 'with a yaml file containing a read error' do
let(:input) do
<<~YAML
image_metrics:
back:
HorizontalResolution: 100
YAML
end

it 'returns caution result' do
expect(response.success?).to eq(false)
expect(response.errors).to eq(
general: [DocAuth::Errors::SELFIE_FAILURE],
selfie: [DocAuth::Errors::FALLBACK_FIELD_LEVEL],
general: [DocAuth::Errors::DPI_LOW_ONE_SIDE],
back: [DocAuth::Errors::DPI_LOW_FIELD],
hints: false,
)
expect(response.exception).to eq(nil)
expect(response.pii_from_doc).to eq({})
expect(response.attention_with_barcode?).to eq(false)
expect(response.extra).to eq(
doc_auth_result: DocAuth::Acuant::ResultCodes::PASSED.name,
doc_auth_result: DocAuth::Acuant::ResultCodes::CAUTION.name,
billed: true,
)
end
Expand Down
6 changes: 3 additions & 3 deletions spec/services/doc_auth_router_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def reload_ab_test_initializer!
)

response = I18n.with_locale(:es) do
proxy.get_results(instance_id: 'abcdef', liveness_enabled: false)
proxy.get_results(instance_id: 'abcdef')
end

expect(response.errors[:some_other_key]).to eq(['will not be translated'])
Expand All @@ -163,7 +163,7 @@ def reload_ab_test_initializer!
),
)

response = proxy.get_results(instance_id: 'abcdef', liveness_enabled: false)
response = proxy.get_results(instance_id: 'abcdef')

expect(response.errors[:network]).to eq(I18n.t('doc_auth.errors.general.network_error'))
end
Expand All @@ -179,7 +179,7 @@ def reload_ab_test_initializer!
),
)

response = proxy.get_results(instance_id: 'abcdef', liveness_enabled: false)
response = proxy.get_results(instance_id: 'abcdef')

expect(response.errors[:selfie]).to eq([I18n.t('doc_auth.errors.alerts.selfie_failure')])
end
Expand Down