diff --git a/src/v0/destinations/sfmc/transform.js b/src/v0/destinations/sfmc/transform.js index 879ca1989a..34630b2eda 100644 --- a/src/v0/destinations/sfmc/transform.js +++ b/src/v0/destinations/sfmc/transform.js @@ -224,16 +224,17 @@ const responseBuilderSimple = async (message, category, destination) => { throw new ConfigurationError('Creating or updating contacts is disabled'); } - if (category.type === 'track' && hashMapExternalKey[message.event.toLowerCase()]) { + const lowerCasedEvent = message?.event?.toLowerCase(); + if (category.type === 'track' && hashMapExternalKey[lowerCasedEvent]) { return responseBuilderForInsertData( message, - hashMapExternalKey[message.event.toLowerCase()], + hashMapExternalKey[lowerCasedEvent], subDomain, category, authToken, 'track', - hashMapPrimaryKey[message.event.toLowerCase()] || CONTACT_KEY_KEY, - hashMapUUID[message.event.toLowerCase()], + hashMapPrimaryKey[lowerCasedEvent] || CONTACT_KEY_KEY, + hashMapUUID[lowerCasedEvent], ); } diff --git a/test/__tests__/data/sfmc_input.json b/test/__tests__/data/sfmc_input.json index ee6eccb154..5050e8c214 100644 --- a/test/__tests__/data/sfmc_input.json +++ b/test/__tests__/data/sfmc_input.json @@ -993,5 +993,94 @@ "Enabled": true, "Transformations": [] } + }, + { + "message": { + "context": { + "app": { + "build": "1.0.0", + "name": "RudderLabs JavaScript SDK", + "version": "1.0.0" + }, + "campaign": { + "name": "Demo Campaign", + "source": "facebook", + "medium": "online", + "term": "Demo terms", + "content": "Demo content" + }, + "traits": { + "email": "tonmoy@rudderstack.com", + "name": "Tonmoy Labs" + }, + "library": { + "name": "RudderLabs JavaScript SDK", + "version": "1.0.0" + }, + "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.90 Safari/537.36", + "locale": "en-GB", + "ip": "0.0.0.0", + "screen": { + "density": 2, + "height": 860, + "width": 1280 + } + }, + "type": "track", + "messageId": "50360b9c-ea8d-409c-b672-c9230f91cce5", + "originalTimestamp": "2019-10-15T09:35:31.288Z", + "userId": "12345", + "properties": { + "Plan": "plan value", + "Price Key": 29.99, + "Contact Key": 12345, + "Guest Key": "2323-34343-3434" + }, + "sentAt": "2019-10-14T09:03:22.563Z", + "integrations": { + "All": true + } + }, + "destination": { + "ID": "1pYpzzvcn7AQ2W9GGIAZSsN6Mfq", + "Name": "SFMC", + "DestinationDefinition": { + "ID": "1pYpYSeQd8OeN6xPdw6VGDzqUd1", + "Name": "SFMC", + "DisplayName": "Salesforce Marketing Cloud", + "Config": { + "destConfig": [], + "excludeKeys": [], + "includeKeys": [], + "saveDestinationResponse": false, + "supportedSourceTypes": [], + "transformAt": "processor" + }, + "ResponseRules": {} + }, + "Config": { + "clientId": "vcn7AQ2W9GGIAZSsN6Mfq", + "clientSecret": "vcn7AQ2W9GGIAZSsN6Mfq", + "createOrUpdateContacts": false, + "eventDelivery": true, + "eventDeliveryTS": 1615371070621, + "eventToExternalKey": [ + { + "from": "Event Name", + "to": "C500FD37-155C-49BD-A21B-AFCEF3D1A9CB" + }, + { "from": "Watch", "to": "C500FD37-155C-49BD-A21B-AFCEF3D1A9CB" } + ], + "eventToPrimaryKey": [ + { "from": "userId", "to": "User Key" }, + { "from": "watch", "to": "Guest Key, Contact Key" } + ], + "eventToUUID": [{ "event": "Event Name", "uuid": true }], + "externalKey": "f3ffa19b-e0b3-4967-829f-549b781080e6", + "subDomain": "vcn7AQ2W9GGIAZSsN6Mfq" + }, + "Enabled": true, + "Transformations": [] + } } ] diff --git a/test/__tests__/data/sfmc_output.json b/test/__tests__/data/sfmc_output.json index 0271475e4a..404ac6dfb3 100644 --- a/test/__tests__/data/sfmc_output.json +++ b/test/__tests__/data/sfmc_output.json @@ -307,5 +307,8 @@ }, "version": "1", "endpoint": "https://vcn7AQ2W9GGIAZSsN6Mfq.rest.marketingcloudapis.com/hub/v1/dataevents/key:C500FD37-155C-49BD-A21B-AFCEF3D1A9CB/rows/Guest Key:2323-34343-3434,Contact Key:12345" + }, + { + "error": "Event not mapped for this track call" } ]