diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/filter/utils/__tests__/evaluate-filter-conditions.util.spec.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/filter/utils/__tests__/evaluate-filter-conditions.util.spec.ts index e5ce98f4a9..ad7adc1acf 100644 --- a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/filter/utils/__tests__/evaluate-filter-conditions.util.spec.ts +++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/filter/utils/__tests__/evaluate-filter-conditions.util.spec.ts @@ -1042,6 +1042,45 @@ describe('evaluateFilterConditions', () => { true, ); }); + + it.each([ + ViewFilterOperand.IS, + ViewFilterOperand.IS_IN_PAST, + ViewFilterOperand.IS_IN_FUTURE, + ViewFilterOperand.IS_TODAY, + ViewFilterOperand.IS_BEFORE, + ViewFilterOperand.IS_AFTER, + ViewFilterOperand.IS_RELATIVE, + ])( + 'should not match and not throw when the left operand is an empty/invalid date (%s)', + (operand) => { + const relativeValue = JSON.stringify({ + direction: 'PAST', + amount: 1, + unit: 'DAY', + }); + + const emptyStepOutputFilter = createFilter( + operand, + '', + relativeValue, + 'DATE', + ); + const missingStepOutputFilter = createFilter( + operand, + undefined, + relativeValue, + 'DATE_TIME', + ); + + expect( + evaluateFilterConditions({ filters: [emptyStepOutputFilter] }), + ).toBe(false); + expect( + evaluateFilterConditions({ filters: [missingStepOutputFilter] }), + ).toBe(false); + }, + ); }); describe('currency operands', () => { diff --git a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/filter/utils/evaluate-filter-conditions.util.ts b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/filter/utils/evaluate-filter-conditions.util.ts index 05ded6949f..566ea37773 100644 --- a/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/filter/utils/evaluate-filter-conditions.util.ts +++ b/packages/twenty-server/src/modules/workflow/workflow-executor/workflow-actions/filter/utils/evaluate-filter-conditions.util.ts @@ -216,8 +216,20 @@ function evaluateBooleanFilter(filter: ResolvedFilter): boolean { function evaluateDateFilter(filter: ResolvedFilter): boolean { // TODO: refactor this with Temporal + if (filter.operand === ViewFilterOperand.IS_EMPTY) { + return !isDefined(filter.leftOperand) || filter.leftOperand === ''; + } + + if (filter.operand === ViewFilterOperand.IS_NOT_EMPTY) { + return isDefined(filter.leftOperand) && filter.leftOperand !== ''; + } + const dateLeftValue = new Date(String(filter.leftOperand)); + if (Number.isNaN(dateLeftValue.getTime())) { + return false; + } + switch (filter.operand) { case ViewFilterOperand.IS: return ( @@ -245,12 +257,6 @@ function evaluateDateFilter(filter: ResolvedFilter): boolean { new Date(String(filter.rightOperand)).getTime() ); - case ViewFilterOperand.IS_EMPTY: - return !isDefined(filter.leftOperand) || filter.leftOperand === ''; - - case ViewFilterOperand.IS_NOT_EMPTY: - return isDefined(filter.leftOperand) && filter.leftOperand !== ''; - case ViewFilterOperand.IS_RELATIVE: return parseAndEvaluateRelativeDateFilter({ dateToCheck: dateLeftValue,