From 1ab9d9992ef07effe45460ab34565377adcc711b Mon Sep 17 00:00:00 2001 From: GreenAsGrassAP Date: Mon, 8 Jul 2024 15:37:57 -0400 Subject: [PATCH] added testing --- lib/trustedform.js | 2 +- test/trustedform_spec.js | 45 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/lib/trustedform.js b/lib/trustedform.js index 44db367..6db5c43 100644 --- a/lib/trustedform.js +++ b/lib/trustedform.js @@ -179,7 +179,7 @@ const response = (vars, req, res) => { page_url: parsed.insights?.properties?.page_url, parent_page_url: parsed.insights?.properties?.parent_page_url, - languages: parsed.verify?.languages, + languages: parsed.verify?.languages.map(lang => lang.text), language_approved: parsed.verify?.result?.language_approved, success: parsed.verify?.result?.success, }, (v) => { return !isUndefined(v); }); diff --git a/test/trustedform_spec.js b/test/trustedform_spec.js index 80db717..14d6a6b 100644 --- a/test/trustedform_spec.js +++ b/test/trustedform_spec.js @@ -387,6 +387,17 @@ describe('v4', () => { masked_cert_url: 'https://cert.trustedform-dev.com/f1fd052c43f08078a37d840b243daa69a35e8eda' }, vendor: 'Inbound Verbose' + }, + verify: { + languages: [ + { + text: 'I understand that the TrustedForm certificate is sent to the email address I provided above and I will receive product updates as they are released.' + } + ], + result: { + language_approved: true, + success: true + } } }) }; @@ -431,7 +442,10 @@ describe('v4', () => { successful_match: true, time_on_page_in_seconds: 8374, time_zone: 'America/Chicago', - vendor: 'Inbound Verbose' + vendor: 'Inbound Verbose', + languages: ['I understand that the TrustedForm certificate is sent to the email address I provided above and I will receive product updates as they are released.'], + language_approved: true, + success: true }; assert.deepEqual(integration.response({ insights: { page_scan: true }}, {}, res), expected); }); @@ -479,6 +493,35 @@ describe('v4', () => { assert.deepEqual(integration.response({ insights: { page_scan: true }}, {}, res), expected); }); + it('should correctly handle a Verify Consent language failure responses', () => { + const res = { + status: 200, + body: JSON.stringify({ + 'verify': { + 'languages': [ + { + 'text': 'By clicking on the "Get Rates" button below, I consent to be contacted' + } + ], + 'result': { + 'language_approved': false, + 'success': false + } + }, + outcome: 'failure', + reason: 'Consent language not detected in the certificate.' + }) + }; + const expected = { + languages: ['By clicking on the "Get Rates" button below, I consent to be contacted'], + language_approved: false, + success: false, + outcome: 'failure', + reason: 'Consent language not detected in the certificate.', + }; + assert.deepEqual(integration.response({}, {}, res), expected); + }); + it('should correctly handle an error response', () => { const res = { status: 500,