From 265a71d20b484205245c20dd3e47d108dc2fd16f Mon Sep 17 00:00:00 2001 From: Anant Jain <62471433+anantjain45823@users.noreply.github.com> Date: Mon, 13 May 2024 12:44:40 +0530 Subject: [PATCH] fix: ninetailed: modify parameter requirements and add default values (#3364) * fix: ninetailed: modify parameter requirements and add default values * chore: add default value for userId --- src/cdk/v2/destinations/ninetailed/config.js | 1 - .../ninetailed/data/contextMapping.json | 13 ++-- .../data/generalPayloadMapping.json | 4 +- .../ninetailed/data/identifyMapping.json | 5 +- .../ninetailed/data/trackMapping.json | 4 +- .../destinations/ninetailed/procWorkflow.yaml | 1 - src/cdk/v2/destinations/ninetailed/utils.js | 1 + .../destinations/ninetailed/commonConfig.ts | 3 +- .../ninetailed/processor/identify.ts | 64 +++++++++++++++---- .../destinations/ninetailed/router/data.ts | 23 +++++-- 10 files changed, 87 insertions(+), 32 deletions(-) diff --git a/src/cdk/v2/destinations/ninetailed/config.js b/src/cdk/v2/destinations/ninetailed/config.js index a59b2a1671..efb1a8908e 100644 --- a/src/cdk/v2/destinations/ninetailed/config.js +++ b/src/cdk/v2/destinations/ninetailed/config.js @@ -19,7 +19,6 @@ const ConfigCategories = { }, }; -// MAX_BATCH_SIZE : // Maximum number of events to send in a single batch const mappingConfig = getMappingConfig(ConfigCategories, __dirname); const batchEndpoint = 'https://experience.ninetailed.co/v2/organizations/{{organisationId}}/environments/{{environment}}/events'; diff --git a/src/cdk/v2/destinations/ninetailed/data/contextMapping.json b/src/cdk/v2/destinations/ninetailed/data/contextMapping.json index f2373b61c1..ad301c8150 100644 --- a/src/cdk/v2/destinations/ninetailed/data/contextMapping.json +++ b/src/cdk/v2/destinations/ninetailed/data/contextMapping.json @@ -1,12 +1,10 @@ [ { "sourceKeys": "app.name", - "required": true, "destKey": "app.name" }, { "sourceKeys": "app.version", - "required": true, "destKey": "app.version" }, { @@ -15,12 +13,16 @@ }, { "sourceKeys": "library.name", - "required": true, - "destKey": "library.name" + "destKey": "library.name", + "metadata": { + "defaultValue": "Rudderstack Ninetailed Destination" + } }, { "sourceKeys": "library.version", - "required": true, + "metadata": { + "defaultValue": "1" + }, "destKey": "library.version" }, { @@ -37,7 +39,6 @@ }, { "sourceKeys": "location", - "required": false, "metadata": { "defaultValue": {} }, diff --git a/src/cdk/v2/destinations/ninetailed/data/generalPayloadMapping.json b/src/cdk/v2/destinations/ninetailed/data/generalPayloadMapping.json index 3ab72d1b9f..22fc637728 100644 --- a/src/cdk/v2/destinations/ninetailed/data/generalPayloadMapping.json +++ b/src/cdk/v2/destinations/ninetailed/data/generalPayloadMapping.json @@ -11,7 +11,9 @@ }, { "sourceKeys": "channel", - "required": true, + "metadata": { + "defaultValue": "server" + }, "destKey": "channel" }, { diff --git a/src/cdk/v2/destinations/ninetailed/data/identifyMapping.json b/src/cdk/v2/destinations/ninetailed/data/identifyMapping.json index e8d3f7797d..b1a340bd98 100644 --- a/src/cdk/v2/destinations/ninetailed/data/identifyMapping.json +++ b/src/cdk/v2/destinations/ninetailed/data/identifyMapping.json @@ -2,13 +2,14 @@ { "sourceKeys": "traits", "sourceFromGenericMap": true, - "required": true, + "metadata": { + "defaultValue": {} + }, "destKey": "traits" }, { "sourceKeys": "userIdOnly", "sourceFromGenericMap": true, - "required": true, "destKey": "userId" } ] diff --git a/src/cdk/v2/destinations/ninetailed/data/trackMapping.json b/src/cdk/v2/destinations/ninetailed/data/trackMapping.json index 44af6dd1a3..5a13f5bba2 100644 --- a/src/cdk/v2/destinations/ninetailed/data/trackMapping.json +++ b/src/cdk/v2/destinations/ninetailed/data/trackMapping.json @@ -1,7 +1,9 @@ [ { "sourceKeys": "properties", - "required": true, + "metadata": { + "defaultValue": {} + }, "destKey": "properties" }, { diff --git a/src/cdk/v2/destinations/ninetailed/procWorkflow.yaml b/src/cdk/v2/destinations/ninetailed/procWorkflow.yaml index 383b850a4d..e31912386a 100644 --- a/src/cdk/v2/destinations/ninetailed/procWorkflow.yaml +++ b/src/cdk/v2/destinations/ninetailed/procWorkflow.yaml @@ -23,7 +23,6 @@ steps: template: | const payload = $.constructFullPayload(.message); $.context.payload = $.removeUndefinedAndNullValues(payload); - - name: buildResponse template: | const response = $.defaultRequestConfig(); diff --git a/src/cdk/v2/destinations/ninetailed/utils.js b/src/cdk/v2/destinations/ninetailed/utils.js index 47b27b3b9d..fec1271561 100644 --- a/src/cdk/v2/destinations/ninetailed/utils.js +++ b/src/cdk/v2/destinations/ninetailed/utils.js @@ -30,6 +30,7 @@ const constructFullPayload = (message) => { message, config.mappingConfig[config.ConfigCategories.IDENTIFY.name], ); + typeSpecifcPayload.userId = typeSpecifcPayload.userId || ''; break; default: break; diff --git a/test/integrations/destinations/ninetailed/commonConfig.ts b/test/integrations/destinations/ninetailed/commonConfig.ts index 4baf72dee1..99df88dd66 100644 --- a/test/integrations/destinations/ninetailed/commonConfig.ts +++ b/test/integrations/destinations/ninetailed/commonConfig.ts @@ -96,11 +96,10 @@ export const contextWithNoLocation = { 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', }; -export const commonInputWithNoLocation = { +export const commonInputWithNoLocationAndChannel = { anonymousId: 'anon_123', messageId: 'dummy_msg_id', context: contextWithNoLocation, - channel: 'web', integrations: { All: true, }, diff --git a/test/integrations/destinations/ninetailed/processor/identify.ts b/test/integrations/destinations/ninetailed/processor/identify.ts index 3bb333c160..b580e17ed0 100644 --- a/test/integrations/destinations/ninetailed/processor/identify.ts +++ b/test/integrations/destinations/ninetailed/processor/identify.ts @@ -2,9 +2,8 @@ import { destination, traits, commonInput, - commonInputWithNoLocation, + commonInputWithNoLocationAndChannel, metadata, - processInstrumentationErrorStatTags, } from '../commonConfig'; import { transformResultBuilder } from '../../../testUtils'; export const identify = [ @@ -110,12 +109,12 @@ export const identify = [ }, }, { - id: 'ninetailed-test-identify-failure-1', + id: 'ninetailed-test-identify-success-2', 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', + 'No Error should be thrown for field userId not present but default empty string should be provided to userId and status code should be 200', feature: 'processor', module: 'destination', version: 'v0', @@ -125,9 +124,8 @@ export const identify = [ { destination, message: { - ...commonInput, + ...commonInputWithNoLocationAndChannel, type: 'identify', - channel: 'mobile', messageId: 'dummy_msg_id', traits: traits, }, @@ -141,13 +139,55 @@ export const identify = [ 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: processInstrumentationErrorStatTags, - statusCode: 400, + output: transformResultBuilder({ + method: 'POST', + endpoint: + 'https://experience.ninetailed.co/v2/organizations/dummyOrganisationId/environments/main/events', + JSON: { + events: [ + { + 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: {}, + }, + type: 'identify', + userId: '', + channel: 'server', + messageId: 'dummy_msg_id', + traits: traits, + anonymousId: 'anon_123', + originalTimestamp: '2021-01-25T15:32:56.409Z', + }, + ], + }, + userId: '', + }), + statusCode: 200, }, ], }, @@ -169,7 +209,7 @@ export const identify = [ destination, message: { type: 'identify', - ...commonInputWithNoLocation, + ...commonInputWithNoLocationAndChannel, userId: 'sajal12', traits: traits, integrations: { @@ -224,7 +264,7 @@ export const identify = [ location: {}, }, type: 'identify', - channel: 'web', + channel: 'server', userId: 'sajal12', messageId: 'dummy_msg_id', traits: traits, diff --git a/test/integrations/destinations/ninetailed/router/data.ts b/test/integrations/destinations/ninetailed/router/data.ts index 1bf664d1c4..14ac046127 100644 --- a/test/integrations/destinations/ninetailed/router/data.ts +++ b/test/integrations/destinations/ninetailed/router/data.ts @@ -3,6 +3,7 @@ import { destination, commonOutput, routerInstrumentationErrorStatTags, + context, } from '../commonConfig'; import { trackProperties, pageProperties, traits } from './basicProperties'; import { defaultMockFns } from '../mocks'; @@ -137,9 +138,14 @@ export const data = [ { message: { type: 'identify', - ...commonInput, + messageId: 'dummy_msg_id', + context, + channel: 'web', + integrations: { + All: true, + }, + originalTimestamp: '2021-01-25T15:32:56.409Z', traits, - integrations: { All: true }, }, metadata: { jobId: 3, userId: 'u1' }, destination, @@ -158,7 +164,7 @@ export const data = [ { batched: false, destination, - error: 'Missing required value from "userIdOnly"', + error: 'Missing required value from "anonymousId"', metadata: [{ jobId: 3, userId: 'u1' }], statTags: routerInstrumentationErrorStatTags, statusCode: 400, @@ -259,9 +265,14 @@ export const data = [ { message: { type: 'identify', - ...commonInput, + messageId: 'dummy_msg_id', + context, + channel: 'web', + integrations: { + All: true, + }, + originalTimestamp: '2021-01-25T15:32:56.409Z', traits, - integrations: { All: true }, }, metadata: { jobId: 4, userId: 'u1' }, destination, @@ -280,7 +291,7 @@ export const data = [ { batched: false, destination, - error: 'Missing required value from "userIdOnly"', + error: 'Missing required value from "anonymousId"', metadata: [{ jobId: 4, userId: 'u1' }], statTags: routerInstrumentationErrorStatTags, statusCode: 400,