Skip to content

Commit

Permalink
Sc 78630/trustedform verify integration is not appending (#120)
Browse files Browse the repository at this point in the history
* Fix verify response variables mapping
  • Loading branch information
henriquelakiap authored Sep 16, 2024
1 parent b95e41f commit b75c04b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
16 changes: 11 additions & 5 deletions lib/trustedform.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,22 @@ const insightsEnabled = (vars) => vars.trustedform?.insights?.valueOf();
const verifyEnabled = (vars) => vars.trustedform?.verify?.valueOf();
const hasRequiredRetainProps = (vars) => !!(vars.lead.email || vars.lead.phone_1);
const hasAtLeastOneInsightsProp = (vars) => formatProperties(vars.insights).length > 0 || vars.insights?.page_scan?.valueOf();

const hasVerifyData = (data) => {
return data.verify?.languages || data.verify?.result?.language_approved || data.verify?.result?.success;
};

const response = (vars, req, res) => {
if (res.status < 500) {
try {
const parsed = JSON.parse(res.body);
if (res.status === 200) {
const verify = hasVerifyData(parsed) ?
{
languages: parsed.verify.languages.map(lang => lang.text),
language_approved: parsed.verify.result.language_approved,
success: parsed.verify.result.success
} : undefined;

const appended = pickBy({
outcome: parsed.outcome,
reason: parsed.reason,
Expand Down Expand Up @@ -179,10 +188,7 @@ const response = (vars, req, res) => {
os_name: parsed.insights?.properties?.os?.name,
page_url: parsed.insights?.properties?.page_url,
parent_page_url: parsed.insights?.properties?.parent_page_url,

languages: parsed.verify?.languages.map(lang => lang.text),
language_approved: parsed.verify?.result?.language_approved,
success: parsed.verify?.result?.success,
verify
}, (v) => { return !isUndefined(v); });
// only include this property if page scan was selected
if (vars.insights?.page_scan?.valueOf()) {
Expand Down
16 changes: 10 additions & 6 deletions test/trustedform_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -490,9 +490,11 @@ describe('v4', () => {
time_on_page_in_seconds: 8374,
time_zone: 'America/Chicago',
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
verify: {
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);
});
Expand Down Expand Up @@ -556,9 +558,11 @@ describe('v4', () => {
})
};
const expected = {
languages: ['By clicking on the "Get Rates" button below, I consent to be contacted'],
language_approved: false,
success: false,
verify: {
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.',
};
Expand Down

0 comments on commit b75c04b

Please sign in to comment.