From f9fe2be4b9458c8d59bc765b840f029eab669911 Mon Sep 17 00:00:00 2001 From: Anant Jain Date: Fri, 22 Mar 2024 11:41:12 +0530 Subject: [PATCH 1/3] fix: tiktok_ads: validate message.event type --- src/v0/destinations/tiktok_ads/transform.js | 6 +- src/v0/destinations/tiktok_ads/transformV2.js | 3 +- .../destinations/tiktok_ads/processor/data.ts | 58 ++++++++++++++++++- 3 files changed, 62 insertions(+), 5 deletions(-) diff --git a/src/v0/destinations/tiktok_ads/transform.js b/src/v0/destinations/tiktok_ads/transform.js index bdf3a0defe..04a28af327 100644 --- a/src/v0/destinations/tiktok_ads/transform.js +++ b/src/v0/destinations/tiktok_ads/transform.js @@ -20,6 +20,7 @@ const { checkInvalidRtTfEvents, handleRtTfSingleEventError, batchMultiplexedEvents, + validateEventName, } = require('../../util'); const { process: processV2, processRouterDest: processRouterDestV2 } = require('./transformV2'); const { getContents } = require('./util'); @@ -130,12 +131,11 @@ const getTrackResponse = (message, Config, event) => { const trackResponseBuilder = async (message, { Config }) => { const { eventsToStandard, sendCustomEvents } = Config; - - let event = message.event?.toLowerCase().trim(); + validateEventName(message.event); + let event = message.event.toLowerCase().trim(); if (!event) { throw new InstrumentationError('Event name is required'); } - const standardEventsMap = getHashFromArrayWithDuplicate(eventsToStandard); if (!sendCustomEvents && eventNameMapping[event] === undefined && !standardEventsMap[event]) { diff --git a/src/v0/destinations/tiktok_ads/transformV2.js b/src/v0/destinations/tiktok_ads/transformV2.js index 98f7d61e1e..feb7b1b4f6 100644 --- a/src/v0/destinations/tiktok_ads/transformV2.js +++ b/src/v0/destinations/tiktok_ads/transformV2.js @@ -15,6 +15,7 @@ const { getHashFromArrayWithDuplicate, checkInvalidRtTfEvents, handleRtTfSingleEventError, + validateEventName, } = require('../../util'); const { getContents, hashUserField } = require('./util'); const config = require('./config'); @@ -60,7 +61,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'); diff --git a/test/integrations/destinations/tiktok_ads/processor/data.ts b/test/integrations/destinations/tiktok_ads/processor/data.ts index 3b68426fbf..5e5311d56b 100644 --- a/test/integrations/destinations/tiktok_ads/processor/data.ts +++ b/test/integrations/destinations/tiktok_ads/processor/data.ts @@ -1369,7 +1369,7 @@ export const data = [ body: [ { statusCode: 400, - error: 'Event name is required', + error: 'Event is a required field and should be a string', statTags: { errorCategory: 'dataValidation', errorType: 'instrumentation', @@ -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, From b2291d544e2154dbe84079acdea7b2c3e34436da Mon Sep 17 00:00:00 2001 From: Anant Jain Date: Tue, 26 Mar 2024 13:05:01 +0530 Subject: [PATCH 2/3] fix: test cases --- test/integrations/destinations/tiktok_ads/processor/data.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integrations/destinations/tiktok_ads/processor/data.ts b/test/integrations/destinations/tiktok_ads/processor/data.ts index 204096e4f9..73a1aa862e 100644 --- a/test/integrations/destinations/tiktok_ads/processor/data.ts +++ b/test/integrations/destinations/tiktok_ads/processor/data.ts @@ -7060,7 +7060,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', From 9549e509e7e84b7c5c41782437ae9ff30d80ed24 Mon Sep 17 00:00:00 2001 From: Anant Jain Date: Tue, 26 Mar 2024 13:16:24 +0530 Subject: [PATCH 3/3] fix: validation for event name --- src/v0/destinations/tiktok_ads/transform.js | 5 -- .../destinations/tiktok_ads/processor/data.ts | 56 ------------------- 2 files changed, 61 deletions(-) diff --git a/src/v0/destinations/tiktok_ads/transform.js b/src/v0/destinations/tiktok_ads/transform.js index 4274dcbc5a..17a37984c3 100644 --- a/src/v0/destinations/tiktok_ads/transform.js +++ b/src/v0/destinations/tiktok_ads/transform.js @@ -132,12 +132,7 @@ const trackResponseBuilder = async (message, { Config }) => { const { eventsToStandard, sendCustomEvents } = Config; validateEventName(message.event); let event = message.event.toLowerCase().trim(); - if (!event) { - throw new InstrumentationError('Event name is required'); - } - const standardEventsMap = getHashFromArrayWithDuplicate(eventsToStandard); - if (!sendCustomEvents && eventNameMapping[event] === undefined && !standardEventsMap[event]) { throw new InstrumentationError( `Event name (${event}) is not valid, must be mapped to one of standard events`, diff --git a/test/integrations/destinations/tiktok_ads/processor/data.ts b/test/integrations/destinations/tiktok_ads/processor/data.ts index 73a1aa862e..429024b8a9 100644 --- a/test/integrations/destinations/tiktok_ads/processor/data.ts +++ b/test/integrations/destinations/tiktok_ads/processor/data.ts @@ -6069,62 +6069,6 @@ export const data = [ }, }, }, - { - 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, - body: [ - { - statusCode: 400, - error: 'Event name is required', - statTags: { - errorCategory: 'dataValidation', - errorType: 'instrumentation', - destType: 'TIKTOK_ADS', - module: 'destination', - implementation: 'native', - feature: 'processor', - }, - }, - ], - }, - }, - }, { name: 'tiktok_ads', description: 'Test 39-> V2 -> Access Token not found',