From 44496ab16b1ed5913d3e1c3a813317e5c8b77141 Mon Sep 17 00:00:00 2001 From: Aanshi Lahoti Date: Mon, 21 Oct 2024 18:34:05 +0530 Subject: [PATCH] chore: router test cases added --- src/v0/destinations/tune/transform.js | 9 +- .../tune/processor/trackTestData.ts | 7 +- .../destinations/tune/router/data.ts | 190 ++++++++++++++++++ 3 files changed, 200 insertions(+), 6 deletions(-) create mode 100644 test/integrations/destinations/tune/router/data.ts diff --git a/src/v0/destinations/tune/transform.js b/src/v0/destinations/tune/transform.js index e26ba8dadc..f7725a76e5 100644 --- a/src/v0/destinations/tune/transform.js +++ b/src/v0/destinations/tune/transform.js @@ -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(); @@ -82,8 +85,6 @@ const processRouterDest = async (inputs, reqMetadata) => { }; module.exports = { - responseBuilder, - processEvent, process, processRouterDest, }; diff --git a/test/integrations/destinations/tune/processor/trackTestData.ts b/test/integrations/destinations/tune/processor/trackTestData.ts index 4b79e248d0..c19ffdd84c 100644 --- a/test/integrations/destinations/tune/processor/trackTestData.ts +++ b/test/integrations/destinations/tune/processor/trackTestData.ts @@ -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' }], }, ], }, @@ -71,6 +71,7 @@ export const trackTestdata: ProcessorTestData[] = [ customProperty1: 'customValue', firstName: 'David', logins: 2, + ip: '0.0.0.0', }, }, anonymousId: 'david_bowie_anonId', @@ -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: {}, diff --git a/test/integrations/destinations/tune/router/data.ts b/test/integrations/destinations/tune/router/data.ts new file mode 100644 index 0000000000..65bfee4ade --- /dev/null +++ b/test/integrations/destinations/tune/router/data.ts @@ -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: 'sampath@gmail.com' }, + }, + 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: 'sampath@gmail.com' }, + }, + 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, + }, + ], + }, + }, + }, + }, +];