Skip to content

Commit

Permalink
fix: handle trade desk null, undefined fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauravudia committed Aug 14, 2024
1 parent 5bae268 commit 5b79684
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 5 deletions.
13 changes: 9 additions & 4 deletions src/cdk/v2/destinations/the_trade_desk/transformRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ const batchResponseBuilder = (items, config) => {
return response;
};

const checkNullUndefinedEmptyFields = (fields) =>
!!Object.entries(fields).some(([, value]) => !value);

const processRecordInputs = (inputs, destination) => {
const { Config } = destination;
const items = [];
Expand Down Expand Up @@ -68,6 +71,11 @@ const processRecordInputs = (inputs, destination) => {
return;
}

if (checkNullUndefinedEmptyFields(fields)) {
errorResponseList.push(handleRtTfSingleEventError(input, emptyFieldsError, {}));
return;
}

successMetadata.push(input.metadata);
const data = [
{
Expand All @@ -78,10 +86,7 @@ const processRecordInputs = (inputs, destination) => {

Object.keys(fields).forEach((id) => {
const value = fields[id];
if (value) {
// adding only non empty ID's
items.push({ [id]: value, Data: data });
}
items.push({ [id]: value, Data: data });
});
});

Expand Down
84 changes: 83 additions & 1 deletion test/integrations/destinations/the_trade_desk/router/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const data = [
action: 'insert',
fields: {
DAID: 'test-daid-2',
UID2: null,
UID2: 'test-uid2-2',
},
channel: 'sources',
context: sampleContext,
Expand Down Expand Up @@ -117,6 +117,35 @@ export const data = [
},
files: {},
},
{
version: '1',
type: 'REST',
method: 'POST',
endpoint: 'https://sin-data.adsrvr.org/data/advertiser',
headers: {},
params: {},
body: {
JSON: {
DataProviderId: dataProviderId,
AdvertiserId: advertiserId,
Items: [
{
UID2: 'test-uid2-2',
Data: [
{
Name: segmentName,
TTLInMinutes: 43200,
},
],
},
],
},
JSON_ARRAY: {},
XML: {},
FORM: {},
},
files: {},
},
],
metadata: [
{
Expand Down Expand Up @@ -727,6 +756,8 @@ export const data = [
action: 'insert',
fields: {
DAID: 'test-daid-1',
UID2: 'test-uid2-1',
EUID: 'test-euid-1',
},
channel: 'sources',
context: sampleContext,
Expand All @@ -737,6 +768,24 @@ export const data = [
jobId: 2,
},
},
{
message: {
type: 'record',
action: 'insert',
fields: {
DAID: 'test-daid-2',
UID2: null,
EUID: null,
},
channel: 'sources',
context: sampleContext,
recordId: '3',
},
destination: sampleDestination,
metadata: {
jobId: 3,
},
},
],
destType,
},
Expand Down Expand Up @@ -771,6 +820,24 @@ export const data = [
},
],
},
{
UID2: 'test-uid2-1',
Data: [
{
Name: segmentName,
TTLInMinutes: 43200,
},
],
},
{
EUID: 'test-euid-1',
Data: [
{
Name: segmentName,
TTLInMinutes: 43200,
},
],
},
],
},
JSON_ARRAY: {},
Expand Down Expand Up @@ -804,6 +871,21 @@ export const data = [
},
destination: sampleDestination,
},
{
batched: false,
metadata: [{ jobId: 3 }],
statusCode: 400,
error: '`fields` cannot be empty',
statTags: {
destType: destTypeInUpperCase,
implementation: 'cdkV2',
feature: 'router',
module: 'destination',
errorCategory: 'dataValidation',
errorType: 'instrumentation',
},
destination: sampleDestination,
},
],
},
},
Expand Down

0 comments on commit 5b79684

Please sign in to comment.