Skip to content

Commit

Permalink
fix: lowercase null check for track event adobe analytics
Browse files Browse the repository at this point in the history
  • Loading branch information
aashishmalik committed Feb 28, 2024
1 parent 2761786 commit 2debc8a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/v0/destinations/adobe_analytics/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const {
getIntegrationsObj,
removeUndefinedAndNullValues,
simpleProcessRouterDest,
validateEventAndLowerCaseConversion,
} = require('../../util');

const {
Expand Down Expand Up @@ -307,7 +308,7 @@ const processTrackEvent = (message, adobeEventName, destinationConfig, extras =
destinationConfig;
const { event: rawMessageEvent, properties } = message;
const { overrideEventString, overrideProductString } = properties;
const event = rawMessageEvent.toLowerCase();
const event = validateEventAndLowerCaseConversion(rawMessageEvent, true, true);
const adobeEventArr = adobeEventName ? adobeEventName.split(',') : [];
// adobeEventArr is an array of events which is defined as
// ["eventName", "mapped Adobe Event=mapped merchproperty's value", "mapped Adobe Event=mapped merchproperty's value", . . .]
Expand Down
20 changes: 20 additions & 0 deletions src/v0/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2201,6 +2201,25 @@ const combineBatchRequestsWithSameJobIds = (inputBatches) => {
return combineBatches(combineBatches(inputBatches));
};

/**
* This function validates the event and return it as string.
* @param {*} isMandatory The event is a required field.
* @param {*} converToLowercase The event should be converted to lower-case.
* @returns {string} Event name converted to string.
*/
const validateEventAndLowerCaseConversion = (event, isMandatory, converToLowercase) => {
if (!event && isMandatory) {
throw new InstrumentationError('Event is a required field');

Check warning on line 2212 in src/v0/util/index.js

View check run for this annotation

Codecov / codecov/patch

src/v0/util/index.js#L2212

Added line #L2212 was not covered by tests
}

if (isMandatory && (!event || typeof event !== 'string')) {
throw new InstrumentationError('Event is a required field and should be a string');

Check warning on line 2216 in src/v0/util/index.js

View check run for this annotation

Codecov / codecov/patch

src/v0/util/index.js#L2216

Added line #L2216 was not covered by tests
}

return converToLowercase ? event.toString().toLowerCase() : event.toString();

};

// ========================================================================
// EXPORTS
// ========================================================================
Expand Down Expand Up @@ -2317,4 +2336,5 @@ module.exports = {
findExistingBatch,
removeDuplicateMetadata,
combineBatchRequestsWithSameJobIds,
validateEventAndLowerCaseConversion
};

0 comments on commit 2debc8a

Please sign in to comment.