Skip to content

Commit

Permalink
chore: router test cases added
Browse files Browse the repository at this point in the history
  • Loading branch information
aanshi07 committed Oct 21, 2024
1 parent e7adf45 commit 44496ab
Show file tree
Hide file tree
Showing 3 changed files with 200 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/v0/destinations/tune/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,11 @@ const responseBuilder = (message, { Config }) => {

const processEvent = (message, destination) => {
// Validate message type
if (!isDefinedAndNotNull(message.type)) {
throw new InstrumentationError('Message Type is not present. Aborting message.', 400);
if (!isDefinedAndNotNull(message.type) || typeof message.type !== 'string') {
throw new InstrumentationError(
'Message Type is not present or is not a string. Aborting message.',
400,
);
}
const messageType = message.type.toLowerCase();

Expand All @@ -82,8 +85,6 @@ const processRouterDest = async (inputs, reqMetadata) => {
};

module.exports = {
responseBuilder,
processEvent,
process,
processRouterDest,
};
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ const destination: Destination = {
{ to: 'status', from: 'status' },
{ to: 'transaction_id', from: 'mytransactionId' },
],
advSubIdMapping: [{ from: 'context.ip', to: 'adv_sub2' }],
advUniqueIdMapping: [],
advSubIdMapping: [{ from: 'context.traits.ip', to: 'adv_sub2' }],
advUniqueIdMapping: [{ from: 'context.traits.customProperty1', to: 'adv_unique1' }],
},
],
},
Expand Down Expand Up @@ -71,6 +71,7 @@ export const trackTestdata: ProcessorTestData[] = [
customProperty1: 'customValue',
firstName: 'David',
logins: 2,
ip: '0.0.0.0',
},
},
anonymousId: 'david_bowie_anonId',
Expand All @@ -94,6 +95,8 @@ export const trackTestdata: ProcessorTestData[] = [
params: {
security_token: '1123',
transaction_id: 'test-123',
adv_sub2: '0.0.0.0',
adv_unique1: 'customValue',
},
userId: '',
JSON: {},
Expand Down
190 changes: 190 additions & 0 deletions test/integrations/destinations/tune/router/data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
import { Destination } from '../../../../../src/types';
import { RouterTestData } from '../../../testTypes';
import { generateMetadata } from '../../../testUtils';

const destination: Destination = {
ID: '123',
Name: 'tune',
DestinationDefinition: {
ID: '123',
Name: 'tune',
DisplayName: 'tune',
Config: {},
},
Config: {
connectionMode: {
web: 'cloud',
},
consentManagement: {},
oneTrustCookieCategories: {},
ketchConsentPurposes: {},
tuneEvents: [
{
url: 'https://demo.go2cloud.org/aff_l?offer_id=45&aff_id=1029',
eventName: 'Product added',
standardMapping: [
{ to: 'aff_id', from: 'affId' },
{ to: 'promo_code', from: 'promoCode' },
{ to: 'security_token', from: 'securityToken' },
{ to: 'status', from: 'status' },
{ to: 'transaction_id', from: 'mytransactionId' },
],
advSubIdMapping: [{ from: 'context.ip', to: 'adv_sub2' }],
advUniqueIdMapping: [{ from: 'context.traits.anonymousId', to: 'adv_unique1' }],
},
],
},
Enabled: true,
WorkspaceID: '123',
Transformations: [],
};

export const data: RouterTestData[] = [
{
id: 'tune-router-test-1',
name: 'tune',
description: 'Basic Router Test for track call with standard properties mapping.',
scenario: 'Business',
successCriteria:
'The response should have a status code of 200, and the output should correctly map the properties.',
feature: 'router',
module: 'destination',
version: 'v0',
input: {
request: {
body: {
input: [
{
destination,
metadata: generateMetadata(1),
message: {
type: 'track',
event: 'Product added',
anonymousId: 'sampath',
channel: 'web',
context: {
app: {
name: 'RudderLabs JavaScript SDK',
version: '1.0.0',
},
ip: '0.0.0.0',
traits: { anonymousId: 'sampath', email: '[email protected]' },
},
integrations: { All: true },
properties: {
securityToken: '1123',
mytransactionId: 'test-123',
},
},
},
],
destType: 'tune',
},
},
},
output: {
response: {
status: 200,
body: {
output: [
{
batchedRequest: {
version: '1',
type: 'REST',
method: 'POST',
endpoint: 'https://demo.go2cloud.org/aff_l?offer_id=45&aff_id=1029',
headers: {},
params: {
security_token: '1123',
transaction_id: 'test-123',
adv_sub2: '0.0.0.0',
adv_unique1: 'sampath',
},
body: {
JSON: {},
JSON_ARRAY: {},
XML: {},
FORM: {},
},
files: {},
},
metadata: [generateMetadata(1)],
batched: false,
statusCode: 200,
destination,
},
],
},
},
},
},
{
id: 'tune-router-test-2',
name: 'tune',
description: 'Basic Router Test with incorrect message type ',
scenario: 'Business',
successCriteria:
'The response should return a 400 status code due to an invalid message type, with an appropriate error message indicating that the message type is not present or is not a string.',
feature: 'router',
module: 'destination',
version: 'v0',
input: {
request: {
body: {
input: [
{
destination,
metadata: generateMetadata(1),
message: {
type: 123,
event: 'Product added',
anonymousId: 'sampath',
channel: 'web',
context: {
app: {
name: 'RudderLabs JavaScript SDK',
version: '1.0.0',
},
ip: '0.0.0.0',
traits: { anonymousId: 'sampath', email: '[email protected]' },
},
integrations: { All: true },
properties: {
securityToken: '1123',
mytransactionId: 'test-123',
},
},
},
],
destType: 'tune',
},
},
},
output: {
response: {
status: 200,
body: {
output: [
{
error: 'Message Type is not present or is not a string. Aborting message.',
statTags: {
destType: 'TUNE',
destinationId: 'default-destinationId',
errorCategory: 'dataValidation',
errorType: 'instrumentation',
feature: 'router',
implementation: 'native',
module: 'destination',
workspaceId: 'default-workspaceId',
},
metadata: [generateMetadata(1)],
batched: false,
statusCode: 400,
destination,
},
],
},
},
},
},
];

0 comments on commit 44496ab

Please sign in to comment.