Skip to content

Commit

Permalink
test: added testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauravudia committed Jan 2, 2024
1 parent aac70cc commit 3a6a0ff
Show file tree
Hide file tree
Showing 5 changed files with 581 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/cdk/v2/destinations/the_trade_desk/rtWorkflow.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
bindings:
- name: processRouterDest
path: ./util
path: ./utils

steps:
- name: validateInput
template: |
$.assert(Array.isArray(^) && ^.length > 0, "Invalid event array")
const config = ^[0].destination.Config
$.assertConfig(config.audienceId, "Segment name is not present. Aborting")
$.assertConfig(config.advertiserId, "Advertiser ID is not present. Aborting")
$.assertConfig(config.advertiserSecretKey, "Advertiser Secret Key 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: processRouterDest
template: |
Expand Down
4 changes: 2 additions & 2 deletions src/cdk/v2/destinations/the_trade_desk/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ const getSignatureHeader = (request, secretKey) => {
};

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

const payload = { DataProviderId: DATA_PROVIDER_ID, AdvertiserId: advertiserID, Items: items };
const payload = { DataProviderId: DATA_PROVIDER_ID, AdvertiserId: advertiserId, Items: items };

const response = defaultRequestConfig();
response.endpoint = getFirstPartyEndpoint(dataServer);
Expand Down
8 changes: 8 additions & 0 deletions src/v0/destinations/the_trade_desk/networkHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ const { JSON_MIME_TYPE } = require('../../util/constant');
const proxyRequest = async (request) => {
const { endpoint, data, method, params, headers, config } = prepareProxyRequest(request);

Check warning on line 13 in src/v0/destinations/the_trade_desk/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/the_trade_desk/networkHandler.js#L13

Added line #L13 was not covered by tests

if (!config?.advertiserSecretKey) {
throw new AbortedError('Advertiser secret key is missing. Aborting');

Check warning on line 16 in src/v0/destinations/the_trade_desk/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/the_trade_desk/networkHandler.js#L16

Added line #L16 was not covered by tests
}

if (!process.env.THE_TRADE_DESK_DATA_PROVIDER_SECRET_KEY) {
throw new AbortedError('Data provider secret key is missing. Aborting');

Check warning on line 20 in src/v0/destinations/the_trade_desk/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/the_trade_desk/networkHandler.js#L20

Added line #L20 was not covered by tests
}

const ProxyHeaders = {

Check warning on line 23 in src/v0/destinations/the_trade_desk/networkHandler.js

View check run for this annotation

Codecov / codecov/patch

src/v0/destinations/the_trade_desk/networkHandler.js#L23

Added line #L23 was not covered by tests
...headers,
TtdSignature: getSignatureHeader(data, config.advertiserSecretKey),
Expand Down
44 changes: 44 additions & 0 deletions test/integrations/destinations/the_trade_desk/common.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
const destType = 'the_trade_desk';
const destTypeInUpperCase = 'THE_TRADE_DESK';
const advertiserId = 'test-advertiser-id';
const dataProviderId = 'rudderstack';
const segmentName = 'test-segment';
const sampleDestination = {
Config: {
advertiserId,
advertiserSecretKey: 'test-advertiser-secret-key',
dataServer: 'apac',
ttlInDays: 30,
audienceId: segmentName,
},
DestinationDefinition: { Config: { cdkV2Enabled: true } },
};

const sampleSource = {
job_id: 'test-job-id',
job_run_id: 'test-job-run-id',
task_run_id: 'test-task-run-id',
version: 'v1.40.4',
};

const sampleContext = {
destinationFields: 'daid, uid2',
externalId: [
{
identifierType: 'tdid',
type: 'THE_TRADE_DESK-test-segment',
},
],
mappedToDestination: 'true',
sources: sampleSource,
};

export {
destType,
destTypeInUpperCase,
advertiserId,
dataProviderId,
segmentName,
sampleDestination,
sampleContext,
};
Loading

0 comments on commit 3a6a0ff

Please sign in to comment.