Skip to content

Commit

Permalink
refactor: add isObject check
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauravudia committed Oct 30, 2023
1 parent 2f3d4b3 commit 7753abe
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/v0/destinations/mp/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const {
getSuccessRespEvents,
defaultBatchRequestConfig,
IsGzipSupported,
isObject,
} = require('../../util');
const {
ConfigCategory,
Expand Down Expand Up @@ -189,7 +190,7 @@ const removeDuplicateMetadata = (mergedBatches) => {
*/
const buildUtmParams = (campaign) => {
const utmParams = {};
if (campaign) {
if (isObject(campaign)) {
Object.keys(campaign).forEach((key) => {
if (key === 'name') {
utmParams.utm_campaign = campaign[key];
Expand Down
6 changes: 6 additions & 0 deletions src/v0/destinations/mp/util.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,12 @@ describe('Mixpanel utils test', () => {
expect(result).toEqual({});
});

it('should return an empty object when campaign is not an object', () => {
const campaign = [{ name: 'test' }];
const result = buildUtmParams(campaign);
expect(result).toEqual({});
});

it('should handle campaign object with null/undefined values', () => {
const campaign = { name: null, source: 'rudder', medium: 'rudder', test: undefined };
const result = buildUtmParams(campaign);
Expand Down

0 comments on commit 7753abe

Please sign in to comment.