mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-13 03:13:47 +00:00
Fix: automation (#1943)
* Fix(automation): Handles undefined values in conditions (#1933) * Fix(automation): Handles undefined values in conditions Addresses an issue where conditions with the 'not_equals' operator incorrectly evaluated undefined values. This change ensures that empty string comparisons correctly identify missing values in automation rules. * Fixes automation "not equals" logic Simplifies the 'not_equals' condition evaluation in automations by reusing the 'equals' condition, improving code readability and consistency. Fixes #1932 * Test(automation): Expanding filter condition testing Expanding test cases to cover various data types and edge case for each operators. Unexpected behavior have been mark with a TO_DO. * Fix(automation): Handles default filter case - Ensures that their is a default scenario. - Fixing Deepsource issue "No default cases in switch statements JS-0047" * Test(automation): Remove abstraction in test * move to test.each * extract a isEquivalent function * lowercase contains test --------- Co-authored-by: Philippe Allard-Rousse <philrousse@gmail.com>
This commit is contained in:
committed by
GitHub
parent
904db95f59
commit
efede83271
@@ -148,6 +148,38 @@ const quickAliases: AliasesDefinition = {
|
||||
startedAt: { key: 'timer.startedAt', cb: (value: string) => formatDisplayFromString(value) },
|
||||
};
|
||||
|
||||
export function isEquivalent(a: unknown, b: string): boolean {
|
||||
// handle the case where we are comparing boolean strings
|
||||
if (typeof a === 'boolean') {
|
||||
return isBooleanEquals(a, b);
|
||||
}
|
||||
// make string comparisons case insensitive
|
||||
if (typeof a === 'string') {
|
||||
return a.toLowerCase() === b;
|
||||
}
|
||||
// overload the edge case where we use empty string to check if a value does not exist
|
||||
// this also avoids the case where 0 == ''
|
||||
if (b === '') {
|
||||
return a === null || a === undefined;
|
||||
}
|
||||
return a == b;
|
||||
}
|
||||
|
||||
export function isContained(a: unknown, b: string): boolean {
|
||||
// handle the case where we are comparing boolean strings
|
||||
if (typeof a === 'boolean') {
|
||||
return false;
|
||||
}
|
||||
// make string comparisons case insensitive
|
||||
if (typeof a === 'string') {
|
||||
return a.toLowerCase().includes(b);
|
||||
}
|
||||
if (typeof a === 'number') {
|
||||
return a.toString().toLowerCase().includes(b);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility encapsulates logic for comparing two strings which may encode numbers
|
||||
* @example isGreaterThan('10', '5') // true
|
||||
|
||||
Reference in New Issue
Block a user