Skip to content

Commit

Permalink
chore: map contect key from properties instead of userId
Browse files Browse the repository at this point in the history
  • Loading branch information
yashasvibajpai committed Feb 22, 2024
1 parent b997069 commit 1c12913
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/v0/destinations/sfmc/transform.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-param-reassign */
/* eslint-disable no-nested-ternary */
const {
NetworkError,
Expand Down Expand Up @@ -182,9 +183,11 @@ const responseBuilderForInsertData = (
return response;
};

// DOC : https://developer.salesforce.com/docs/marketing/marketing-cloud/references/mc_rest_interaction/postEvent.html

const responseBuilderForMessageEvent = (message, subDomain, authToken, hashMapEventDefinition) => {
const contactKey =
getFieldValueFromMessage(message, 'userIdOnly') || getFieldValueFromMessage(message, 'email');
const contactKey = message.properties.contactId;
delete message.properties.contactId;
const response = defaultRequestConfig();
response.method = defaultPostRequestConfig.requestMethod;
response.endpoint = `https://${subDomain}.${ENDPOINTS.EVENT}`;
Expand Down
9 changes: 6 additions & 3 deletions src/v0/destinations/sfmc/transform.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,10 @@ describe('responseBuilderSimple', () => {

it('should build response object with correct details for message event', () => {
const message = {
userId: '12345',
userId: 'u123',
event: 'testEvent',
properties: {
contactId: '12345',
prop1: 'value1',
prop2: 'value2',
},
Expand All @@ -145,13 +146,15 @@ describe('responseBuilderSimple', () => {
hashMapEventDefinition,
);
expect(response.method).toBe('POST');
expect(response.endpoint).toBe('https://subdomain.rest.marketingcloudapis.com/interaction/v1/events');
expect(response.endpoint).toBe(
'https://subdomain.rest.marketingcloudapis.com/interaction/v1/events',
);
expect(response.headers).toEqual({
'Content-Type': 'application/json',
Authorization: 'Bearer token',
});
expect(response.body.JSON).toEqual({
ContactKey: "12345",
ContactKey: '12345',
EventDefinitionKey: 'eventDefinitionKey',
Data: {
prop1: 'value1',
Expand Down

0 comments on commit 1c12913

Please sign in to comment.