Skip to content

Commit

Permalink
refactor: trade desk proxy testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauravudia committed Mar 10, 2024
1 parent a5d20ad commit 6fdf273
Show file tree
Hide file tree
Showing 4 changed files with 280 additions and 2 deletions.
20 changes: 18 additions & 2 deletions test/integrations/destinations/the_trade_desk/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ const destTypeInUpperCase = 'THE_TRADE_DESK';
const advertiserId = 'test-advertiser-id';
const dataProviderId = 'rudderstack';
const segmentName = 'test-segment';

const trackerId = 'test-trackerId';
const firstPartyDataEndpoint = 'https://sin-data.adsrvr.org/data/advertiser';

const sampleDestination: Destination = {
Config: {
Expand Down Expand Up @@ -48,6 +47,20 @@ const sampleContext = {
sources: sampleSource,
};

const proxyV1NetworkErrorStatTags = {
destType: destTypeInUpperCase,
destinationId: 'default-destinationId',
errorCategory: 'network',
errorType: 'aborted',
feature: 'dataDelivery',
implementation: 'native',
module: 'destination',
workspaceId: 'default-workspaceId',
};

const { errorType: _, ...proxyV1PlatformErrorStatTags } = proxyV1NetworkErrorStatTags;
proxyV1PlatformErrorStatTags.errorCategory = 'platform';

export {
destType,
destTypeInUpperCase,
Expand All @@ -56,4 +69,7 @@ export {
segmentName,
sampleDestination,
sampleContext,
proxyV1NetworkErrorStatTags,
proxyV1PlatformErrorStatTags,
firstPartyDataEndpoint,
};
175 changes: 175 additions & 0 deletions test/integrations/destinations/the_trade_desk/delivery/business.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
import { ProxyV1TestData } from '../../../testTypes';
import { generateProxyV1Payload, generateMetadata } from '../../../testUtils';
import {
destType,
advertiserId,
dataProviderId,
segmentName,
sampleDestination,
proxyV1NetworkErrorStatTags,
firstPartyDataEndpoint,
} from '../common';

const validRequestPayload1 = {
AdvertiserId: advertiserId,
DataProviderId: dataProviderId,
Items: [
{
DAID: 'test-daid-1',
Data: [
{
Name: segmentName,
TTLInMinutes: 43200,
},
],
},
{
Data: [
{
Name: segmentName,
TTLInMinutes: 43200,
},
],
UID2: 'test-uid2-1',
},
{
DAID: 'test-daid-2',
Data: [
{
Name: segmentName,
TTLInMinutes: 0,
},
],
},
{
Data: [
{
Name: segmentName,
TTLInMinutes: 0,
},
],
UID2: 'test-uid2-2',
},
],
};

const invalidRequestPayload1 = {
AdvertiserId: advertiserId,
DataProviderId: dataProviderId,
Items: [
{
DAID: 'test-daid',
Data: [
{
Name: segmentName,
TTLInMinutes: 43200,
},
],
},
{
Data: [
{
Name: segmentName,
TTLInMinutes: 43200,
},
],
UID2: 'test-invalid-uid2',
},
],
};

const metadataArray = [generateMetadata(1)];

export const businessProxyV1: ProxyV1TestData[] = [
{
id: 'ttd_v1_scenario_1',
name: destType,
description:
'[Proxy v1 API] :: Test for a valid request - Successful delivery of Add/Remove IDs to Trade Desk',
successCriteria: 'Should return 200 with no error with destination response',
scenario: 'Business',
feature: 'dataDelivery',
module: 'destination',
version: 'v1',
input: {
request: {
body: generateProxyV1Payload(
{
headers: {},
params: {},
JSON: validRequestPayload1,
endpoint: firstPartyDataEndpoint,
},
metadataArray,
sampleDestination.Config,
),
method: 'POST',
},
},
output: {
response: {
status: 200,
body: {
output: {
status: 200,
message: 'Request Processed Successfully',
response: [
{
statusCode: 200,
metadata: generateMetadata(1),
error: '{}',
},
],
},
},
},
},
},
{
id: 'ttd_v1_scenario_2',
name: destType,
description:
'[Proxy v1 API] :: Test for invalid ID - where the destination responds with 200 with invalid ID',
successCriteria: 'Should return 400 with error with destination response',
scenario: 'Business',
feature: 'dataDelivery',
module: 'destination',
version: 'v1',
input: {
request: {
body: generateProxyV1Payload(
{
headers: {},
params: {},
JSON: invalidRequestPayload1,
endpoint: firstPartyDataEndpoint,
},
metadataArray,
sampleDestination.Config,
),
method: 'POST',
},
},
output: {
response: {
status: 200,
body: {
output: {
message:
'Request failed with status: 200 due to {"FailedLines":[{"ErrorCode":"MissingUserId","Message":"Invalid UID2, item #2"}]}',
response: [
{
error:
'{"FailedLines":[{"ErrorCode":"MissingUserId","Message":"Invalid UID2, item #2"}]}',
metadata: generateMetadata(1),
statusCode: 400,
},
],
statTags: proxyV1NetworkErrorStatTags,
status: 400,
},
},
},
},
},
];
78 changes: 78 additions & 0 deletions test/integrations/destinations/the_trade_desk/delivery/other.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { ProxyV1TestData } from '../../../testTypes';
import { generateProxyV1Payload, generateMetadata } from '../../../testUtils';
import {
destType,
advertiserId,
dataProviderId,
segmentName,
proxyV1PlatformErrorStatTags,
firstPartyDataEndpoint,
} from '../common';
import { envMock } from '../mocks';

envMock();

const validRequestPayload1 = {
AdvertiserId: advertiserId,
DataProviderId: dataProviderId,
Items: [
{
DAID: 'test-daid-1',
Data: [
{
Name: segmentName,
TTLInMinutes: 43200,
},
],
},
],
};

const metadataArray = [generateMetadata(1)];

export const otherProxyV1: ProxyV1TestData[] = [
{
id: 'ttd_v1_scenario_1',
name: destType,
description:
'[Proxy v1 API] :: Missing advertiser secret key in destination config from proxy request from server',
successCriteria: 'Should return 400 with platform error',
scenario: 'Framework',
feature: 'dataDelivery',
module: 'destination',
version: 'v1',
input: {
request: {
body: generateProxyV1Payload(
{
headers: {},
params: {},
JSON: validRequestPayload1,
endpoint: firstPartyDataEndpoint,
},
metadataArray,
),
method: 'POST',
},
},
output: {
response: {
status: 200,
body: {
output: {
message: 'Advertiser secret key is missing in destination config. Aborting',
response: [
{
error: 'Advertiser secret key is missing in destination config. Aborting',
metadata: generateMetadata(1),
statusCode: 400,
},
],
statTags: proxyV1PlatformErrorStatTags,
status: 400,
},
},
},
},
},
];
9 changes: 9 additions & 0 deletions test/integrations/destinations/the_trade_desk/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,12 @@ import config from '../../../../src/cdk/v2/destinations/the_trade_desk/config';
export const defaultMockFns = () => {
jest.replaceProperty(config, 'MAX_REQUEST_SIZE_IN_BYTES', 250);
};

export const envMock = () => {
process.env.THE_TRADE_DESK_DATA_PROVIDER_SECRET_KEY = 'mockedDataProviderSecretKey';

// Clean up after all tests are done
afterAll(() => {
delete process.env.THE_TRADE_DESK_DATA_PROVIDER_SECRET_KEY;
});
};

0 comments on commit 6fdf273

Please sign in to comment.