Skip to content

Commit

Permalink
feat(engine): ♿️ Lowercase resiliency on "contains" operator
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Apr 8, 2022
1 parent 25961d3 commit 519723b
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions packages/bot-engine/src/services/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,22 @@ const executeCondition = (
const executeComparison =
(variables: Variable[]) => (comparison: Comparison) => {
if (!comparison?.variableId) return false
const inputValue =
const inputValue = (
variables.find((v) => v.id === comparison.variableId)?.value ?? ''
const value = parseVariables(variables)(comparison.value)
)
.toString()
.trim()
const value = parseVariables(variables)(comparison.value).toString().trim()
if (isNotDefined(value)) return false
switch (comparison.comparisonOperator) {
case ComparisonOperators.CONTAINS: {
return inputValue.toString().includes(value.toString())
return inputValue.toLowerCase().includes(value.toLowerCase())
}
case ComparisonOperators.EQUAL: {
return inputValue.toString() === value.toString()
return inputValue === value
}
case ComparisonOperators.NOT_EQUAL: {
return inputValue.toString() !== value.toString()
return inputValue !== value
}
case ComparisonOperators.GREATER: {
return parseFloat(inputValue) >= parseFloat(value)
Expand Down

0 comments on commit 519723b

Please sign in to comment.