Permalink
Browse files

fix(api): fix comparator matching

  • Loading branch information...
RangerRick committed Aug 4, 2017
1 parent 3a243a5 commit 6897389b6107019101e172f64c243c3bbbc844c6
Showing with 45 additions and 2 deletions.
  1. +3 −2 src/api/Comparator.ts
  2. +42 −0 test/api/Comparator.spec.ts
View
@@ -15,8 +15,9 @@ export class Comparator extends OnmsEnum<number> {
/** Whether this comparator matches the given comparator string. */
public matches(comparator: string) {
return (comparator.toLowerCase() === this.label.toLowerCase())
|| this.aliases.indexOf(comparator) >= 0;
const compareTo = comparator.toUpperCase();
return (compareTo === this.label.toUpperCase())
|| this.aliases.indexOf(compareTo) >= 0;
}
}
@@ -0,0 +1,42 @@
declare const describe, beforeEach, it, expect;
import {Comparator, Comparators} from '../../src/api/Comparator';
const matches = {
'=': Comparators.EQ,
'==': Comparators.EQ,
'eq': Comparators.EQ,
'!=': Comparators.NE,
'ne': Comparators.NE,
'ilike': Comparators.ILIKE,
'like': Comparators.LIKE,
'>': Comparators.GT,
'gt': Comparators.GT,
'<': Comparators.LT,
'lt': Comparators.LT,
'>=': Comparators.GE,
'ge': Comparators.GE,
'<=': Comparators.LE,
'le': Comparators.LE,
'null': Comparators.NULL,
'isnull': Comparators.NULL,
'notnull': Comparators.NOTNULL
}
describe('Comparators: Lower-Case', () => {
for (const match in matches) {
const comparator = matches[match];
it(comparator.label + ' should match ' + match.toLowerCase(), () => {
expect(comparator.matches(match.toLowerCase())).toBeTruthy();
});
}
});
describe('Comparators: Upper-Case', () => {
for (const match in matches) {
const comparator = matches[match];
it(comparator.label + ' should match ' + match.toUpperCase(), () => {
expect(comparator.matches(match.toUpperCase())).toBeTruthy();
});
}
});

0 comments on commit 6897389

Please sign in to comment.