diff --git a/src/filter.js b/src/filter.js index 0b26c82..b3ab3f6 100644 --- a/src/filter.js +++ b/src/filter.js @@ -72,26 +72,24 @@ class Filter { _in(value, key, result) { let isValid = false - if (!result[key]) { - isValid = false - } - - if (Array.isArray(value)) { - let found = false - - // run through array - value.forEach((v, index) => { - if (result[key].indexOf(v) !== -1) { - found = true + if (result[key]) { + if (Array.isArray(value)) { + let found = false + + // run through array + value.forEach((v, index) => { + if (result[key].indexOf(v) !== -1) { + found = true + } + }) + + if (found) { + isValid = true + } + } else { + if (result[key].indexOf(value) !== -1) { + isValid = true } - }) - - if (found) { - isValid = true - } - } else { - if (result[key].indexOf(value) !== -1) { - isValid = true } } diff --git a/test/filter.js b/test/filter.js index d50f036..ff4359a 100644 --- a/test/filter.js +++ b/test/filter.js @@ -54,6 +54,21 @@ describe('Filter', function () { assert.equal(filter.validate(data), true) }) + it('_in single, missing tags', function() { + + const filter = new Filter({ + tags: { + _in: 'monday' + } + }) + + const data = { + name: 'monday' + } + + assert.equal(filter.validate(data), false) + }) + it('_in array', function() { const filter = new Filter({