Skip to content

Commit

Permalink
chore: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
yashasvibajpai committed Feb 21, 2024
1 parent 075e459 commit 7ff582b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/v0/destinations/sfmc/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,9 @@ const processRouterDest = async (inputs, reqMetadata) => {
return respList;
};

module.exports = { process, processRouterDest, responseBuilderSimple };
module.exports = {
process,
processRouterDest,
responseBuilderSimple,
responseBuilderForMessageEvent,
};
39 changes: 38 additions & 1 deletion src/v0/destinations/sfmc/transform.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { ConfigurationError } = require('@rudderstack/integrations-lib');
const axios = require('axios');
const MockAxiosAdapter = require('axios-mock-adapter');
const { responseBuilderSimple } = require('./transform');
const { responseBuilderSimple, responseBuilderForMessageEvent } = require('./transform');
beforeAll(() => {
const mock = new MockAxiosAdapter(axios);
mock
Expand Down Expand Up @@ -122,4 +122,41 @@ describe('responseBuilderSimple', () => {
expect(response).toHaveProperty('body.JSON');
expect(response).toHaveProperty('headers');
});

it('should build response object with correct details for message event', () => {
const message = {
userId: '12345',
event: 'testEvent',
properties: {
prop1: 'value1',
prop2: 'value2',
},
};
const subDomain = 'subdomain';
const authToken = 'token';
const hashMapEventDefinition = {
testevent: 'eventDefinitionKey',
};

const response = responseBuilderForMessageEvent(
message,
subDomain,
authToken,
hashMapEventDefinition,
);
expect(response.method).toBe('POST');
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",
EventDefinitionKey: 'eventDefinitionKey',
Data: {
prop1: 'value1',
prop2: 'value2',
},
});
});
});

0 comments on commit 7ff582b

Please sign in to comment.