Skip to content

Commit

Permalink
chore: add component test cases for some destinations part2 (#2917)
Browse files Browse the repository at this point in the history
* 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
ItsSudip authored Dec 20, 2023
1 parent 99613a0 commit c864ff2
Show file tree
Hide file tree
Showing 96 changed files with 43,270 additions and 39,347 deletions.
8 changes: 4 additions & 4 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ module.exports = {
// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 60,
functions: 75,
lines: 75,
statements: 75,
branches: 30,
functions: 40,
lines: 50,
statements: 50,
},
},

Expand Down
8 changes: 4 additions & 4 deletions jest.default.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ module.exports = {
// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 60,
functions: 75,
lines: 75,
statements: 75,
branches: 30,
functions: 40,
lines: 50,
statements: 50,
},
},

Expand Down
84 changes: 5 additions & 79 deletions test/__mocks__/axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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));
Expand All @@ -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));
}
Expand All @@ -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")) {
Expand All @@ -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 });
Expand All @@ -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));
Expand Down
29 changes: 29 additions & 0 deletions test/__mocks__/braze.mock.js
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 };
34 changes: 34 additions & 0 deletions test/__mocks__/data/braze/proxy_response.json
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": {}
}
}
46 changes: 46 additions & 0 deletions test/__mocks__/data/braze/response.json
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": {}
}
}
Loading

0 comments on commit c864ff2

Please sign in to comment.