Skip to content

Commit

Permalink
chore: added test cases for processor
Browse files Browse the repository at this point in the history
  • Loading branch information
anantjain45823 committed Feb 21, 2024
1 parent bf506ea commit ee1b055
Show file tree
Hide file tree
Showing 15 changed files with 809 additions and 21 deletions.
12 changes: 12 additions & 0 deletions src/cdk/v2/destinations/ninetailed/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@ const ConfigCategories = {
type: 'context',
name: 'contextMapping',
},
TRACK: {
type: 'track',
name: 'trackMapping',
},
IDENTIFY: {
type: 'identify',
name: 'identifyMapping',
},
PAGE: {
type: 'page',
name: 'pageMapping',
},
};
const MAX_BATCH_SIZE = 200; // Maximum number of events to send in a single batch
const mappingConfig = getMappingConfig(ConfigCategories, __dirname);
Expand Down
18 changes: 4 additions & 14 deletions src/cdk/v2/destinations/ninetailed/data/generalPayloadMapping.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,12 @@
"required": true,
"destKey": "channel"
},
{
"sourceKeys": "properties",
"destKey": "properties"
},
{
"sourceKeys": "traits",
"sourceFromGenericMap": true,
"destKey": "traits"
},
{
"sourceKeys": "userIdOnly",
"sourceFromGenericMap": true,
"destKey": "userId"
},
{
"sourceKeys": "type",
"destKey": "type"
},
{
"sourceKeys": "originalTimestamp",
"destKey": "originalTimestamp"
}
]
14 changes: 14 additions & 0 deletions src/cdk/v2/destinations/ninetailed/data/identifyMapping.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[
{
"sourceKeys": "traits",
"sourceFromGenericMap": true,
"required": true,
"destKey": "traits"
},
{
"sourceKeys": "userIdOnly",
"sourceFromGenericMap": true,
"required": true,
"destKey": "userId"
}
]
7 changes: 7 additions & 0 deletions src/cdk/v2/destinations/ninetailed/data/pageMapping.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[
{
"sourceKeys": "properties",
"required": true,
"destKey": "properties"
}
]
12 changes: 12 additions & 0 deletions src/cdk/v2/destinations/ninetailed/data/trackMapping.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[
{
"sourceKeys": "properties",
"required": true,
"destKey": "properties"
},
{
"sourceKeys": "event",
"required": true,
"destKey": "event"
}
]
2 changes: 1 addition & 1 deletion src/cdk/v2/destinations/ninetailed/procWorkflow.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ steps:
template: |
let messageType = $.outputs.messageType;
$.assert(messageType, "message Type is not present. Aborting");
$.assert(messageType in {{$.EventType.([.TRACK,.IDENITFY,.PAGE])}}, "message type " + messageType + " is not supported");
$.assert(messageType in {{$.EventType.([.TRACK,.IDENTIFY,.PAGE])}}, "message type " + messageType + " is not supported");
$.assertConfig(.destination.Config.organisationId, "Organisation ID is not present. Aborting");
$.assertConfig(.destination.Config.environment, "Environment is not present. Aborting");
- name: preparePayload
Expand Down
28 changes: 23 additions & 5 deletions src/cdk/v2/destinations/ninetailed/utils.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { mappingConfig, ConfigCategories } = require('./config');
const { mappingConfig, ConfigCategories, batchEndpoint } = require('./config');
const { constructPayload } = require('../../../../v0/util');

/**
Expand All @@ -9,9 +9,27 @@ const { constructPayload } = require('../../../../v0/util');
*/
const constructFullPayload = (message) => {
const context = constructPayload(message, mappingConfig[ConfigCategories.CONTEXT.name]);
const payload = constructPayload(message, mappingConfig[ConfigCategories.GENERAL.name]);
payload.context = context;
return payload;
let payload = constructPayload(message, mappingConfig[ConfigCategories.GENERAL.name]);
let typeSpecifcPayload;
switch (message.type) {
case 'track':
typeSpecifcPayload = constructPayload(message, mappingConfig[ConfigCategories.TRACK.name]);
break;
case 'identify':
typeSpecifcPayload = constructPayload(message, mappingConfig[ConfigCategories.IDENTIFY.name]);
break;
case 'page':
typeSpecifcPayload = constructPayload(message, mappingConfig[ConfigCategories.PAGE.name]);
break;
default:
break;
}
payload = { ...payload, ...context };
return { ...payload, ...typeSpecifcPayload }; // merge base and type-specific payloads;
};

module.exports = { constructFullPayload };
const getEndpoint = (organisationId, environment) => batchEndpoint
.replace('{{organisationId}}', organisationId)
.replace('{{environment}}', environment);

module.exports = { constructFullPayload, getEndpoint };
3 changes: 2 additions & 1 deletion src/features.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
"TIKTOK_AUDIENCE": true,
"REDDIT": true,
"THE_TRADE_DESK": true,
"INTERCOM": true
"INTERCOM": true,
"NINETAILED": true
},
"regulations": [
"BRAZE",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export const destination = {
ID: 'random_id',
Name: 'ninetailed',
DestinationDefinition: {
Config: {
cdkV2Enabled: true,
},
},
Config: {
organisationId: 'dummyOrganisationId',
environment: 'main',
},
};

export const metadata = {
destinationId: 'dummyDestId',
};
// export const endpoint = 'https://track.linksynergy.com/ep';
export const commonOutputHeaders = {
accept: 'application/json',
'content-type': 'application/json',
};
export const commonProperties = {
segment: 'SampleSegment',
shipcountry: 'USA',
shipped: '20240129_1500',
sitename: 'SampleSiteName',
storeId: '12345',
storecat: 'Electronics',
};
export const traits = {
email: '[email protected]',
firstname: 'John',
lastname: 'Doe',
phone: '+1(123)456-7890',
gender: 'Male',
birthday: '1980-01-02',
city: 'San Francisco',
};
5 changes: 5 additions & 0 deletions test/integrations/destinations/ninetailed/processor/data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { validationFailures } from './validation';
import { track } from './track';
import { page } from './page';
import { identify } from './identify';
export const data = [...identify, ...page, ...track, ...validationFailures];
160 changes: 160 additions & 0 deletions test/integrations/destinations/ninetailed/processor/identify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import { destination, traits, context, metadata } from './commonConfig';
import { transformResultBuilder } from '../../../testUtils';
export const identify = [
{
id: 'ninetailed-test-identify-success-1',
name: 'ninetailed',
description: 'identify call with all mappings available',
scenario: 'Framework+Buisness',
successCriteria: 'Response should contain all the mappings and status code should be 200',
feature: 'processor',
module: 'destination',
version: 'v0',
input: {
request: {
body: [
{
destination,
message: {

type: 'identify',
context,
userId: 'sajal12',
channel: 'mobile',
messageId: '1611588776408-ee5a3212-fbf9-4cbb-bbad-3ed0f7c6a2ce',
traits: traits,
anonymousId: '9c6bd77ea9da3e68',
integrations: {
All: true,
},
originalTimestamp: '2021-01-25T15:32:56.409Z',
},
metadata,
},
],
},
},
output: {
response: {
status: 200,
body: [
{
metadata: {
destinationId: 'dummyDestId',
},
output: transformResultBuilder({
method: 'POST',
JSON: {
context: {
app: {
name: 'RudderLabs JavaScript SDK',
version: '1.0.0',
},
campaign: {
name: 'campign_123',
source: 'social marketing',
medium: 'facebook',
term: '1 year',
},
library: {
name: 'RudderstackSDK',
version: 'Ruddderstack SDK version',
},
locale: 'en-US',
page: {
path: '/signup',
referrer: 'https://rudderstack.medium.com/',
search: '?type=freetrial',
url: 'https://app.rudderstack.com/signup?type=freetrial',
},
userAgent:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36',
location: {
coordinates: {
latitude: 40.7128,
longitude: -74.006,
},
city: 'San Francisco',
postalCode: '94107',
region: 'CA',
regionCode: 'CA',
country: ' United States',
countryCode: 'United States of America',
continent: 'North America',
timezone: 'America/Los_Angeles',
},
},
type: 'identify',
channel: 'mobile',
userId: 'sajal12',
messageId: '1611588776408-ee5a3212-fbf9-4cbb-bbad-3ed0f7c6a2ce',
traits: traits,
anonymousId: '9c6bd77ea9da3e68',
originalTimestamp: '2021-01-25T15:32:56.409Z',
},
userId: '',
}),
statusCode: 200,
},
],
},
},
},
{
id: 'ninetailed-test-identify-failure-1',
name: 'ninetailed',
description: 'identify call with no userId available',
scenario: 'Framework',
successCriteria:
'Error should be thrown for required field userId not present and status code should be 200',
feature: 'processor',
module: 'destination',
version: 'v0',
input: {
request: {
body: [
{
destination,
message: {
context,
type: 'identify',
channel: 'mobile',
messageId: '1611588776408-ee5a3212-fbf9-4cbb-bbad-3ed0f7c6a2ce',
traits: traits,
anonymousId: '9c6bd77ea9da3e68',
integrations: {
All: true,
},
originalTimestamp: '2021-01-25T15:32:56.409Z',
},
metadata,
},
],
},
},
output: {
response: {
status: 200,
body: [
{
error:
'Missing required value from "userIdOnly": Workflow: procWorkflow, Step: preparePayload, ChildStep: undefined, OriginalError: Missing required value from "userIdOnly"',
metadata: {
destinationId: 'dummyDestId',
},
statTags: {
destType: 'NINETAILED',
destinationId: 'dummyDestId',
errorCategory: 'dataValidation',
errorType: 'instrumentation',
feature: 'processor',
implementation: 'cdkV2',
module: 'destination',
},
statusCode: 400,
},
],
},
},
},
];
Loading

0 comments on commit ee1b055

Please sign in to comment.