Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tiktok_ads: validate message.event type #3203

Merged
merged 4 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/v0/destinations/tiktok_ads/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const {
getHashFromArrayWithDuplicate,
handleRtTfSingleEventError,
batchMultiplexedEvents,
validateEventName,
} = require('../../util');
const { process: processV2, processRouterDest: processRouterDestV2 } = require('./transformV2');
const { getContents } = require('./util');
Expand Down Expand Up @@ -129,10 +130,12 @@ const getTrackResponse = (message, Config, event) => {

const trackResponseBuilder = async (message, { Config }) => {
const { eventsToStandard, sendCustomEvents } = Config;
if (!message.event || typeof message.event !== 'string') {
throw new InstrumentationError('Either event name is not present or it is not a string');
validateEventName(message.event);
let event = message.event.toLowerCase().trim();
if (!event) {
throw new InstrumentationError('Event name is required');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldnt validateEventName take care of it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case the event name is an empty string it would not take care of it

}
let event = message.event?.toLowerCase().trim();

const standardEventsMap = getHashFromArrayWithDuplicate(eventsToStandard);

if (!sendCustomEvents && eventNameMapping[event] === undefined && !standardEventsMap[event]) {
Expand Down
3 changes: 2 additions & 1 deletion src/v0/destinations/tiktok_ads/transformV2.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const {
getDestinationExternalID,
getHashFromArrayWithDuplicate,
handleRtTfSingleEventError,
validateEventName,
} = require('../../util');
const { getContents, hashUserField } = require('./util');
const config = require('./config');
Expand Down Expand Up @@ -59,7 +60,7 @@ const getTrackResponsePayload = (message, destConfig, event) => {

const trackResponseBuilder = async (message, { Config }) => {
const { eventsToStandard, sendCustomEvents, accessToken, pixelCode } = Config;

validateEventName(message.event);
let event = message.event?.toLowerCase().trim();
if (!event) {
throw new InstrumentationError('Event name is required');
Expand Down
58 changes: 57 additions & 1 deletion test/integrations/destinations/tiktok_ads/processor/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1369,7 +1369,7 @@ export const data = [
body: [
{
statusCode: 400,
error: 'Either event name is not present or it is not a string',
error: 'Event is a required field and should be a string',
statTags: {
errorCategory: 'dataValidation',
errorType: 'instrumentation',
Expand Down Expand Up @@ -6049,6 +6049,62 @@ export const data = [
],
},
},
output: {
response: {
status: 200,
body: [
{
statusCode: 400,
error: 'Event is a required field and should be a string',
statTags: {
errorCategory: 'dataValidation',
errorType: 'instrumentation',
destType: 'TIKTOK_ADS',
module: 'destination',
implementation: 'native',
feature: 'processor',
},
},
],
},
},
},
{
name: 'tiktok_ads',
description: 'Test 38-> V2 -> Event name found but include spaces only',
feature: 'processor',
module: 'destination',
version: 'v0',
input: {
request: {
body: [
{
message: {
anonymousId: '21e13f4bc7ceddad',
event: ' ',
channel: 'web',
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',
integrations: {
All: true,
},
sentAt: '2019-10-14T09:03:22.563Z',
},
destination: {
Config: {
accessToken: 'dummyAccessToken',
pixelCode: '{{PIXEL-CODE}}',
hashUserProperties: false,
version: 'v2',
},
},
},
],
},
},
output: {
response: {
status: 200,
Expand Down
Loading