Skip to content

Commit

Permalink
fix: tiktok_ads: validate message.event type (#3203)
Browse files Browse the repository at this point in the history
* fix: tiktok_ads: validate message.event type

* fix: test cases

* fix: validation for event name
  • Loading branch information
anantjain45823 authored Mar 26, 2024
1 parent f51a01a commit a86c277
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
8 changes: 3 additions & 5 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,12 +130,9 @@ 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');
}
let event = message.event?.toLowerCase().trim();
validateEventName(message.event);
let event = message.event.toLowerCase().trim();
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`,
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
6 changes: 3 additions & 3 deletions 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 @@ -6055,7 +6055,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',
Expand Down Expand Up @@ -7004,7 +7004,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

0 comments on commit a86c277

Please sign in to comment.