-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: onboard Adobe Analytics to transformer proxy (#2858)
* chore: init onboard * chore: add network handler * chore: add test * fix: adding correct mock with corrections & modify the status-code in test-case Signed-off-by: Sai Sankeerth <[email protected]> * chore: add dummy destination id * chore: add dummy ws id * chore: add tests for success and generic error case --------- Signed-off-by: Sai Sankeerth <[email protected]> Co-authored-by: Sai Sankeerth <[email protected]>
- Loading branch information
1 parent
36d3f25
commit e8f2d1a
Showing
4 changed files
with
244 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
const { InstrumentationError } = require('@rudderstack/integrations-lib'); | ||
const { proxyRequest, prepareProxyRequest } = require('../../../adapters/network'); | ||
const { | ||
processAxiosResponse, | ||
} = require('../../../adapters/utils/networkUtils'); | ||
const { DESTINATION } = require('./config'); | ||
|
||
|
||
/** | ||
* Extract data inside different tags from an xml payload | ||
* @param {*} xml | ||
* @param {*} tagName | ||
* @returns data inside the tagName | ||
*/ | ||
function extractContent(xmlPayload, tagName) { | ||
const pattern = new RegExp(`<${tagName}>(.*?)</${tagName}>`); | ||
const match = xmlPayload.match(pattern); | ||
return match ? match[1] : null; | ||
} | ||
|
||
const responseHandler = (destinationResponse, dest) => { | ||
const message = `[${DESTINATION}] - Request Processed Successfully`; | ||
const { response, status } = destinationResponse; | ||
|
||
// Extract values between different tags | ||
const responseStatus = extractContent(response, 'status'); | ||
const reason = extractContent(response, 'reason'); | ||
|
||
// if the status tag in XML contains FAILURE, we build and throw an explicit error | ||
if (responseStatus === 'FAILURE') { | ||
if (reason) { | ||
throw new InstrumentationError(`[${DESTINATION} Response Handler] Request failed for destination ${dest} : ${reason}` ) | ||
} else { | ||
throw new InstrumentationError(`[${DESTINATION} Response Handler] Request failed for destination ${dest} with a general error`) | ||
} | ||
} | ||
|
||
return { | ||
status, | ||
message, | ||
destinationResponse, | ||
}; | ||
}; | ||
|
||
function networkHandler() { | ||
this.responseHandler = responseHandler; | ||
this.proxy = proxyRequest; | ||
this.prepareProxy = prepareProxyRequest; | ||
this.processAxiosResponse = processAxiosResponse; | ||
} | ||
|
||
module.exports = { | ||
networkHandler, | ||
}; |
142 changes: 142 additions & 0 deletions
142
test/integrations/destinations/adobe_analytics/dataDelivery/data.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
export const data = [ | ||
{ | ||
name: 'adobe_analytics', | ||
description: 'Test 0: Failure response from Adobe Analytics with reason', | ||
feature: 'dataDelivery', | ||
module: 'destination', | ||
version: 'v0', | ||
input: { | ||
request: { | ||
body: { | ||
version: '1', | ||
type: 'REST', | ||
method: 'POST', | ||
endpoint: 'https://adobe.failure.omtrdc.net/b/ss//6', | ||
headers: { | ||
'Content-type': 'application/xml', | ||
}, | ||
params: {}, | ||
body: { | ||
JSON: {}, | ||
JSON_ARRAY: {}, | ||
XML: { | ||
payload: | ||
'<?xml version="1.0" encoding="utf-8"?><request><browserHeight>1794</browserHeight><browserWidth>1080</browserWidth><campaign>sales campaign</campaign><channel>web</channel><currencyCode>USD</currencyCode><ipaddress>127.0.0.1</ipaddress><language>en-US</language><userAgent>Dalvik/2.1.0 (Linux; U; Android 9; Android SDK built for x86 Build/PSR1.180720.075)</userAgent><referrer>https://www.google.com/search?q=estore+bestseller</referrer><marketingcloudorgid/><events>prodView</events><products>Games;;11;148.39</products><reportSuiteID>failureReport</reportSuiteID></request>', | ||
}, | ||
FORM: {}, | ||
}, | ||
files: {}, | ||
}, | ||
method: 'POST', | ||
}, | ||
}, | ||
output: { | ||
response: { | ||
status: 400, | ||
statTags: { | ||
errorCategory: 'dataValidation', | ||
errorType: 'instrumentation', | ||
destType: 'ADOBE_ANALYTICS', | ||
module: 'destination', | ||
implementation: 'native', | ||
feature: 'dataDelivery', | ||
destinationId: '2S3s0dXXXXXX7m0UfBwyblDrzs', | ||
workspaceId: '1pKWrE6GXXXXXKBikka1SbRgrSN', | ||
}, | ||
destinationResponse: '', | ||
authErrorCategory: '', | ||
message: | ||
'[ADOBE_ANALYTICS Response Handler] Request failed for destination adobe_analytics : NO pagename OR pageurl', | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: 'adobe_analytics', | ||
description: 'Test 1: Failure response from Adobe Analytics without reason (Generic error)', | ||
feature: 'dataDelivery', | ||
module: 'destination', | ||
version: 'v0', | ||
input: { | ||
request: { | ||
body: { | ||
version: '1', | ||
type: 'REST', | ||
method: 'POST', | ||
endpoint: 'https://adobe.failure2.omtrdc.net/b/ss//6', | ||
headers: { | ||
'Content-type': 'application/xml', | ||
}, | ||
params: {}, | ||
body: { | ||
JSON: {}, | ||
JSON_ARRAY: {}, | ||
XML: { | ||
payload: | ||
'<?xml version="1.0" encoding="utf-8"?><request><browserHeight>1794</browserHeight><browserWidth>1080</browserWidth><campaign>sales campaign</campaign><channel>web</channel><currencyCode>USD</currencyCode><ipaddress>127.0.0.1</ipaddress><language>en-US</language><userAgent>Dalvik/2.1.0 (Linux; U; Android 9; Android SDK built for x86 Build/PSR1.180720.075)</userAgent><referrer>https://www.google.com/search?q=estore+bestseller</referrer><marketingcloudorgid/><events>prodView</events><products>Games;;11;148.39</products><reportSuiteID>failureReportgeneric</reportSuiteID></request>', | ||
}, | ||
FORM: {}, | ||
}, | ||
files: {}, | ||
}, | ||
method: 'POST', | ||
}, | ||
}, | ||
output: { | ||
response: { | ||
status: 400, | ||
statTags: { | ||
errorCategory: 'dataValidation', | ||
errorType: 'instrumentation', | ||
destType: 'ADOBE_ANALYTICS', | ||
module: 'destination', | ||
implementation: 'native', | ||
feature: 'dataDelivery', | ||
destinationId: '2S3s0dXXXXXX7m0UfBwyblDrzs', | ||
workspaceId: '1pKWrE6GXXXXXKBikka1SbRgrSN', | ||
}, | ||
destinationResponse: '', | ||
authErrorCategory: '', | ||
message: | ||
'[ADOBE_ANALYTICS Response Handler] Request failed for destination adobe_analytics with a general error', | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: 'adobe_analytics', | ||
description: 'Test 2: Success response from Adobe Analytics', | ||
feature: 'dataDelivery', | ||
module: 'destination', | ||
version: 'v0', | ||
input: { | ||
request: { | ||
body: { | ||
version: '1', | ||
type: 'REST', | ||
method: 'POST', | ||
endpoint: 'https://adobe.success.omtrdc.net/b/ss//6', | ||
headers: { | ||
'Content-type': 'application/xml', | ||
}, | ||
params: {}, | ||
body: { | ||
JSON: {}, | ||
JSON_ARRAY: {}, | ||
XML: { | ||
payload: | ||
'<?xml version="1.0" encoding="utf-8"?><request><ipaddress>127.0.1.0</ipaddress><pageUrl>www.google.co.in</pageUrl><pageName>Google</pageName><visitorID>id1110011</visitorID><events>prodView</events><products>Games;Monopoly;1;14.00,Games;UNO;2;6.90</products><reportSuiteID>successreport</reportSuiteID></request>', | ||
}, | ||
FORM: {}, | ||
}, | ||
files: {}, | ||
}, | ||
method: 'POST', | ||
}, | ||
}, | ||
output: { | ||
response: { | ||
status: 200, | ||
destinationResponse: '<?xml version="1.0" encoding="UTF-8"?><status>SUCCESS</status>', | ||
}, | ||
}, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
export const networkCallsData = [ | ||
{ | ||
httpReq: { | ||
url: 'https://adobe.failure.omtrdc.net/b/ss//6', | ||
data: '<?xml version="1.0" encoding="utf-8"?><request><browserHeight>1794</browserHeight><browserWidth>1080</browserWidth><campaign>sales campaign</campaign><channel>web</channel><currencyCode>USD</currencyCode><ipaddress>127.0.0.1</ipaddress><language>en-US</language><userAgent>Dalvik/2.1.0 (Linux; U; Android 9; Android SDK built for x86 Build/PSR1.180720.075)</userAgent><referrer>https://www.google.com/search?q=estore+bestseller</referrer><marketingcloudorgid/><events>prodView</events><products>Games;;11;148.39</products><reportSuiteID>failureReport</reportSuiteID></request>', | ||
params: {}, | ||
headers: { | ||
'Content-Type': 'application/xml', | ||
}, | ||
method: 'POST', | ||
}, | ||
httpRes: { | ||
status: 200, | ||
data: '<?xml version="1.0" encoding="UTF-8"?><status>FAILURE</status><reason>NO pagename OR pageurl</reason>', | ||
}, | ||
}, | ||
{ | ||
httpReq: { | ||
url: 'https://adobe.failure2.omtrdc.net/b/ss//6', | ||
data: '<?xml version="1.0" encoding="utf-8"?><request><browserHeight>1794</browserHeight><browserWidth>1080</browserWidth><campaign>sales campaign</campaign><channel>web</channel><currencyCode>USD</currencyCode><ipaddress>127.0.0.1</ipaddress><language>en-US</language><userAgent>Dalvik/2.1.0 (Linux; U; Android 9; Android SDK built for x86 Build/PSR1.180720.075)</userAgent><referrer>https://www.google.com/search?q=estore+bestseller</referrer><marketingcloudorgid/><events>prodView</events><products>Games;;11;148.39</products><reportSuiteID>failureReportgeneric</reportSuiteID></request>', | ||
params: {}, | ||
headers: { | ||
'Content-Type': 'application/xml', | ||
}, | ||
method: 'POST', | ||
}, | ||
httpRes: { | ||
status: 200, | ||
data: '<?xml version="1.0" encoding="UTF-8"?><status>FAILURE</status>', | ||
}, | ||
}, | ||
{ | ||
httpReq: { | ||
url: 'https://adobe.success.omtrdc.net/b/ss//6', | ||
data: '<?xml version="1.0" encoding="utf-8"?><request><ipaddress>127.0.1.0</ipaddress><pageUrl>www.google.co.in</pageUrl><pageName>Google</pageName><visitorID>id1110011</visitorID><events>prodView</events><products>Games;Monopoly;1;14.00,Games;UNO;2;6.90</products><reportSuiteID>successreport</reportSuiteID></request>', | ||
params: {}, | ||
headers: { | ||
'Content-Type': 'application/xml', | ||
}, | ||
method: 'POST', | ||
}, | ||
httpRes: { | ||
status: 200, | ||
data: '<?xml version="1.0" encoding="UTF-8"?><status>SUCCESS</status>', | ||
}, | ||
}, | ||
]; |