diff --git a/src/v0/destinations/splitio/data/EventConfig.json b/src/v0/destinations/splitio/data/EventConfig.json index d41398a5e2..6435458368 100644 --- a/src/v0/destinations/splitio/data/EventConfig.json +++ b/src/v0/destinations/splitio/data/EventConfig.json @@ -29,5 +29,17 @@ "type": "toFloat" }, "required": false + }, + { + "destKey": "trafficTypeName", + "sourceKeys": [ + "traits.trafficTypeName", + "context.traits.trafficTypeName", + "properties.trafficTypeName" + ], + "metadata": { + "type": "toString" + }, + "required": false } ] diff --git a/src/v0/destinations/splitio/transform.js b/src/v0/destinations/splitio/transform.js index 6641a62fe8..3dd5bea4f2 100644 --- a/src/v0/destinations/splitio/transform.js +++ b/src/v0/destinations/splitio/transform.js @@ -56,6 +56,7 @@ function prepareResponse(message, destination, category) { let outputPayload = {}; + // ref: https://docs.split.io/reference/events-overview outputPayload = constructPayload(message, MAPPING_CONFIG[category.name]); outputPayload.eventTypeId = outputPayload.eventTypeId.replace(/ /g, '_'); if (EVENT_TYPE_ID_REGEX.test(outputPayload.eventTypeId)) { @@ -93,7 +94,12 @@ function prepareResponse(message, destination, category) { if (isDefinedAndNotNullAndNotEmpty(environment)) { outputPayload.environmentName = environment; } - outputPayload.trafficTypeName = trafficType; + + // in case traffic type could not be mapped from the input payloads, falls back to the UI configured default traffic type. + if (!isDefinedAndNotNullAndNotEmpty(outputPayload.trafficTypeName)) { + outputPayload.trafficTypeName = trafficType; + } + outputPayload.properties = removeUndefinedNullValuesAndEmptyObjectArray( flattenJson(bufferProperty), ); diff --git a/src/v0/destinations/zendesk/transform.js b/src/v0/destinations/zendesk/transform.js index 5862014784..cadb1d3964 100644 --- a/src/v0/destinations/zendesk/transform.js +++ b/src/v0/destinations/zendesk/transform.js @@ -4,6 +4,7 @@ const { NetworkInstrumentationError, InstrumentationError, NetworkError, + isDefinedAndNotNull, } = require('@rudderstack/integrations-lib'); const myAxios = require('../../../util/myAxios'); @@ -405,6 +406,9 @@ async function getUserMembershipPayload(message, headers, orgId, destinationConf } async function createOrganization(message, category, headers, destinationConfig, baseEndpoint) { + if (!isDefinedAndNotNull(message.traits)) { + throw new InstrumentationError('Organisation Traits are missing. Aborting.'); + } await checkAndCreateUserFields( message.traits, category.organizationFieldsEndpoint, diff --git a/test/integrations/destinations/splitio/processor/data.ts b/test/integrations/destinations/splitio/processor/data.ts index 3fda93cc30..d4c3e39794 100644 --- a/test/integrations/destinations/splitio/processor/data.ts +++ b/test/integrations/destinations/splitio/processor/data.ts @@ -43,7 +43,7 @@ export const data = [ Config: { apiKey: 'abcde', environment: 'staging', - trafficType: 'user', + trafficType: 'anonymous', }, }, }, @@ -246,7 +246,7 @@ export const data = [ Config: { apiKey: 'abcde', environment: 'production', - trafficType: 'user', + trafficType: 'anonymous', }, }, }, @@ -847,6 +847,9 @@ export const data = [ library: { name: 'http', }, + traits: { + trafficTypeName: 'user', + }, }, type: 'identify', timestamp: '2020-01-21T00:21:34.208Z', @@ -858,7 +861,7 @@ export const data = [ Config: { apiKey: 'abcde', environment: 'staging', - trafficType: 'user', + trafficType: 'anonymous', }, }, }, diff --git a/test/integrations/destinations/zendesk/processor/data.ts b/test/integrations/destinations/zendesk/processor/data.ts index 4dab6c5d5d..d84cdba15a 100644 --- a/test/integrations/destinations/zendesk/processor/data.ts +++ b/test/integrations/destinations/zendesk/processor/data.ts @@ -2370,4 +2370,89 @@ export const data = [ }, }, }, + { + name: 'zendesk', + description: 'Group Call : If message.traits are not present, aborting the call.', + feature: 'processor', + module: 'destination', + version: 'v0', + input: { + request: { + body: [ + { + destination: { + Config: { + apiToken: 'myDummyApiToken4', + createUsersAsVerified: true, + domain: 'rudderlabshelp', + email: 'myDummyUserName1', + password: 'myDummyPwd1', + removeUsersFromOrganization: true, + sendGroupCallsWithoutUserId: true, + }, + DestinationDefinition: { + DisplayName: 'Zendesk', + ID: '1YknZ1ENqB8UurJQJE2VrEA61tr', + Name: 'ZENDESK', + }, + Enabled: true, + ID: 'xxxxxxxxxxxxxxxxxxxxxxxO51P', + Name: 'zendesk', + Transformations: [], + }, + message: { + anonymousId: '297b0750-934b-4411-b66c-9b418cdbc0c9', + channel: 'web', + context: { + app: { + build: '1.0.0', + name: 'RudderLabs JavaScript SDK', + namespace: 'com.rudderlabs.javascript', + version: '1.1.0-beta.2', + }, + ip: '0.0.0.0', + library: { name: 'RudderLabs JavaScript SDK', version: '1.1.0-beta.2' }, + locale: 'en-GB', + os: { name: '', version: '' }, + screen: { density: 2 }, + traits: { email: 'example124@email.com', name: 'abcd124' }, + userAgent: + 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36', + }, + groupId: 'group-124', + integrations: { All: true }, + messageId: '2d54ba80-ce5f-4bcb-b1d7-7587e7a865fc', + originalTimestamp: '2020-03-23T18:27:28.983Z', + receivedAt: '2020-03-23T23:57:29.022+05:30', + request_ip: '[::1]:51574', + sentAt: '2020-03-23T18:27:28.983Z', + timestamp: '2020-03-23T23:57:29.022+05:30', + type: 'group', + userId: 'abcd-124', + }, + }, + ], + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: [ + { + error: 'Organisation Traits are missing. Aborting.', + statTags: { + destType: 'ZENDESK', + errorCategory: 'dataValidation', + errorType: 'instrumentation', + feature: 'processor', + implementation: 'native', + module: 'destination', + }, + statusCode: 400, + }, + ], + }, + }, + }, ];