-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MOB-9145: support isOneOf and isNotOneOf comparator #446
Changes from 4 commits
7c68c4b
8cd05ed
2ff52dd
0ed9b9c
12da954
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,7 @@ | |
} | ||
|
||
class CriteriaCompletionChecker { | ||
private localStoredEventList: any[]; | ||
|
||
constructor(localStoredEventList: string) { | ||
this.localStoredEventList = JSON.parse(localStoredEventList); | ||
|
@@ -72,9 +72,9 @@ | |
return matchingCriteria ? matchingCriteria.criteriaId : null; | ||
} | ||
|
||
private prepareEventsToProcess(): any[] { | ||
const eventsToProcess: any[] = this.getEventsWithCartItems(); | ||
const nonPurchaseEvents: any[] = this.getNonCartEvents(); | ||
|
||
nonPurchaseEvents.forEach((event) => { | ||
eventsToProcess.push(event); | ||
|
@@ -83,7 +83,7 @@ | |
return eventsToProcess; | ||
} | ||
|
||
private getEventsWithCartItems(): any[] { | ||
const processedEvents: any[] = []; | ||
|
||
this.localStoredEventList.forEach((localEventData) => { | ||
|
@@ -362,7 +362,7 @@ | |
return this.evaluateComparison( | ||
query.comparatorType, | ||
valueFromObj, | ||
query.value ? query.value : '' | ||
query.value ? query.values : '' | ||
); | ||
} | ||
return false; | ||
|
@@ -374,14 +374,14 @@ | |
return this.evaluateComparison( | ||
query.comparatorType, | ||
valueFromObj, | ||
query.value ? query.value : '' | ||
query.value ?? query.values ?? '' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what happens if an empty string is evaluated? should we even run the evaluation at all if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So empty string is compared with the criteria value, empty string is not matched with value and gives result as false. |
||
); | ||
} | ||
} else if (eventKeyItems.length) { | ||
return this.evaluateComparison( | ||
query.comparatorType, | ||
eventData[field], | ||
query.value ? query.value : '' | ||
query.value ?? query.values ?? '' | ||
); | ||
} | ||
return false; | ||
|
@@ -427,7 +427,7 @@ | |
return this.evaluateComparison( | ||
query.comparatorType, | ||
item[field], | ||
query.value ? query.value : '' | ||
query.value ?? query.values ?? '' | ||
); | ||
} | ||
return false; | ||
|
@@ -437,7 +437,7 @@ | |
private evaluateComparison( | ||
comparatorType: string, | ||
matchObj: any, | ||
valueToCompare: string | ||
valueToCompare: string | string[] | ||
): boolean { | ||
if (!valueToCompare && comparatorType !== 'IsSet') { | ||
return false; | ||
|
@@ -455,27 +455,36 @@ | |
case 'LessThanOrEqualTo': | ||
return this.compareNumericValues( | ||
matchObj, | ||
valueToCompare, | ||
valueToCompare as string, | ||
comparatorType | ||
); | ||
case 'Contains': | ||
return this.compareStringContains(matchObj, valueToCompare); | ||
return this.compareStringContains(matchObj, valueToCompare as string); | ||
case 'StartsWith': | ||
return this.compareStringStartsWith(matchObj, valueToCompare); | ||
return this.compareStringStartsWith(matchObj, valueToCompare as string); | ||
case 'MatchesRegex': | ||
return this.compareWithRegex(matchObj, valueToCompare); | ||
return this.compareWithRegex(matchObj, valueToCompare as string); | ||
default: | ||
return false; | ||
} | ||
} | ||
|
||
private compareValueEquality(sourceTo: any, stringValue: string): boolean { | ||
private compareValueEquality( | ||
sourceTo: any, | ||
stringValue: string | string[] | ||
): boolean { | ||
if (Array.isArray(sourceTo)) { | ||
return sourceTo.some((source) => | ||
this.compareValueEquality(source, stringValue) | ||
); | ||
} | ||
|
||
if (Array.isArray(stringValue)) { | ||
return stringValue.some((value) => | ||
this.compareValueEquality(sourceTo, value) | ||
); | ||
} | ||
|
||
if ( | ||
(typeof sourceTo === 'number' || typeof sourceTo === 'boolean') && | ||
stringValue !== '' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this one slightly different than the others?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because in value we have single element and in values we have multiple element(s),
and when we create criteria for the isOneOf and isNotOneOf comparator we get values instead of value