Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: trade desk proxy testcases #3175

Merged
merged 5 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
Gauravudia marked this conversation as resolved.
Show resolved Hide resolved
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[] = [
Gauravudia marked this conversation as resolved.
Show resolved Hide resolved
{
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;
});
};
Loading