From 9d3de70a266db193197e644c830604de88b6a522 Mon Sep 17 00:00:00 2001 From: scottinet Date: Fri, 14 Sep 2018 11:32:24 +0200 Subject: [PATCH] fix #13 --- lib/match/matchEquals.js | 6 +++--- test/keywords/equals.test.js | 10 +++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/match/matchEquals.js b/lib/match/matchEquals.js index 94e4be1..6ebc80b 100644 --- a/lib/match/matchEquals.js +++ b/lib/match/matchEquals.js @@ -42,10 +42,10 @@ function MatchEquals (storage, testTables, document) { value = document[field]; if (document[field] !== undefined) { - const subfilters = storage.fields[field][typeof value][value]; + const subfilters = storage.fields[field][typeof value]; - if (subfilters !== undefined) { - testTables.addMatch(subfilters); + if (subfilters !== undefined && subfilters[value] !== undefined) { + testTables.addMatch(subfilters[value]); } } } diff --git a/test/keywords/equals.test.js b/test/keywords/equals.test.js index 789dbe0..870879c 100644 --- a/test/keywords/equals.test.js +++ b/test/keywords/equals.test.js @@ -157,6 +157,15 @@ describe('DSL.keyword.equals', () => { }); }); + // see https://github.com/kuzzleio/koncorde/issues/13 + it('should skip the matching if the document tested property is not of the same type than the known values', () => { + return dsl.register('index', 'collection', {equals: {foo: 'bar'}}) + .then(() => { + should(dsl.test('index', 'collection', {foo: ['bar']})).be.an.Array().and.empty(); + should(dsl.test('index', 'collection', {foo: {bar: true}})).be.an.Array().and.empty(); + }); + }); + it('should match a document with the subscribed nested keyword', () => { return dsl.register('index', 'collection', {equals: {'foo.bar.baz': 'qux'}}) .then(subscription => { @@ -207,7 +216,6 @@ describe('DSL.keyword.equals', () => { .length(1); }); }); - }); describe('#removal', () => {