Skip to content

Commit

Permalink
fix: added test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
aashishmalik committed Feb 28, 2024
1 parent 2debc8a commit 25c74af
Show file tree
Hide file tree
Showing 2 changed files with 448 additions and 403 deletions.
19 changes: 10 additions & 9 deletions src/v0/util/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2208,16 +2208,17 @@ const combineBatchRequestsWithSameJobIds = (inputBatches) => {
* @returns {string} Event name converted to string.
*/
const validateEventAndLowerCaseConversion = (event, isMandatory, converToLowercase) => {
if (!event && isMandatory) {
throw new InstrumentationError('Event is a required field');
if (typeof event === 'object' || event === NaN || !isDefined(event)) {

Check failure on line 2211 in src/v0/util/index.js

View workflow job for this annotation

GitHub Actions / Check for formatting & lint errors

Use the isNaN function to compare with NaN
throw new InstrumentationError('Event should not be a object, function or NaN and undefined');
}

if (isMandatory && (!event || typeof event !== 'string')) {
throw new InstrumentationError('Event is a required field and should be a string');
if (!isMandatory) {
return converToLowercase ? event.toString().toLowerCase() : event.toString();
}

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

// handling 0 as it is a valid value
if (!event && event !== 0) {
throw new InstrumentationError('Event is a required field');
}
return converToLowercase ? event.toString().toLowerCase() : event.toString();
};

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

0 comments on commit 25c74af

Please sign in to comment.