empty lists are invalid comparators (#5160)

This commit is contained in:
Gabe Lyons 2018-06-07 15:02:43 -07:00 committed by John Bodley
parent 57e125688f
commit 5b35f75cbf
2 changed files with 27 additions and 1 deletions

View File

@ -112,6 +112,26 @@ describe('AdhocFilter', () => {
});
// eslint-disable-next-line no-unused-expressions
expect(adhocFilter3.isValid()).to.be.false;
const adhocFilter4 = new AdhocFilter({
expressionType: EXPRESSION_TYPES.SIMPLE,
subject: 'value',
operator: 'in',
comparator: [],
clause: CLAUSES.WHERE,
});
// eslint-disable-next-line no-unused-expressions
expect(adhocFilter4.isValid()).to.be.false;
const adhocFilter5 = new AdhocFilter({
expressionType: EXPRESSION_TYPES.SIMPLE,
subject: 'value',
operator: 'in',
comparator: ['val1'],
clause: CLAUSES.WHERE,
});
// eslint-disable-next-line no-unused-expressions
expect(adhocFilter5.isValid()).to.be.true;
});
it('can translate from simple expressions to sql expressions', () => {

View File

@ -83,7 +83,13 @@ export default class AdhocFilter {
isValid() {
if (this.expressionType === EXPRESSION_TYPES.SIMPLE) {
return !!(this.operator && this.subject && this.comparator && this.clause);
return !!(
this.operator &&
this.subject &&
this.comparator &&
this.comparator.length > 0 &&
this.clause
);
} else if (this.expressionType === EXPRESSION_TYPES.SQL) {
return !!(this.sqlExpression && this.clause);
}