Skip to content

Commit

Permalink
refactor: created separate validateConfig utility for both flows
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauravudia committed Feb 2, 2024
1 parent 354fe58 commit 649df83
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 34 deletions.
7 changes: 3 additions & 4 deletions src/cdk/v2/destinations/the_trade_desk/rtWorkflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,12 @@ bindings:
path: '@rudderstack/integrations-lib'

steps:
- name: validateConfig
- name: validateCommonConfig
description: |
validate common config for first party data and realtime conversion flow
template: |
const config = ^[0].destination.Config
$.assertConfig(config.advertiserId, "Advertiser ID is not present. Aborting")
$.assertConfig(config.advertiserSecretKey, "Advertiser Secret Key is not present. Aborting")
$.assertConfig(config.trackerId, "Tracking Tag ID is not present. Aborting")
config.ttlInDays ? $.assertConfig(config.ttlInDays >=0 && config.ttlInDays <= 180, "TTL is out of range. Allowed values are 0 to 180 days")
- name: validateInput
template: |
Expand Down
11 changes: 8 additions & 3 deletions src/cdk/v2/destinations/the_trade_desk/transformConversion.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { InstrumentationError } = require('@rudderstack/integrations-lib');
const { InstrumentationError, ConfigurationError } = require('@rudderstack/integrations-lib');
const {
defaultRequestConfig,
simpleProcessRouterDest,
Expand Down Expand Up @@ -28,7 +28,12 @@ const responseBuilder = (payload) => {
return response;
};

const validateInput = (message) => {
const validateInputAndConfig = (message, destination) => {
const { Config } = destination;
if (!Config.trackerId) {
throw new ConfigurationError('Tracking Tag ID is not present. Aborting');
}

if (!message.type) {
throw new InstrumentationError('Event type is required');

Check warning on line 38 in src/cdk/v2/destinations/the_trade_desk/transformConversion.js

View check run for this annotation

Codecov / codecov/patch

src/cdk/v2/destinations/the_trade_desk/transformConversion.js#L38

Added line #L38 was not covered by tests
}
Expand Down Expand Up @@ -76,7 +81,7 @@ const trackResponseBuilder = (message, destination) => {
};

const processEvent = (message, destination) => {
validateInput(message);
validateInputAndConfig(message, destination);
return trackResponseBuilder(message, destination);
};

Expand Down
24 changes: 15 additions & 9 deletions src/cdk/v2/destinations/the_trade_desk/transformRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ const tradeDeskConfig = require('./config');

const { DATA_PROVIDER_ID } = tradeDeskConfig;

const validateConfig = (config) => {
if (!config.advertiserSecretKey) {
throw new ConfigurationError('Advertiser Secret Key is not present. Aborting');
}

if (config.ttlInDays && !(config.ttlInDays >= 0 && config.ttlInDays <= 180)) {
throw new ConfigurationError('TTL is out of range. Allowed values are 0 to 180 days');
}

if (!config.audienceId) {
throw new ConfigurationError('Segment name/Audience ID is not present. Aborting');
}
};

const responseBuilder = (items, config) => {
const { advertiserId, dataServer } = config;

Expand Down Expand Up @@ -50,15 +64,7 @@ const processRecordInputs = (inputs, destination) => {
return [];
}

if (!Config.audienceId) {
const segmentNameError = new ConfigurationError(
'Segment name/Audience ID is not present. Aborting',
);
const errorResponses = inputs.map((input) =>
handleRtTfSingleEventError(input, segmentNameError, {}),
);
return errorResponses;
}
validateConfig(Config);

const invalidActionTypeError = new InstrumentationError(
'Invalid action type. You can only add or remove IDs from the audience/segment',
Expand Down
159 changes: 141 additions & 18 deletions test/integrations/destinations/the_trade_desk/router/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,22 +358,10 @@ export const data = [
output: [
{
batched: false,
metadata: [{ jobId: 1, userId: 'u1' }],
statusCode: 400,
error: 'Segment name/Audience ID is not present. Aborting',
statTags: {
destType: destTypeInUpperCase,
implementation: 'cdkV2',
feature: 'router',
module: 'destination',
errorCategory: 'dataValidation',
errorType: 'configuration',
},
destination: overrideDestination(sampleDestination, { audienceId: '' }),
},
{
batched: false,
metadata: [{ jobId: 2, userId: 'u1' }],
metadata: [
{ jobId: 1, userId: 'u1' },
{ jobId: 2, userId: 'u1' },
],
statusCode: 400,
error: 'Segment name/Audience ID is not present. Aborting',
statTags: {
Expand All @@ -384,7 +372,6 @@ export const data = [
errorCategory: 'dataValidation',
errorType: 'configuration',
},
destination: overrideDestination(sampleDestination, { audienceId: '' }),
},
],
},
Expand Down Expand Up @@ -419,6 +406,24 @@ export const data = [
userId: 'u1',
},
},
{
message: {
type: 'record',
action: 'insert',
fields: {
DAID: 'test-daid-2',
UID2: 'test-uid2-2',
},
channel: 'sources',
context: sampleContext,
recordId: '1',
},
destination: overrideDestination(sampleDestination, { advertiserId: '' }),
metadata: {
jobId: 2,
userId: 'u1',
},
},
],
destType,
},
Expand All @@ -432,7 +437,10 @@ export const data = [
output: [
{
batched: false,
metadata: [{ jobId: 1, userId: 'u1' }],
metadata: [
{ jobId: 1, userId: 'u1' },
{ jobId: 2, userId: 'u1' },
],
statusCode: 400,
error: 'Advertiser ID is not present. Aborting',
statTags: {
Expand Down Expand Up @@ -1809,4 +1817,119 @@ export const data = [
},
},
},
{
name: destType,
description: 'Tracker id is not present',
feature: 'router',
module: 'destination',
version: 'v0',
input: {
request: {
body: {
input: [
{
message: {
type: 'record',
action: 'insert',
fields: {
DAID: 'test-daid-1',
},
channel: 'sources',
context: sampleContext,
recordId: '1',
},
destination: overrideDestination(sampleDestination, { trackerId: '' }),
metadata: {
jobId: 1,
},
},
{
message: {
type: 'track',
event: 'custom event abc',
properties: {
key1: 'value1',
value: 25,
product_id: 'prd123',
key2: true,
test: 'test123',
},
},
destination: overrideDestination(sampleDestination, { trackerId: '' }),
metadata: {
jobId: 2,
},
},
],
destType,
},
method: 'POST',
},
},
output: {
response: {
status: 200,
body: {
output: [
{
batchedRequest: [
{
version: '1',
type: 'REST',
method: 'POST',
endpoint: 'https://sin-data.adsrvr.org/data/advertiser',
headers: {},
params: {},
body: {
JSON: {
DataProviderId: dataProviderId,
AdvertiserId: advertiserId,
Items: [
{
DAID: 'test-daid-1',
Data: [
{
Name: segmentName,
TTLInMinutes: 43200,
},
],
},
],
},
JSON_ARRAY: {},
XML: {},
FORM: {},
},
files: {},
},
],
metadata: [
{
jobId: 1,
},
],
batched: true,
statusCode: 200,
destination: overrideDestination(sampleDestination, { trackerId: '' }),
},
{
batched: false,
metadata: [{ jobId: 2 }],
statusCode: 400,
error: 'Tracking Tag ID is not present. Aborting',
statTags: {
errorCategory: 'dataValidation',
errorType: 'configuration',
destType: 'THE_TRADE_DESK',
module: 'destination',
implementation: 'cdkV2',
feature: 'router',
},
destination: overrideDestination(sampleDestination, { trackerId: '' }),
},
],
},
},
},
},
];

0 comments on commit 649df83

Please sign in to comment.