From 93593038d63b42a777807a6c7f23da9eb4b44fa3 Mon Sep 17 00:00:00 2001 From: Parissa Date: Thu, 28 Jul 2022 11:06:54 -0400 Subject: [PATCH 01/12] LG-6668 safeguard failed message --- .../acuant/responses/get_results_response.rb | 10 ++-- .../lexis_nexis/responses/true_id_response.rb | 10 ++-- .../responses/get_results_response_spec.rb | 54 +++++++++++++++++++ .../responses/true_id_response_spec.rb | 5 ++ 4 files changed, 73 insertions(+), 6 deletions(-) diff --git a/app/services/doc_auth/acuant/responses/get_results_response.rb b/app/services/doc_auth/acuant/responses/get_results_response.rb index 9f77da3f06d..d8ba2cfcc25 100644 --- a/app/services/doc_auth/acuant/responses/get_results_response.rb +++ b/app/services/doc_auth/acuant/responses/get_results_response.rb @@ -97,12 +97,16 @@ def processed_alerts def log_alerts(alerts) log_alert_results = {} + has_failed = {} + alerts.keys.each do |key| alerts[key.to_sym].each do |alert| - side = alert[:side] || 'no_side' - log_alert_results[alert[:name]. + alert_name_key = alert[:name]. downcase. - parameterize(separator: '_').to_sym] = { "#{side}": alert[:result] } + parameterize(separator: '_') + side = alert[:side] || 'no_side' + log_alert_results[alert_name_key.to_sym] = { "#{side}": alert[:result] } unless has_failed[alert_name_key.to_sym] + has_failed[alert_name_key.to_sym] = key == 'passed'.to_sym ? false : true end end log_alert_results diff --git a/app/services/doc_auth/lexis_nexis/responses/true_id_response.rb b/app/services/doc_auth/lexis_nexis/responses/true_id_response.rb index 7f544dcd5c7..dc544182ac7 100644 --- a/app/services/doc_auth/lexis_nexis/responses/true_id_response.rb +++ b/app/services/doc_auth/lexis_nexis/responses/true_id_response.rb @@ -124,12 +124,16 @@ def response_info def log_alerts(alerts) log_alert_results = {} + has_failed = {} + alerts.keys.each do |key| alerts[key.to_sym].each do |alert| - side = alert[:side] || 'no_side' - log_alert_results[alert[:name]. + alert_name_key = alert[:name]. downcase. - parameterize(separator: '_').to_sym] = { "#{side}": alert[:result] } + parameterize(separator: '_') + side = alert[:side] || 'no_side' + log_alert_results[alert_name_key.to_sym] = { "#{side}": alert[:result] } unless has_failed[alert_name_key.to_sym] + has_failed[alert_name_key.to_sym] = key == 'passed'.to_sym ? false : true end end log_alert_results diff --git a/spec/services/doc_auth/acuant/responses/get_results_response_spec.rb b/spec/services/doc_auth/acuant/responses/get_results_response_spec.rb index 275e187537f..174db5b26e9 100644 --- a/spec/services/doc_auth/acuant/responses/get_results_response_spec.rb +++ b/spec/services/doc_auth/acuant/responses/get_results_response_spec.rb @@ -154,6 +154,7 @@ back: [DocAuth::Errors::FALLBACK_FIELD_LEVEL], hints: true, ) + expect(response.to_h[:log_alert_results]).to eq( document_classification: { no_side: 'Failed' }, ) @@ -162,6 +163,59 @@ expect(response.result_code.billed?).to eq(false) end + context 'when visiual_pattern fails and passes' do + let(:http_response) do + parsed_response_body['Alerts'] << { + "Actions": "Check the visible (white) document image to verify the presence of the security feature. Possible reasons this test may fail for a valid document may be that the document was moving during the capture, or the document may be excessively worn or damaged.", + "DataFieldReferences": [], + "Description": "Verified the presence of a pattern on the visible image.", + "Disposition": "A visible pattern was not found", + "FieldReferences": [], + "Id": "4add9651-27ed-40a2-90eb-7fa46a694156", + "ImageReferences": [], + "Information": "Verified that a security feature in the visible spectrum is present and in an expected location on the document.", + "Key": "Visible Pattern", + "Name": "Visible Pattern", + "RegionReferences": [], + "Result": 2, + } + parsed_response_body['Alerts'] << { + "Actions": "Check the visible (white) document image to verify the presence of the security feature. Possible reasons this test may fail for a valid document may be that the document was moving during the capture, or the document may be excessively worn or damaged.", + "DataFieldReferences": [], + "Description": "Verified the presence of a pattern on the visible image.", + "Disposition": "A visible pattern was not found", + "FieldReferences": [], + "Id": "4add9651-27ed-40a2-90eb-7fa46a694156", + "ImageReferences": [], + "Information": "Verified that a security feature in the visible spectrum is present and in an expected location on the document.", + "Key": "Visible Pattern", + "Name": "Visible Pattern", + "RegionReferences": [], + "Result": 1, + } + + instance_double( + Faraday::Response, + body: parsed_response_body.to_json, + ) + end + + it 'returns log_alert_results for visible_pattern as false' do + expect(response.to_h[:processed_alerts]).to eq( + passed: [{ name: 'Visible Pattern', result: 'Passed' }], + failed: + [{ name: 'Document Classification', + result:'Failed' }, + { name: 'Visible Pattern', + result: 'Failed' }] + ) + + expect(response.to_h[:log_alert_results]).to eq( + { visible_pattern: { no_side: 'Failed' }, :document_classification=>{ no_side: 'Failed' } } + ) + end + end + context 'when with an acuant error message' do let(:http_response) do parsed_response_body['Alerts'].first['Disposition'] = 'This message does not have a key' diff --git a/spec/services/doc_auth/lexis_nexis/responses/true_id_response_spec.rb b/spec/services/doc_auth/lexis_nexis/responses/true_id_response_spec.rb index f5bc8c60b9e..21b059068a1 100644 --- a/spec/services/doc_auth/lexis_nexis/responses/true_id_response_spec.rb +++ b/spec/services/doc_auth/lexis_nexis/responses/true_id_response_spec.rb @@ -185,6 +185,11 @@ expect(errors[:hints]).to eq(true) end + it 'returns log_alert_results, visible_pattern as false when alerts has it as true and false' do + output = described_class.new(failure_response_no_liveness, false, config).to_h + expect(output.to_h[:log_alert_results]).to match(a_hash_including('visible_pattern': { no_side: 'Failed' })) + end + it 'produces appropriate errors with liveness' do output = described_class.new(failure_response_with_liveness, true, config).to_h errors = output[:errors] From bd1c7e0afd65c55e6e62bb5a94ddd95479294384 Mon Sep 17 00:00:00 2001 From: Parissa Date: Thu, 28 Jul 2022 11:12:45 -0400 Subject: [PATCH 02/12] remove extra space --- .../doc_auth/acuant/responses/get_results_response_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/services/doc_auth/acuant/responses/get_results_response_spec.rb b/spec/services/doc_auth/acuant/responses/get_results_response_spec.rb index 174db5b26e9..b404c6dd40d 100644 --- a/spec/services/doc_auth/acuant/responses/get_results_response_spec.rb +++ b/spec/services/doc_auth/acuant/responses/get_results_response_spec.rb @@ -154,7 +154,6 @@ back: [DocAuth::Errors::FALLBACK_FIELD_LEVEL], hints: true, ) - expect(response.to_h[:log_alert_results]).to eq( document_classification: { no_side: 'Failed' }, ) From 6224bfacc58bc52c74452c79bc718a58e476ac3d Mon Sep 17 00:00:00 2001 From: Parissa Date: Thu, 28 Jul 2022 11:47:25 -0400 Subject: [PATCH 03/12] fix lint errors --- .../acuant/responses/get_results_response.rb | 7 ++- .../lexis_nexis/responses/true_id_response.rb | 7 ++- .../responses/get_results_response_spec.rb | 59 ++++++++++--------- .../responses/true_id_response_spec.rb | 3 +- 4 files changed, 42 insertions(+), 34 deletions(-) diff --git a/app/services/doc_auth/acuant/responses/get_results_response.rb b/app/services/doc_auth/acuant/responses/get_results_response.rb index d8ba2cfcc25..5a34fe0ecc2 100644 --- a/app/services/doc_auth/acuant/responses/get_results_response.rb +++ b/app/services/doc_auth/acuant/responses/get_results_response.rb @@ -105,8 +105,11 @@ def log_alerts(alerts) downcase. parameterize(separator: '_') side = alert[:side] || 'no_side' - log_alert_results[alert_name_key.to_sym] = { "#{side}": alert[:result] } unless has_failed[alert_name_key.to_sym] - has_failed[alert_name_key.to_sym] = key == 'passed'.to_sym ? false : true + unless has_failed[alert_name_key.to_sym] + log_alert_results[alert_name_key.to_sym] = + { "#{side}": alert[:result] } + end + has_failed[alert_name_key.to_sym] = !(key == :passed) end end log_alert_results diff --git a/app/services/doc_auth/lexis_nexis/responses/true_id_response.rb b/app/services/doc_auth/lexis_nexis/responses/true_id_response.rb index dc544182ac7..70ac64b0e1b 100644 --- a/app/services/doc_auth/lexis_nexis/responses/true_id_response.rb +++ b/app/services/doc_auth/lexis_nexis/responses/true_id_response.rb @@ -132,8 +132,11 @@ def log_alerts(alerts) downcase. parameterize(separator: '_') side = alert[:side] || 'no_side' - log_alert_results[alert_name_key.to_sym] = { "#{side}": alert[:result] } unless has_failed[alert_name_key.to_sym] - has_failed[alert_name_key.to_sym] = key == 'passed'.to_sym ? false : true + unless has_failed[alert_name_key.to_sym] + log_alert_results[alert_name_key.to_sym] = + { "#{side}": alert[:result] } + end + has_failed[alert_name_key.to_sym] = !(key == :passed) end end log_alert_results diff --git a/spec/services/doc_auth/acuant/responses/get_results_response_spec.rb b/spec/services/doc_auth/acuant/responses/get_results_response_spec.rb index b404c6dd40d..e1213f6b263 100644 --- a/spec/services/doc_auth/acuant/responses/get_results_response_spec.rb +++ b/spec/services/doc_auth/acuant/responses/get_results_response_spec.rb @@ -164,33 +164,33 @@ context 'when visiual_pattern fails and passes' do let(:http_response) do - parsed_response_body['Alerts'] << { - "Actions": "Check the visible (white) document image to verify the presence of the security feature. Possible reasons this test may fail for a valid document may be that the document was moving during the capture, or the document may be excessively worn or damaged.", - "DataFieldReferences": [], - "Description": "Verified the presence of a pattern on the visible image.", - "Disposition": "A visible pattern was not found", - "FieldReferences": [], - "Id": "4add9651-27ed-40a2-90eb-7fa46a694156", - "ImageReferences": [], - "Information": "Verified that a security feature in the visible spectrum is present and in an expected location on the document.", - "Key": "Visible Pattern", - "Name": "Visible Pattern", - "RegionReferences": [], - "Result": 2, + parsed_response_body['Alerts'] << { + Actions: 'Check the visible (white) document image...', + DataFieldReferences: [], + Description: 'Verified the presence of a pattern on the visible image.', + Disposition: 'A visible pattern was not found', + FieldReferences: [], + Id: '4add9651-27ed-40a2-90eb-7fa46a694156', + ImageReferences: [], + Information: 'Verified that a security feature...', + Key: 'Visible Pattern', + Name: 'Visible Pattern', + RegionReferences: [], + Result: 2, } - parsed_response_body['Alerts'] << { - "Actions": "Check the visible (white) document image to verify the presence of the security feature. Possible reasons this test may fail for a valid document may be that the document was moving during the capture, or the document may be excessively worn or damaged.", - "DataFieldReferences": [], - "Description": "Verified the presence of a pattern on the visible image.", - "Disposition": "A visible pattern was not found", - "FieldReferences": [], - "Id": "4add9651-27ed-40a2-90eb-7fa46a694156", - "ImageReferences": [], - "Information": "Verified that a security feature in the visible spectrum is present and in an expected location on the document.", - "Key": "Visible Pattern", - "Name": "Visible Pattern", - "RegionReferences": [], - "Result": 1, + parsed_response_body['Alerts'] << { + Actions: 'Check the visible (white) document image...', + DataFieldReferences: [], + Description: 'Verified the presence of a pattern on the visible image.', + Disposition: 'A visible pattern was not found', + FieldReferences: [], + Id: '4add9651-27ed-40a2-90eb-7fa46a694156', + ImageReferences: [], + Information: 'Verified that a security feature...', + Key: 'Visible Pattern', + Name: 'Visible Pattern', + RegionReferences: [], + Result: 1, } instance_double( @@ -204,13 +204,14 @@ passed: [{ name: 'Visible Pattern', result: 'Passed' }], failed: [{ name: 'Document Classification', - result:'Failed' }, + result: 'Failed' }, { name: 'Visible Pattern', - result: 'Failed' }] + result: 'Failed' }], ) expect(response.to_h[:log_alert_results]).to eq( - { visible_pattern: { no_side: 'Failed' }, :document_classification=>{ no_side: 'Failed' } } + { visible_pattern: { no_side: 'Failed' }, + document_classification: { no_side: 'Failed' } }, ) end end diff --git a/spec/services/doc_auth/lexis_nexis/responses/true_id_response_spec.rb b/spec/services/doc_auth/lexis_nexis/responses/true_id_response_spec.rb index 21b059068a1..46eef1ea2d6 100644 --- a/spec/services/doc_auth/lexis_nexis/responses/true_id_response_spec.rb +++ b/spec/services/doc_auth/lexis_nexis/responses/true_id_response_spec.rb @@ -187,7 +187,8 @@ it 'returns log_alert_results, visible_pattern as false when alerts has it as true and false' do output = described_class.new(failure_response_no_liveness, false, config).to_h - expect(output.to_h[:log_alert_results]).to match(a_hash_including('visible_pattern': { no_side: 'Failed' })) + expect(output.to_h[:log_alert_results]). + to match(a_hash_including(visible_pattern: { no_side: 'Failed' })) end it 'produces appropriate errors with liveness' do From de52d6efac28fa288ec7fd6acc47ec009783db27 Mon Sep 17 00:00:00 2001 From: Parissa Date: Thu, 28 Jul 2022 12:19:10 -0400 Subject: [PATCH 04/12] Add changelog changelog: Improvements, logging, safeguard duplicate success, failed alerts to show failed, during document authentication --- .../acuant/responses/get_results_response_spec.rb | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/spec/services/doc_auth/acuant/responses/get_results_response_spec.rb b/spec/services/doc_auth/acuant/responses/get_results_response_spec.rb index e1213f6b263..9dea959937d 100644 --- a/spec/services/doc_auth/acuant/responses/get_results_response_spec.rb +++ b/spec/services/doc_auth/acuant/responses/get_results_response_spec.rb @@ -165,31 +165,19 @@ context 'when visiual_pattern fails and passes' do let(:http_response) do parsed_response_body['Alerts'] << { - Actions: 'Check the visible (white) document image...', - DataFieldReferences: [], Description: 'Verified the presence of a pattern on the visible image.', Disposition: 'A visible pattern was not found', - FieldReferences: [], Id: '4add9651-27ed-40a2-90eb-7fa46a694156', - ImageReferences: [], - Information: 'Verified that a security feature...', Key: 'Visible Pattern', Name: 'Visible Pattern', - RegionReferences: [], Result: 2, } parsed_response_body['Alerts'] << { - Actions: 'Check the visible (white) document image...', - DataFieldReferences: [], Description: 'Verified the presence of a pattern on the visible image.', Disposition: 'A visible pattern was not found', - FieldReferences: [], Id: '4add9651-27ed-40a2-90eb-7fa46a694156', - ImageReferences: [], - Information: 'Verified that a security feature...', Key: 'Visible Pattern', Name: 'Visible Pattern', - RegionReferences: [], Result: 1, } From c15256ed898dc5a8fb03a63a23ab4f25cd3d3b69 Mon Sep 17 00:00:00 2001 From: Parissa Date: Thu, 28 Jul 2022 12:24:55 -0400 Subject: [PATCH 05/12] simplified the alert hash in the test --- .../acuant/responses/get_results_response_spec.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/spec/services/doc_auth/acuant/responses/get_results_response_spec.rb b/spec/services/doc_auth/acuant/responses/get_results_response_spec.rb index 9dea959937d..242d464c178 100644 --- a/spec/services/doc_auth/acuant/responses/get_results_response_spec.rb +++ b/spec/services/doc_auth/acuant/responses/get_results_response_spec.rb @@ -165,19 +165,15 @@ context 'when visiual_pattern fails and passes' do let(:http_response) do parsed_response_body['Alerts'] << { - Description: 'Verified the presence of a pattern on the visible image.', - Disposition: 'A visible pattern was not found', - Id: '4add9651-27ed-40a2-90eb-7fa46a694156', Key: 'Visible Pattern', Name: 'Visible Pattern', + RegionReferences: [], Result: 2, } parsed_response_body['Alerts'] << { - Description: 'Verified the presence of a pattern on the visible image.', - Disposition: 'A visible pattern was not found', - Id: '4add9651-27ed-40a2-90eb-7fa46a694156', Key: 'Visible Pattern', Name: 'Visible Pattern', + RegionReferences: [], Result: 1, } From 2ee0694b7b1cec515d62c5d35af6681093c085d3 Mon Sep 17 00:00:00 2001 From: Parissa Date: Fri, 29 Jul 2022 17:07:24 -0400 Subject: [PATCH 06/12] changes made to comma delimit the alert values --- .../acuant/responses/get_results_response.rb | 25 +++++++++++---- .../lexis_nexis/responses/true_id_response.rb | 25 +++++++++++---- .../responses/get_results_response_spec.rb | 32 +++++++++---------- .../responses/true_id_response_spec.rb | 8 ++--- 4 files changed, 58 insertions(+), 32 deletions(-) diff --git a/app/services/doc_auth/acuant/responses/get_results_response.rb b/app/services/doc_auth/acuant/responses/get_results_response.rb index 5a34fe0ecc2..7e3a260d817 100644 --- a/app/services/doc_auth/acuant/responses/get_results_response.rb +++ b/app/services/doc_auth/acuant/responses/get_results_response.rb @@ -95,6 +95,14 @@ def processed_alerts @processed_alerts ||= process_raw_alerts(raw_alerts) end + def get_alert_result(log_alert_results, side, alert_name_key, result) + if log_alert_results.dig(alert_name_key, side.to_sym).present? + log_alert_results[alert_name_key][side.to_sym] + ", #{result}" + else + result + end + end + def log_alerts(alerts) log_alert_results = {} has_failed = {} @@ -103,13 +111,18 @@ def log_alerts(alerts) alerts[key.to_sym].each do |alert| alert_name_key = alert[:name]. downcase. - parameterize(separator: '_') + parameterize(separator: '_').to_sym side = alert[:side] || 'no_side' - unless has_failed[alert_name_key.to_sym] - log_alert_results[alert_name_key.to_sym] = - { "#{side}": alert[:result] } - end - has_failed[alert_name_key.to_sym] = !(key == :passed) + + log_alert_results[alert_name_key] = + { "#{side}": get_alert_result( + log_alert_results, + side, + alert_name_key, + alert[:result], + ). + split(', ').uniq.join(', ') } + has_failed[alert_name_key] = !(key == :passed) end end log_alert_results diff --git a/app/services/doc_auth/lexis_nexis/responses/true_id_response.rb b/app/services/doc_auth/lexis_nexis/responses/true_id_response.rb index 70ac64b0e1b..710ca64c59d 100644 --- a/app/services/doc_auth/lexis_nexis/responses/true_id_response.rb +++ b/app/services/doc_auth/lexis_nexis/responses/true_id_response.rb @@ -122,6 +122,14 @@ def response_info @response_info ||= create_response_info end + def get_alert_result(log_alert_results, side, alert_name_key, result) + if log_alert_results.dig(alert_name_key, side.to_sym).present? + log_alert_results[alert_name_key][side.to_sym] + ", #{result}" + else + result + end + end + def log_alerts(alerts) log_alert_results = {} has_failed = {} @@ -130,13 +138,18 @@ def log_alerts(alerts) alerts[key.to_sym].each do |alert| alert_name_key = alert[:name]. downcase. - parameterize(separator: '_') + parameterize(separator: '_').to_sym side = alert[:side] || 'no_side' - unless has_failed[alert_name_key.to_sym] - log_alert_results[alert_name_key.to_sym] = - { "#{side}": alert[:result] } - end - has_failed[alert_name_key.to_sym] = !(key == :passed) + + log_alert_results[alert_name_key] = + { "#{side}": get_alert_result( + log_alert_results, + side, + alert_name_key, + alert[:result], + ). + split(', ').uniq.join(', ') } + has_failed[alert_name_key] = !(key == :passed) end end log_alert_results diff --git a/spec/services/doc_auth/acuant/responses/get_results_response_spec.rb b/spec/services/doc_auth/acuant/responses/get_results_response_spec.rb index 242d464c178..a52600999fa 100644 --- a/spec/services/doc_auth/acuant/responses/get_results_response_spec.rb +++ b/spec/services/doc_auth/acuant/responses/get_results_response_spec.rb @@ -162,20 +162,16 @@ expect(response.result_code.billed?).to eq(false) end - context 'when visiual_pattern fails and passes' do + context 'when visiual_pattern fails with multiple results' do let(:http_response) do - parsed_response_body['Alerts'] << { - Key: 'Visible Pattern', - Name: 'Visible Pattern', - RegionReferences: [], - Result: 2, - } - parsed_response_body['Alerts'] << { - Key: 'Visible Pattern', - Name: 'Visible Pattern', - RegionReferences: [], - Result: 1, - } + [1, 2, 3, 4].each do |index| + parsed_response_body['Alerts'] << { + Key: 'Visible Pattern', + Name: 'Visible Pattern', + RegionReferences: [], + Result: index, + } + end instance_double( Faraday::Response, @@ -183,18 +179,22 @@ ) end - it 'returns log_alert_results for visible_pattern as false' do + it 'returns log_alert_results for visible_pattern with multiple results comma separated' do expect(response.to_h[:processed_alerts]).to eq( passed: [{ name: 'Visible Pattern', result: 'Passed' }], failed: [{ name: 'Document Classification', result: 'Failed' }, { name: 'Visible Pattern', - result: 'Failed' }], + result: 'Failed' }, + { name: 'Visible Pattern', + result: 'Skipped' }, + { name: 'Visible Pattern', + result: 'Caution' }], ) expect(response.to_h[:log_alert_results]).to eq( - { visible_pattern: { no_side: 'Failed' }, + { visible_pattern: { no_side: 'Passed, Failed, Skipped, Caution' }, document_classification: { no_side: 'Failed' } }, ) end diff --git a/spec/services/doc_auth/lexis_nexis/responses/true_id_response_spec.rb b/spec/services/doc_auth/lexis_nexis/responses/true_id_response_spec.rb index 46eef1ea2d6..254a6c930e1 100644 --- a/spec/services/doc_auth/lexis_nexis/responses/true_id_response_spec.rb +++ b/spec/services/doc_auth/lexis_nexis/responses/true_id_response_spec.rb @@ -170,7 +170,7 @@ layout_valid: { no_side: 'Passed' }, sex_crosscheck: { no_side: 'Passed' }, visible_color_response: { no_side: 'Passed' }, - visible_pattern: { no_side: 'Failed' }, + visible_pattern: { no_side: 'Passed, Failed' }, visible_photo_characteristics: { no_side: 'Passed' }, '1d_control_number_valid': { no_side: 'Failed' }, '2d_barcode_content': { no_side: 'Failed' }, @@ -185,10 +185,10 @@ expect(errors[:hints]).to eq(true) end - it 'returns log_alert_results, visible_pattern as false when alerts has it as true and false' do + it 'returns all of the alerts for log_alert_results, comma delimited' do output = described_class.new(failure_response_no_liveness, false, config).to_h expect(output.to_h[:log_alert_results]). - to match(a_hash_including(visible_pattern: { no_side: 'Failed' })) + to match(a_hash_including(visible_pattern: { no_side: 'Passed, Failed' })) end it 'produces appropriate errors with liveness' do @@ -210,7 +210,7 @@ layout_valid: { no_side: 'Passed' }, sex_crosscheck: { no_side: 'Passed' }, visible_color_response: { no_side: 'Passed' }, - visible_pattern: { no_side: 'Failed' }, + visible_pattern: { no_side: 'Passed, Failed' }, visible_photo_characteristics: { no_side: 'Passed' }, '1d_control_number_valid': { no_side: 'Failed' }, '2d_barcode_content': { no_side: 'Failed' }, From 9a9ef138484a076fa0c9e5598f647e0a4cc81f02 Mon Sep 17 00:00:00 2001 From: Parissa Date: Fri, 29 Jul 2022 17:12:12 -0400 Subject: [PATCH 07/12] remove has_failed --- app/services/doc_auth/acuant/responses/get_results_response.rb | 2 -- app/services/doc_auth/lexis_nexis/responses/true_id_response.rb | 2 -- 2 files changed, 4 deletions(-) diff --git a/app/services/doc_auth/acuant/responses/get_results_response.rb b/app/services/doc_auth/acuant/responses/get_results_response.rb index 7e3a260d817..efc831ea5ba 100644 --- a/app/services/doc_auth/acuant/responses/get_results_response.rb +++ b/app/services/doc_auth/acuant/responses/get_results_response.rb @@ -105,7 +105,6 @@ def get_alert_result(log_alert_results, side, alert_name_key, result) def log_alerts(alerts) log_alert_results = {} - has_failed = {} alerts.keys.each do |key| alerts[key.to_sym].each do |alert| @@ -122,7 +121,6 @@ def log_alerts(alerts) alert[:result], ). split(', ').uniq.join(', ') } - has_failed[alert_name_key] = !(key == :passed) end end log_alert_results diff --git a/app/services/doc_auth/lexis_nexis/responses/true_id_response.rb b/app/services/doc_auth/lexis_nexis/responses/true_id_response.rb index 710ca64c59d..c2959b7b188 100644 --- a/app/services/doc_auth/lexis_nexis/responses/true_id_response.rb +++ b/app/services/doc_auth/lexis_nexis/responses/true_id_response.rb @@ -132,7 +132,6 @@ def get_alert_result(log_alert_results, side, alert_name_key, result) def log_alerts(alerts) log_alert_results = {} - has_failed = {} alerts.keys.each do |key| alerts[key.to_sym].each do |alert| @@ -149,7 +148,6 @@ def log_alerts(alerts) alert[:result], ). split(', ').uniq.join(', ') } - has_failed[alert_name_key] = !(key == :passed) end end log_alert_results From e5938f363977c3b52b3471815d1ef861d9f38287 Mon Sep 17 00:00:00 2001 From: Parissa Date: Mon, 1 Aug 2022 11:04:27 -0400 Subject: [PATCH 08/12] update code to just log when written over --- .../acuant/responses/get_results_response.rb | 9 ++++----- .../lexis_nexis/responses/true_id_response.rb | 9 ++++----- .../acuant/responses/get_results_response_spec.rb | 12 ++++-------- .../lexis_nexis/responses/true_id_response_spec.rb | 10 +++++----- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/app/services/doc_auth/acuant/responses/get_results_response.rb b/app/services/doc_auth/acuant/responses/get_results_response.rb index efc831ea5ba..3100595da8f 100644 --- a/app/services/doc_auth/acuant/responses/get_results_response.rb +++ b/app/services/doc_auth/acuant/responses/get_results_response.rb @@ -97,10 +97,10 @@ def processed_alerts def get_alert_result(log_alert_results, side, alert_name_key, result) if log_alert_results.dig(alert_name_key, side.to_sym).present? - log_alert_results[alert_name_key][side.to_sym] + ", #{result}" - else - result + Rails.logger. + info("ALERT ALREADY HAS A VALUE: #{log_alert_results[alert_name_key][side.to_sym]}, #{result}") end + result end def log_alerts(alerts) @@ -119,8 +119,7 @@ def log_alerts(alerts) side, alert_name_key, alert[:result], - ). - split(', ').uniq.join(', ') } + ) } end end log_alert_results diff --git a/app/services/doc_auth/lexis_nexis/responses/true_id_response.rb b/app/services/doc_auth/lexis_nexis/responses/true_id_response.rb index c2959b7b188..fc4d35649da 100644 --- a/app/services/doc_auth/lexis_nexis/responses/true_id_response.rb +++ b/app/services/doc_auth/lexis_nexis/responses/true_id_response.rb @@ -124,10 +124,10 @@ def response_info def get_alert_result(log_alert_results, side, alert_name_key, result) if log_alert_results.dig(alert_name_key, side.to_sym).present? - log_alert_results[alert_name_key][side.to_sym] + ", #{result}" - else - result + Rails.logger. + info("ALERT ALREADY HAS A VALUE: #{log_alert_results[alert_name_key][side.to_sym]}, #{result}") end + result end def log_alerts(alerts) @@ -146,8 +146,7 @@ def log_alerts(alerts) side, alert_name_key, alert[:result], - ). - split(', ').uniq.join(', ') } + )} end end log_alert_results diff --git a/spec/services/doc_auth/acuant/responses/get_results_response_spec.rb b/spec/services/doc_auth/acuant/responses/get_results_response_spec.rb index a52600999fa..092feac1edd 100644 --- a/spec/services/doc_auth/acuant/responses/get_results_response_spec.rb +++ b/spec/services/doc_auth/acuant/responses/get_results_response_spec.rb @@ -162,9 +162,9 @@ expect(response.result_code.billed?).to eq(false) end - context 'when visiual_pattern fails with multiple results' do + context 'when visiual_pattern passes and fails' do let(:http_response) do - [1, 2, 3, 4].each do |index| + [1, 2].each do |index| parsed_response_body['Alerts'] << { Key: 'Visible Pattern', Name: 'Visible Pattern', @@ -186,15 +186,11 @@ [{ name: 'Document Classification', result: 'Failed' }, { name: 'Visible Pattern', - result: 'Failed' }, - { name: 'Visible Pattern', - result: 'Skipped' }, - { name: 'Visible Pattern', - result: 'Caution' }], + result: 'Failed' }], ) expect(response.to_h[:log_alert_results]).to eq( - { visible_pattern: { no_side: 'Passed, Failed, Skipped, Caution' }, + { visible_pattern: { no_side: 'Failed' }, document_classification: { no_side: 'Failed' } }, ) end diff --git a/spec/services/doc_auth/lexis_nexis/responses/true_id_response_spec.rb b/spec/services/doc_auth/lexis_nexis/responses/true_id_response_spec.rb index 254a6c930e1..fac69784ea7 100644 --- a/spec/services/doc_auth/lexis_nexis/responses/true_id_response_spec.rb +++ b/spec/services/doc_auth/lexis_nexis/responses/true_id_response_spec.rb @@ -102,7 +102,7 @@ transaction_reason_code: 'trueid_pass', product_status: 'pass', doc_auth_result: 'Passed', - processed_alerts: a_hash_including(:passed, :failed), + processed_alerts: a_hash_including(:failed), alert_failure_count: a_kind_of(Numeric), portrait_match_results: nil, image_metrics: a_hash_including(:front, :back), @@ -170,7 +170,7 @@ layout_valid: { no_side: 'Passed' }, sex_crosscheck: { no_side: 'Passed' }, visible_color_response: { no_side: 'Passed' }, - visible_pattern: { no_side: 'Passed, Failed' }, + visible_pattern: { no_side: 'Failed' }, visible_photo_characteristics: { no_side: 'Passed' }, '1d_control_number_valid': { no_side: 'Failed' }, '2d_barcode_content': { no_side: 'Failed' }, @@ -185,10 +185,10 @@ expect(errors[:hints]).to eq(true) end - it 'returns all of the alerts for log_alert_results, comma delimited' do + it 'returns Failed for visible_pattern when it gets passed and failed value ' do output = described_class.new(failure_response_no_liveness, false, config).to_h expect(output.to_h[:log_alert_results]). - to match(a_hash_including(visible_pattern: { no_side: 'Passed, Failed' })) + to match(a_hash_including(visible_pattern: { no_side: 'Failed' })) end it 'produces appropriate errors with liveness' do @@ -210,7 +210,7 @@ layout_valid: { no_side: 'Passed' }, sex_crosscheck: { no_side: 'Passed' }, visible_color_response: { no_side: 'Passed' }, - visible_pattern: { no_side: 'Passed, Failed' }, + visible_pattern: { no_side: 'Failed' }, visible_photo_characteristics: { no_side: 'Passed' }, '1d_control_number_valid': { no_side: 'Failed' }, '2d_barcode_content': { no_side: 'Failed' }, From ff6575a0b970eb5cb05e53ce9338fc0db3b77a1a Mon Sep 17 00:00:00 2001 From: Parissa Date: Mon, 1 Aug 2022 11:28:43 -0400 Subject: [PATCH 09/12] fix linter errors --- .../doc_auth/acuant/responses/get_results_response.rb | 5 +++-- .../doc_auth/lexis_nexis/responses/true_id_response.rb | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/app/services/doc_auth/acuant/responses/get_results_response.rb b/app/services/doc_auth/acuant/responses/get_results_response.rb index 3100595da8f..7318fed4231 100644 --- a/app/services/doc_auth/acuant/responses/get_results_response.rb +++ b/app/services/doc_auth/acuant/responses/get_results_response.rb @@ -97,8 +97,9 @@ def processed_alerts def get_alert_result(log_alert_results, side, alert_name_key, result) if log_alert_results.dig(alert_name_key, side.to_sym).present? + alert_value = log_alert_results[alert_name_key][side.to_sym] Rails.logger. - info("ALERT ALREADY HAS A VALUE: #{log_alert_results[alert_name_key][side.to_sym]}, #{result}") + info("ALERT ALREADY HAS A VALUE: #{alert_value}, #{result}") end result end @@ -119,7 +120,7 @@ def log_alerts(alerts) side, alert_name_key, alert[:result], - ) } + ) } end end log_alert_results diff --git a/app/services/doc_auth/lexis_nexis/responses/true_id_response.rb b/app/services/doc_auth/lexis_nexis/responses/true_id_response.rb index fc4d35649da..00b9321d695 100644 --- a/app/services/doc_auth/lexis_nexis/responses/true_id_response.rb +++ b/app/services/doc_auth/lexis_nexis/responses/true_id_response.rb @@ -124,8 +124,9 @@ def response_info def get_alert_result(log_alert_results, side, alert_name_key, result) if log_alert_results.dig(alert_name_key, side.to_sym).present? + alert_value = log_alert_results[alert_name_key][side.to_sym] Rails.logger. - info("ALERT ALREADY HAS A VALUE: #{log_alert_results[alert_name_key][side.to_sym]}, #{result}") + info("ALERT ALREADY HAS A VALUE: #{alert_value}, #{result}") end result end @@ -146,7 +147,7 @@ def log_alerts(alerts) side, alert_name_key, alert[:result], - )} + ) } end end log_alert_results From 860077a9056d7f91dfe3325649244b4a8a591a63 Mon Sep 17 00:00:00 2001 From: Parissa Date: Wed, 3 Aug 2022 10:17:43 -0400 Subject: [PATCH 10/12] Add changelog changelog: Improvements, docuauth Logs, log warning when duplicate messages from same alert occures --- .../acuant/responses/get_results_response.rb | 34 ++----------------- .../lexis_nexis/responses/true_id_response.rb | 34 ++----------------- .../processed_alert_to_log_alert_formatter.rb | 34 +++++++++++++++++++ ...essed_alert_to_log_alert_formatter_spec.rb | 34 +++++++++++++++++++ 4 files changed, 72 insertions(+), 64 deletions(-) create mode 100644 app/services/doc_auth/processed_alert_to_log_alert_formatter.rb create mode 100644 spec/services/doc_auth/processed_alert_to_log_alert_formatter_spec.rb diff --git a/app/services/doc_auth/acuant/responses/get_results_response.rb b/app/services/doc_auth/acuant/responses/get_results_response.rb index 7318fed4231..b301bd93feb 100644 --- a/app/services/doc_auth/acuant/responses/get_results_response.rb +++ b/app/services/doc_auth/acuant/responses/get_results_response.rb @@ -53,13 +53,14 @@ def response_info def create_response_info alerts = processed_alerts + log_alert_formatter = DocAuth::ProcessedAlertToLogAlertFormatter.new { vendor: 'Acuant', billed: result_code.billed, doc_auth_result: result_code.name, processed_alerts: alerts, alert_failure_count: alerts[:failed]&.count.to_i, - log_alert_results: log_alerts(alerts), + log_alert_results: log_alert_formatter.log_alerts(alerts), image_metrics: processed_image_metrics, tamper_result: tamper_result_code&.name, } @@ -95,37 +96,6 @@ def processed_alerts @processed_alerts ||= process_raw_alerts(raw_alerts) end - def get_alert_result(log_alert_results, side, alert_name_key, result) - if log_alert_results.dig(alert_name_key, side.to_sym).present? - alert_value = log_alert_results[alert_name_key][side.to_sym] - Rails.logger. - info("ALERT ALREADY HAS A VALUE: #{alert_value}, #{result}") - end - result - end - - def log_alerts(alerts) - log_alert_results = {} - - alerts.keys.each do |key| - alerts[key.to_sym].each do |alert| - alert_name_key = alert[:name]. - downcase. - parameterize(separator: '_').to_sym - side = alert[:side] || 'no_side' - - log_alert_results[alert_name_key] = - { "#{side}": get_alert_result( - log_alert_results, - side, - alert_name_key, - alert[:result], - ) } - end - end - log_alert_results - end - def processed_image_metrics @processed_image_metrics ||= raw_images_data.index_by do |image| image.delete('Uri') diff --git a/app/services/doc_auth/lexis_nexis/responses/true_id_response.rb b/app/services/doc_auth/lexis_nexis/responses/true_id_response.rb index 00b9321d695..d7c131828c8 100644 --- a/app/services/doc_auth/lexis_nexis/responses/true_id_response.rb +++ b/app/services/doc_auth/lexis_nexis/responses/true_id_response.rb @@ -122,39 +122,9 @@ def response_info @response_info ||= create_response_info end - def get_alert_result(log_alert_results, side, alert_name_key, result) - if log_alert_results.dig(alert_name_key, side.to_sym).present? - alert_value = log_alert_results[alert_name_key][side.to_sym] - Rails.logger. - info("ALERT ALREADY HAS A VALUE: #{alert_value}, #{result}") - end - result - end - - def log_alerts(alerts) - log_alert_results = {} - - alerts.keys.each do |key| - alerts[key.to_sym].each do |alert| - alert_name_key = alert[:name]. - downcase. - parameterize(separator: '_').to_sym - side = alert[:side] || 'no_side' - - log_alert_results[alert_name_key] = - { "#{side}": get_alert_result( - log_alert_results, - side, - alert_name_key, - alert[:result], - ) } - end - end - log_alert_results - end - def create_response_info alerts = parsed_alerts + log_alert_formatter = DocAuth::ProcessedAlertToLogAlertFormatter.new { liveness_enabled: @liveness_checking_enabled, @@ -164,7 +134,7 @@ def create_response_info doc_auth_result: doc_auth_result, processed_alerts: alerts, alert_failure_count: alerts[:failed]&.count.to_i, - log_alert_results: log_alerts(alerts), + log_alert_results: log_alert_formatter.log_alerts(alerts), portrait_match_results: true_id_product[:PORTRAIT_MATCH_RESULT], image_metrics: parse_image_metrics, } diff --git a/app/services/doc_auth/processed_alert_to_log_alert_formatter.rb b/app/services/doc_auth/processed_alert_to_log_alert_formatter.rb new file mode 100644 index 00000000000..a21c09429a4 --- /dev/null +++ b/app/services/doc_auth/processed_alert_to_log_alert_formatter.rb @@ -0,0 +1,34 @@ +module DocAuth + class ProcessedAlertToLogAlertFormatter + def get_alert_result(log_alert_results, side, alert_name_key, result) + if log_alert_results.dig(alert_name_key, side.to_sym).present? + alert_value = log_alert_results[alert_name_key][side.to_sym] + Rails.logger. + info("ALERT ALREADY HAS A VALUE: #{alert_value}, #{result}") + end + result + end + + def log_alerts(alerts) + log_alert_results = {} + + alerts.keys.each do |key| + alerts[key.to_sym].each do |alert| + alert_name_key = alert[:name]. + downcase. + parameterize(separator: '_').to_sym + side = alert[:side] || 'no_side' + + log_alert_results[alert_name_key] = + { "#{side}": get_alert_result( + log_alert_results, + side, + alert_name_key, + alert[:result], + ) } + end + end + log_alert_results + end + end +end diff --git a/spec/services/doc_auth/processed_alert_to_log_alert_formatter_spec.rb b/spec/services/doc_auth/processed_alert_to_log_alert_formatter_spec.rb new file mode 100644 index 00000000000..26384cf86a8 --- /dev/null +++ b/spec/services/doc_auth/processed_alert_to_log_alert_formatter_spec.rb @@ -0,0 +1,34 @@ +require 'rails_helper' + +RSpec.describe DocAuth::ProcessedAlertToLogAlertFormatter do + let(:alerts) do + { passed: [{ alert: 'Alert_1', name: 'Visible Pattern', result: 'Passed' }], + failed: + [ + { alert: 'Alert_1', name: '2D Barcode Read', result: 'Failed' }, + { alert: 'Alert_2', name: 'Layout Valid', result: 'Attention' }, + { alert: 'Alert_3', name: '2D Barcode Read', result: 'Failed' }, + { alert: 'Alert_4', name: 'Visible Pattern', result: 'Failed' }, + { alert: 'Alert_5', name: 'Visible Photo Characteristics', result: 'Failed' }, + ] } + end + + context('when ProcessedAlertToLogAlertFormatter is called') do + subject { + DocAuth::ProcessedAlertToLogAlertFormatter.new.log_alerts(alerts) + } + + it('returns failed if both passed and failed are returned by the alert') do + expect(subject).to match(a_hash_including(visible_pattern: { no_side: 'Failed' })) + end + + it('returns the formatted log hash') do + expect(subject).to eq( + { '2d_barcode_read': { no_side: 'Failed' }, + layout_valid: { no_side: 'Attention' }, + visible_pattern: { no_side: 'Failed' }, + visible_photo_characteristics: { no_side: 'Failed' } }, + ) + end + end +end From de25f663895beae55e23659b115868e832e4bba1 Mon Sep 17 00:00:00 2001 From: Parissa Date: Wed, 3 Aug 2022 10:28:12 -0400 Subject: [PATCH 11/12] add a comment to service class method --- .../doc_auth/processed_alert_to_log_alert_formatter_spec.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spec/services/doc_auth/processed_alert_to_log_alert_formatter_spec.rb b/spec/services/doc_auth/processed_alert_to_log_alert_formatter_spec.rb index 26384cf86a8..d4dd3823417 100644 --- a/spec/services/doc_auth/processed_alert_to_log_alert_formatter_spec.rb +++ b/spec/services/doc_auth/processed_alert_to_log_alert_formatter_spec.rb @@ -1,3 +1,6 @@ +# Take the proccessed alerts and reformat them in a hash so that its easier to search and collect stats +# through cloudwatch. + require 'rails_helper' RSpec.describe DocAuth::ProcessedAlertToLogAlertFormatter do From 1517f52f7528504b1e4d49dc6e955b59a9a3db2f Mon Sep 17 00:00:00 2001 From: Parissa Date: Wed, 3 Aug 2022 11:11:31 -0400 Subject: [PATCH 12/12] update lint errors --- .../doc_auth/processed_alert_to_log_alert_formatter_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/services/doc_auth/processed_alert_to_log_alert_formatter_spec.rb b/spec/services/doc_auth/processed_alert_to_log_alert_formatter_spec.rb index d4dd3823417..ce00c1fe573 100644 --- a/spec/services/doc_auth/processed_alert_to_log_alert_formatter_spec.rb +++ b/spec/services/doc_auth/processed_alert_to_log_alert_formatter_spec.rb @@ -1,5 +1,5 @@ -# Take the proccessed alerts and reformat them in a hash so that its easier to search and collect stats -# through cloudwatch. +# Take the proccessed alerts and reformat them in a hash so that its easier to search and collect +# stats through cloudwatch. require 'rails_helper' @@ -18,7 +18,7 @@ context('when ProcessedAlertToLogAlertFormatter is called') do subject { - DocAuth::ProcessedAlertToLogAlertFormatter.new.log_alerts(alerts) + DocAuth::ProcessedAlertToLogAlertFormatter.new.log_alerts(alerts) } it('returns failed if both passed and failed are returned by the alert') do