Skip to content

Commit

Permalink
feat(filter): add "is in" filter (#806)
Browse files Browse the repository at this point in the history
  • Loading branch information
olesyakorovina authored Sep 10, 2021
1 parent e039498 commit bb10856
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/services/filters-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ function FiltersParser(modelSchema, timezone, options) {
case 'includes_all':
return { [this.OPERATORS.CONTAINS]: value };
case 'in':
return { [this.OPERATORS.IN]: value };
return typeof value === 'string'
? { [this.OPERATORS.IN]: value.split(',').map((elem) => elem.trim()) }
: { [this.OPERATORS.IN]: value };
default:
throw new NoMatchingOperatorError();
}
Expand Down
8 changes: 6 additions & 2 deletions test/services/filters-parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ describe('services > filters-parser', () => {
});

describe('formatOperatorValue function', () => {
const values = [5, 'toto', null];
const values = [5, 'toto,tutu ', null];

values.forEach((value) => {
it(`should return the appropriate value (${typeof value})`, () => {
Expand All @@ -113,7 +113,11 @@ describe('services > filters-parser', () => {
[OPERATORS.EQ]: '',
}],
});
expect(defaultFiltersParser.formatOperatorValue('in', value)).toStrictEqual({ [OPERATORS.IN]: value });
expect(defaultFiltersParser.formatOperatorValue('in', value)).toStrictEqual(
typeof value === 'string'
? { [OPERATORS.IN]: value.split(',').map((elem) => elem.trim()) }
: { [OPERATORS.IN]: value },
);
});

it('should raise an error on unknown operator', () => {
Expand Down

0 comments on commit bb10856

Please sign in to comment.