-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add component test cases for some destinations part2 (#2917)
* chore: add component test cases for some destinations * chore: added component test cases for desitnations * chore: decrease coverageThreshold in jest.config.js * chore: decrease coverageThreshold in jest.default.config.js
- Loading branch information
Showing
96 changed files
with
43,270 additions
and
39,347 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
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 |
---|---|---|
|
@@ -3,51 +3,30 @@ | |
/// ///////////////////////////////////////////////////////////////////////////// | ||
const axios = jest.genMockFromModule("axios"); | ||
const acPostRequestHandler = require("./active_campaign.mock"); | ||
const { | ||
klaviyoPostRequestHandler, | ||
klaviyoGetRequestHandler | ||
} = require("./klaviyo.mock"); | ||
|
||
const kustomerGetRequestHandler = require("./kustomer.mock"); | ||
const trengoGetRequestHandler = require("./trengo.mock"); | ||
const gainsightRequestHandler = require("./gainsight.mock"); | ||
const mailchimpGetRequestHandler = require("./mailchimp.mock"); | ||
const yahooDspPostRequestHandler = require("./yahoo_dsp.mock"); | ||
const { gainsightPXGetRequestHandler } = require("./gainsight_px.mock"); | ||
const profitwellGetRequestHandler = require("./profitwell.mock"); | ||
const cannyPostRequestHandler = require("./canny.mock"); | ||
const { userGetRequestHandler, userPutRequestHandler } = require("./user.mock"); | ||
const { mixpanelPostRequestHandler } = require("./mixpanel.mock"); | ||
const { mondayPostRequestHandler } = require("./monday.mock"); | ||
const { sendgridGetRequestHandler } = require("./sendgrid.mock"); | ||
const { sendinblueGetRequestHandler } = require("./sendinblue.mock"); | ||
const { courierGetRequestHandler } = require("./courier.mock"); | ||
const { brazePostRequestHandler } = require("./braze.mock"); | ||
|
||
const urlDirectoryMap = { | ||
"zendesk.com": "zendesk", | ||
"salesforce.com": "salesforce", | ||
"mktorest.com": "marketo", | ||
"active.campaigns.rudder.com": "active_campaigns", | ||
"api.aptrinsic.com": "gainsight_px", | ||
"api.profitwell.com": "profitwell", | ||
"ruddertest2.mautic.net": "mautic", | ||
"api.sendgrid.com": "sendgrid", | ||
"api.sendinblue.com": "sendinblue", | ||
"api.criteo.com": "criteo_audience", | ||
"api.courier.com": "courier", | ||
}; | ||
|
||
const fs = require("fs"); | ||
const path = require("path"); | ||
|
||
const getParamEncodedUrl = (url, options) => { | ||
const { params } = options; | ||
const paramString = Object.keys(params) | ||
.map(key => `${key}=${params[key]}`) | ||
.join("&"); | ||
return `${url}?${paramString}`; | ||
}; | ||
|
||
function getData(url) { | ||
let directory = ""; | ||
Object.keys(urlDirectoryMap).forEach(key => { | ||
|
@@ -67,44 +46,11 @@ function getData(url) { | |
|
||
function get(url, options) { | ||
const mockData = getData(url); | ||
if (url.includes("https://api.kustomerapp.com") || url.includes("https://api.prod2.kustomerapp.com")) { | ||
return new Promise((resolve, reject) => { | ||
resolve(kustomerGetRequestHandler(url)); | ||
}); | ||
} | ||
if (url.includes("https://app.trengo.com")) { | ||
return new Promise((resolve, reject) => { | ||
resolve(trengoGetRequestHandler(url)); | ||
}); | ||
} | ||
if (url.includes("api.mailchimp.com")) { | ||
return new Promise((resolve, reject) => { | ||
resolve(mailchimpGetRequestHandler(url)); | ||
}); | ||
} | ||
if (url.includes("https://api.aptrinsic.com")) { | ||
return gainsightPXGetRequestHandler(url, mockData); | ||
} | ||
if (url.includes("https://a.klaviyo.com/api/v2/people/search")) { | ||
return klaviyoGetRequestHandler(getParamEncodedUrl(url, options)); | ||
} | ||
if (url.includes("https://api.profitwell.com")) { | ||
return profitwellGetRequestHandler(url, mockData); | ||
} | ||
if ( | ||
url.includes( | ||
"https://api.getdrip.com/v2/1809802/subscribers/[email protected]" | ||
) | ||
) { | ||
return Promise.resolve({ status: 200 }); | ||
} | ||
if ( | ||
url.includes( | ||
"https://api.getdrip.com/v2/1809802/subscribers/[email protected]" | ||
) | ||
) { | ||
return Promise.reject({ status: 404 }); | ||
} | ||
if (url.includes("https://commander.user.com")) { | ||
return new Promise((resolve, reject) => { | ||
resolve(userGetRequestHandler(url)); | ||
|
@@ -113,9 +59,6 @@ function get(url, options) { | |
if (url.includes("https://api.sendgrid.com/v3/marketing/field_definitions")) { | ||
return Promise.resolve(sendgridGetRequestHandler(url)); | ||
} | ||
if (url.includes("https://api.sendinblue.com/v3/contacts/")) { | ||
return Promise.resolve(sendinblueGetRequestHandler(url, mockData)); | ||
} | ||
if (url.includes("https://api.courier.com")) { | ||
return Promise.resolve(courierGetRequestHandler(url, mockData)); | ||
} | ||
|
@@ -139,14 +82,9 @@ function post(url, payload) { | |
resolve(acPostRequestHandler(url, payload)); | ||
}); | ||
} | ||
if (url.includes("https://a.klaviyo.com")) { | ||
if(url.includes("braze.com")) { | ||
return new Promise((resolve, reject) => { | ||
resolve(klaviyoPostRequestHandler(url, payload)); | ||
}); | ||
} | ||
if (url.includes("https://demo-domain.gainsightcloud.com")) { | ||
return new Promise(resolve => { | ||
resolve(gainsightRequestHandler(url, payload)); | ||
resolve(brazePostRequestHandler(url, payload)); | ||
}); | ||
} | ||
if (url.includes("https://api.aptrinsic.com")) { | ||
|
@@ -172,16 +110,11 @@ function post(url, payload) { | |
resolve(mixpanelPostRequestHandler(url, payload)); | ||
}); | ||
} | ||
|
||
if ( | ||
url.includes("https://api.monday.com") && | ||
payload.query.includes("query") | ||
) { | ||
if(url.includes("braze.com")) { | ||
return new Promise((resolve, reject) => { | ||
resolve(mondayPostRequestHandler(payload)); | ||
resolve(brazePostRequestHandler(url, payload)); | ||
}); | ||
} | ||
|
||
return new Promise((resolve, reject) => { | ||
if (mockData) { | ||
resolve({ data: mockData, status: 200 }); | ||
|
@@ -193,13 +126,6 @@ function post(url, payload) { | |
|
||
function put(url, payload, options) { | ||
const mockData = getData(url); | ||
if (url.includes("https://demo-domain.gainsightcloud.com")) { | ||
return new Promise(resolve => { | ||
resolve( | ||
gainsightRequestHandler(getParamEncodedUrl(url, options), payload) | ||
); | ||
}); | ||
} | ||
if (url.includes("https://commander.user.com")) { | ||
return new Promise((resolve, reject) => { | ||
resolve(userPutRequestHandler(url)); | ||
|
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,29 @@ | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const getData = url => { | ||
const dataFile = fs.readFileSync( | ||
path.resolve(__dirname, "./data/braze/response.json") | ||
); | ||
const data = JSON.parse(dataFile); | ||
const response = data[url]; | ||
return response || {}; | ||
}; | ||
|
||
const brazePostRequestHandler = (url, payload) => { | ||
const mockData = getData(url); | ||
switch (url) { | ||
case "https://rest.iad-03.braze.com": | ||
//resolve with status 201 and response data contains value for contact created | ||
return { data: mockData, status: 201 }; | ||
default: | ||
return new Promise((resolve, reject) => { | ||
if (mockData) { | ||
resolve({ data: mockData, status: 200 }); | ||
} else { | ||
resolve({ error: "Request failed" }); | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
module.exports = { brazePostRequestHandler }; |
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,34 @@ | ||
{ | ||
"https://rest.iad-03.braze.com/users/identify/test1": { | ||
"data": { | ||
"aliases_processed": 1, | ||
"message": "success" | ||
}, | ||
"status": 201 | ||
}, | ||
"https://rest.iad-03.braze.com/users/identify/test2": { | ||
"data": { | ||
"message": "success", | ||
"errors": ["minor error message"] | ||
}, | ||
"status": 201 | ||
}, | ||
"https://rest.iad-03.braze.com/users/identify/test3": { | ||
"data": { | ||
"message": "fatal error message", | ||
"errors": ["minor error message"] | ||
}, | ||
"status": 201 | ||
}, | ||
"https://rest.iad-03.braze.com/users/identify/test4": { | ||
"data": "", | ||
"status": 201 | ||
}, | ||
"https://rest.iad-03.braze.com/users/identify/test5": {}, | ||
"https://rest.iad-03.braze.com/users/identify/test6": { | ||
"code": "[ENOTFOUND] :: DNS lookup failed" | ||
}, | ||
"https://rest.iad-03.braze.com/users/identify/test7": { | ||
"response": {} | ||
} | ||
} |
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,46 @@ | ||
{ | ||
"https://rest.iad-03.braze.com/users/export/ids": { | ||
"users": [ | ||
{ | ||
"created_at": "2023-03-17T20:51:58.297Z", | ||
"external_id": "braze_test_user", | ||
"user_aliases": [], | ||
"appboy_id": "6414d2ee33326e3354e3040b", | ||
"braze_id": "6414d2ee33326e3354e3040b", | ||
"first_name": "Jackson", | ||
"last_name": "Miranda", | ||
"random_bucket": 8134, | ||
"email": "[email protected]", | ||
"custom_attributes": { | ||
"pwa": false, | ||
"is_registered": true, | ||
"last_identify": "GOOGLE_SIGN_IN", | ||
"account_region": "ON", | ||
"is_pickup_selected": "false", | ||
"has_tradein_attempt": false, | ||
"custom_obj_attr": { | ||
"key1": "value1", | ||
"key2": "value2", | ||
"key3": "value3" | ||
}, | ||
"custom_arr": [1, 2, "str1"] | ||
}, | ||
"custom_events": [ | ||
{ | ||
"name": "Sign In Completed", | ||
"first": "2023-03-10T18:36:05.028Z", | ||
"last": "2023-03-10T18:36:05.028Z", | ||
"count": 2 | ||
} | ||
], | ||
"total_revenue": 0, | ||
"push_subscribe": "subscribed", | ||
"email_subscribe": "subscribed" | ||
} | ||
], | ||
"message": "success" | ||
}, | ||
"https://rest.iad-01.braze.com/users/identify": { | ||
"response": {} | ||
} | ||
} |
Oops, something went wrong.