Skip to content

Commit

Permalink
Merge branch 'develop' into feat.hs-batching
Browse files Browse the repository at this point in the history
  • Loading branch information
mihir-4116 authored Dec 27, 2023
2 parents 2ac79e9 + 429ca71 commit 52dcfdb
Show file tree
Hide file tree
Showing 185 changed files with 68,417 additions and 59,978 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
11 changes: 10 additions & 1 deletion src/v0/destinations/am/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,15 @@ const identifyBuilder = (message, destination, rawPayload) => {
}
});
}
// update identify call request with unset fields
// AM docs https://www.docs.developers.amplitude.com/analytics/apis/http-v2-api/#keys-for-the-event-argument:~:text=exceed%2040%20layers.-,user_properties,-Optional.%20Object.%20A
const unsetObject = AMUtils.getUnsetObj(message);
if (unsetObject) {
// Example unsetObject = {
// "testObj.del1": "-"
// }
set(rawPayload, `user_properties.$unset`, unsetObject);
}
return rawPayload;
};

Expand Down Expand Up @@ -334,7 +343,7 @@ const getResponseData = (evType, destination, rawPayload, message, groupInfo) =>
case EventType.IDENTIFY:
// event_type for identify event is $identify
rawPayload.event_type = IDENTIFY_AM;
identifyBuilder(message, destination, rawPayload);
rawPayload = identifyBuilder(message, destination, rawPayload);
break;
case EventType.GROUP:
// event_type for identify event is $identify
Expand Down
66 changes: 66 additions & 0 deletions src/v0/destinations/am/util.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
const { getUnsetObj } = require('./utils');

describe('getUnsetObj', () => {
it("should return undefined when 'message.integrations.Amplitude.fieldsToUnset' is not array", () => {
const message = {
integrations: {
Amplitude: { fieldsToUnset: 'field_name' },
},
};
const result = getUnsetObj(message);
expect(result).toBeUndefined();
});
it("should return undefined when 'message.integrations.Amplitude.fieldsToUnset' is undefined", () => {
const message = {
integrations: {
Amplitude: {},
},
};
const result = getUnsetObj(message);
expect(result).toBeUndefined();
});

it("should return an empty objecty when 'message.integrations.Amplitude.fieldsToUnset' is an empty array", () => {
const message = {
integrations: {
Amplitude: { fieldsToUnset: [] },
},
};
const result = getUnsetObj(message);
expect(result).toEqual({});
});

it("should return an object with keys and values set to '-' when 'message.integrations.Amplitude.fieldsToUnset' is an array of strings", () => {
const message = {
integrations: {
Amplitude: { fieldsToUnset: ['Unset1', 'Unset2'] },
},
};
const result = getUnsetObj(message);
expect(result).toEqual({
Unset1: '-',
Unset2: '-',
});
});

it("should handle missing 'message' parameter", () => {
const result = getUnsetObj();
expect(result).toBeUndefined();
});

// Should handle missing 'integrations' property in 'message' parameter
it("should handle missing 'integrations' property in 'message' parameter", () => {
const message = {};
const result = getUnsetObj(message);
expect(result).toBeUndefined();
});

// Should handle missing 'Amplitude' property in 'message.integrations' parameter
it("should handle missing 'Amplitude' property in 'message.integrations' parameter", () => {
const message = {
integrations: {},
};
const result = getUnsetObj(message);
expect(result).toBeUndefined();
});
});
27 changes: 27 additions & 0 deletions src/v0/destinations/am/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,32 @@ const getEventId = (payload, sourceKey) => {
return undefined;
};

/**
* generates the unsetObject and returns it
* @param {*} message
* @returns
*
* Example message = {
integrations: {
Amplitude: { fieldsToUnset: ['Unset1', 'Unset2'] },
All: true,
},
};
return unsetObj = {
"Unset1": "-",
"Unset2": "-"
}
AM docs: https://www.docs.developers.amplitude.com/analytics/apis/http-v2-api/#keys-for-the-event-argument:~:text=exceed%2040%20layers.-,user_properties,-Optional.%20Object.%20A
*/
const getUnsetObj = (message) => {
const fieldsToUnset = get(message, 'integrations.Amplitude.fieldsToUnset');
let unsetObject;
if (Array.isArray(fieldsToUnset)) {
unsetObject = Object.fromEntries(fieldsToUnset.map((field) => [field, '-']));
}

return unsetObject;
};
module.exports = {
getOSName,
getOSVersion,
Expand All @@ -90,4 +116,5 @@ module.exports = {
getPlatform,
getBrand,
getEventId,
getUnsetObj,
};
1 change: 1 addition & 0 deletions src/v0/destinations/tiktok_ads/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const getContents = (message) => {
price: product.price,
quantity: product.quantity,
description: product.description,
brand: product.brand
};
contents.push(removeUndefinedAndNullValues(singleProduct));
});
Expand Down
144 changes: 5 additions & 139 deletions test/__mocks__/axios.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,69 +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 { hsGetRequestHandler, hsPostRequestHandler } = require("./hs.mock");
const { delightedGetRequestHandler } = require("./delighted.mock");
const { dripPostRequestHandler } = require("./drip.mock");
const profitwellGetRequestHandler = require("./profitwell.mock");
const cannyPostRequestHandler = require("./canny.mock");
const custifyPostRequestHandler = require("./custify.mock");
const {
wootricGetRequestHandler,
wootricPostRequestHandler
} = require("./wootric.mock");
const { userGetRequestHandler, userPutRequestHandler } = require("./user.mock");
const { mixpanelPostRequestHandler } = require("./mixpanel.mock");
const { clickUpGetRequestHandler } = require("./clickup.mock");
const {
freshmarketerPostRequestHandler,
freshmarketerGetRequestHandler
} = require("./freshmarketer.mock");
const { mondayPostRequestHandler } = require("./monday.mock");
const {
freshsalesGetRequestHandler,
freshsalesPostRequestHandler
} = require("./freshsales.mock");
const { sendgridGetRequestHandler } = require("./sendgrid.mock");
const { sendinblueGetRequestHandler } = require("./sendinblue.mock");
const { courierGetRequestHandler } = require("./courier.mock");
const { brazePostRequestHandler } = require("./braze.mock");

const urlDirectoryMap = {
"api.hubapi.com": "hs",
"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 @@ -85,75 +46,19 @@ 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.hubapi.com")) {
return hsGetRequestHandler(url, mockData);
}
if (url.includes("https://api.delighted.com/v1/people.json")) {
return delightedGetRequestHandler(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://api.wootric.com")) {
return new Promise((resolve, reject) => {
resolve(wootricGetRequestHandler(url));
});
}
if (url.includes("https://commander.user.com")) {
return new Promise((resolve, reject) => {
resolve(userGetRequestHandler(url));
});
}
if (url.includes("https://api.clickup.com")) {
return Promise.resolve(clickUpGetRequestHandler(url));
}
if (url.includes("https://domain-rudder.myfreshworks.com/crm/sales/api")) {
return Promise.resolve(freshmarketerGetRequestHandler(url));
}
if (url.includes("https://domain-rudder.myfreshworks.com/crm/sales/api")) {
return Promise.resolve(freshsalesGetRequestHandler(url));
}
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 @@ -177,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 @@ -197,22 +97,11 @@ function post(url, payload) {
resolve(yahooDspPostRequestHandler(url, payload));
});
}
if (url.includes("https://api.getdrip.com/v2/1809802/subscribers")) {
return dripPostRequestHandler(url, payload);
}
if (url.includes("https://canny.io/api/v1/users/retrieve")) {
return new Promise((resolve, reject) => {
resolve(cannyPostRequestHandler(url));
});
}
if (url.includes("https://api.hubapi.com")) {
return hsPostRequestHandler(payload, mockData);
}
if (url.includes("https://api.wootric.com")) {
return new Promise((resolve, reject) => {
resolve(wootricPostRequestHandler(url, payload));
});
}
if (
url.includes("https://api.mixpanel.com/engage/") ||
url.includes("https://api-eu.mixpanel.com/engage/")
Expand All @@ -221,27 +110,11 @@ function post(url, payload) {
resolve(mixpanelPostRequestHandler(url, payload));
});
}
if (url.includes("https://domain-rudder.myfreshworks.com/crm/sales/api")) {
if(url.includes("braze.com")) {
return new Promise((resolve, reject) => {
resolve(freshmarketerPostRequestHandler(url));
resolve(brazePostRequestHandler(url, payload));
});
}
if (url.includes("https://domain-rudder.myfreshworks.com/crm/sales/api")) {
return new Promise((resolve, reject) => {
resolve(freshsalesPostRequestHandler(url));
});
}
if (
url.includes("https://api.monday.com") &&
payload.query.includes("query")
) {
return new Promise((resolve, reject) => {
resolve(mondayPostRequestHandler(payload));
});
}
if (url.includes("https://api.custify.com")) {
return Promise.resolve(custifyPostRequestHandler(url));
}
return new Promise((resolve, reject) => {
if (mockData) {
resolve({ data: mockData, status: 200 });
Expand All @@ -253,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
Loading

0 comments on commit 52dcfdb

Please sign in to comment.