Skip to content

Commit

Permalink
Merge branch 'develop' into feat.newDestBlueCore
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouti1507 authored Feb 14, 2024
2 parents f8e0953 + 6a364fb commit e13abae
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/v0/destinations/am/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,16 +614,16 @@ const processSingleMessage = (message, destination) => {
case EventType.PAGE:
if (useUserDefinedPageEventName) {
const getMessagePath = userProvidedPageEventString
.substring(
?.substring(
userProvidedPageEventString.indexOf('{') + 2,
userProvidedPageEventString.indexOf('}'),
)
.trim();
evType =
userProvidedPageEventString.trim() === ''
userProvidedPageEventString?.trim() === ''
? name
: userProvidedPageEventString
.trim()
?.trim()
.replaceAll(/{{([^{}]+)}}/g, get(message, getMessagePath));
} else {
evType = `Viewed ${name || get(message, CATEGORY_KEY) || ''} Page`;
Expand Down Expand Up @@ -701,6 +701,7 @@ const processSingleMessage = (message, destination) => {
logger.debug('could not determine type');
throw new InstrumentationError('message type not supported');
}
AMUtils.validateEventType(evType);
return responseBuilderSimple(
groupInfo,
payloadObjectName,
Expand Down
33 changes: 32 additions & 1 deletion src/v0/destinations/am/util.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { getUnsetObj } = require('./utils');
const { getUnsetObj, validateEventType } = require('./utils');

describe('getUnsetObj', () => {
it("should return undefined when 'message.integrations.Amplitude.fieldsToUnset' is not array", () => {
Expand Down Expand Up @@ -64,3 +64,34 @@ describe('getUnsetObj', () => {
expect(result).toBeUndefined();
});
});


describe('validateEventType', () => {

it('should validate event type when it is valid with only page name given', () => {
expect(() => {
validateEventType('Home Page');
}).not.toThrow();
});

it('should throw an error when event type is null', () => {
expect(() => {
validateEventType(null);
}).toThrow('Event type is missing. Please send it under `event.type`. For page/screen events, send it under `event.name`');
});

it('should throw an error when event type is undefined', () => {
expect(() => {
validateEventType(undefined);
}).toThrow('Event type is missing. Please send it under `event.type`. For page/screen events, send it under `event.name`');
});

// Function receives an empty string as event type
it('should throw an error when event type is an empty string', () => {
expect(() => {
validateEventType('');
}).toThrow('Event type is missing. Please send it under `event.type`. For page/screen events, send it under `event.name`');
});

});

15 changes: 15 additions & 0 deletions src/v0/destinations/am/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// populate these dest keys
const get = require('get-value');
const uaParser = require('@amplitude/ua-parser-js');
const { InstrumentationError } = require('@rudderstack/integrations-lib');
const logger = require('../../../logger');
const { isDefinedAndNotNull } = require('../../util');

Expand Down Expand Up @@ -108,6 +109,19 @@ const getUnsetObj = (message) => {

return unsetObject;
};

/**
* Check for evType as in some cases, like when the page name is absent,
* either the template depends only on the event.name or there is no template provided by user
* @param {*} evType
*/
const validateEventType = (evType) => {
if (!isDefinedAndNotNull(evType) || (typeof evType === "string" && evType.length ===0)) {
throw new InstrumentationError(
'Event type is missing. Please send it under `event.type`. For page/screen events, send it under `event.name`',
);
}
};
module.exports = {
getOSName,
getOSVersion,
Expand All @@ -117,4 +131,5 @@ module.exports = {
getBrand,
getEventId,
getUnsetObj,
validateEventType
};
4 changes: 2 additions & 2 deletions src/v0/destinations/ga4/networkHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ const responseHandler = (destinationResponse, dest) => {
const { description, validationCode, fieldPath } = response.validationMessages[0];
throw new NetworkError(
`Validation Server Response Handler:: Validation Error for ${dest} of field path :${fieldPath} | ${validationCode}-${description}`,
status,
400,
{
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(status),
[tags.TAG_NAMES.ERROR_TYPE]: getDynamicErrorType(400),
},
response?.validationMessages[0]?.description,
);
Expand Down
2 changes: 1 addition & 1 deletion src/v0/destinations/tiktok_ads/transformV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const getTrackResponsePayload = (message, destConfig, event) => {
}

// if contents is not present but we have properties.products present which has fields with superset of contents fields
if (payload.properties && !payload.properties.contents && message.properties.products) {
if (!payload.properties?.contents && message.properties?.products) {
// retreiving data from products only when contents is not present
payload.properties.contents = getContents(message, false);
}
Expand Down
53 changes: 53 additions & 0 deletions test/integrations/destinations/am/processor/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11327,4 +11327,57 @@ export const data = [
},
},
},
{
name: 'am',
description:
'Test 78 -> Page call invalid event type as page name and template is not provided',
feature: 'processor',
module: 'destination',
version: 'v0',
input: {
request: {
body: [
{
message: {
request_ip: '1.1.1.1',
type: 'page',
userId: '12345',
properties: {},
integrations: {
All: true,
},
sentAt: '2019-10-14T11:15:53.296Z',
},
destination: {
Config: {
apiKey: 'abcde',
useUserDefinedPageEventName: true,
userProvidedPageEventString: '',
},
},
},
],
},
},
output: {
response: {
status: 200,
body: [
{
statusCode: 400,
error:
'Event type is missing. Please send it under `event.type`. For page/screen events, send it under `event.name`',
statTags: {
errorCategory: 'dataValidation',
errorType: 'instrumentation',
destType: 'AM',
module: 'destination',
implementation: 'native',
feature: 'processor',
},
},
],
},
},
},
];
103 changes: 103 additions & 0 deletions test/integrations/destinations/tiktok_ads/processor/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6870,4 +6870,107 @@ export const data = [
},
},
},
{
name: 'tiktok_ads',
description: 'Test 46 -> V2 -> Event with no properties',
feature: 'processor',
module: 'destination',
version: 'v0',
input: {
request: {
body: [
{
message: {
anonymousId: '21e13f4bc7ceddad',
channel: 'web',
context: {
traits: {
email: 'dd6ff77f54e2106661089bae4d40cdb600979bf7edc9eb65c0942ba55c7c2d7f',
},
userAgent:
'Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion',
ip: '13.57.97.131',
locale: 'en-US',
externalId: [
{
type: 'tiktokExternalId',
id: 'f0e388f53921a51f0bb0fc8a2944109ec188b59172935d8f23020b1614cc44bc',
},
],
},
messageId: '84e26acc-56a5-4835-8233-591137fca468',
session_id: '3049dc4c-5a95-4ccd-a3e7-d74a7e411f22',
originalTimestamp: '2019-10-14T09:03:17.562Z',
timestamp: '2020-09-17T19:49:27Z',
type: 'track',
event: 'customEvent',
integrations: {
All: true,
},
sentAt: '2019-10-14T09:03:22.563Z',
},
destination: {
Config: {
version: 'v2',
accessToken: 'dummyAccessToken',
pixelCode: '{{PIXEL-CODE}}',
hashUserProperties: false,
sendCustomEvents: true,
},
},
},
],
},
},
output: {
response: {
status: 200,
body: [
{
output: {
version: '1',
type: 'REST',
method: 'POST',
endpoint: 'https://business-api.tiktok.com/open_api/v1.3/event/track/',
headers: {
'Access-Token': 'dummyAccessToken',
'Content-Type': 'application/json',
},
params: {},
body: {
JSON: {
event_source: 'web',
event_source_id: '{{PIXEL-CODE}}',
partner_name: 'RudderStack',
data: [
{
event: 'customEvent',
event_id: '84e26acc-56a5-4835-8233-591137fca468',
event_time: 1600372167,
properties: { content_type: 'product' },
user: {
locale: 'en-US',
email: 'dd6ff77f54e2106661089bae4d40cdb600979bf7edc9eb65c0942ba55c7c2d7f',
external_id:
'f0e388f53921a51f0bb0fc8a2944109ec188b59172935d8f23020b1614cc44bc',
ip: '13.57.97.131',
user_agent:
'Mozilla/5.0 (platform; rv:geckoversion) Gecko/geckotrail Firefox/firefoxversion',
},
},
],
},
JSON_ARRAY: {},
XML: {},
FORM: {},
},
files: {},
userId: '',
},
statusCode: 200,
},
],
},
},
},
];

0 comments on commit e13abae

Please sign in to comment.