From e9ff88f4536d0108712e802f89857bb170f393e1 Mon Sep 17 00:00:00 2001 From: paulussup Date: Tue, 25 Apr 2017 08:58:11 +0930 Subject: [PATCH] Fix/geo null (#1334) * fix check for null * add tests * fix for early return * Allow check for null and non-existent value Some connectors uses a non existent prop instead of allowing null Modified test case to look if null exists or the prop is non existent * Check for null value with geo near query * Apply requested changes * change test to two users and simplify * check error first * Fix simple query test case with null value * BDD for connectors w//o null support --- lib/geo.js | 3 ++- test/basic-querying.test.js | 16 +++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/geo.js b/lib/geo.js index 08f8354d..fd2c4737 100644 --- a/lib/geo.js +++ b/lib/geo.js @@ -19,6 +19,7 @@ exports.nearFilter = function nearFilter(where) { parentKeys = parentKeys || []; Object.keys(clause).forEach(function(clauseKey) { + if (typeof clause[clauseKey] !== 'object' || !clause[clauseKey]) return; if (Array.isArray(clause[clauseKey])) { clause[clauseKey].forEach(function(el, index) { var ret = nearSearch(el, parentKeys.concat(clauseKey).concat(index)); @@ -37,7 +38,7 @@ exports.nearFilter = function nearFilter(where) { key: clauseKey, }); } - } + }; }); } var nearResults = []; diff --git a/test/basic-querying.test.js b/test/basic-querying.test.js index 9b1ea00a..9adf6092 100644 --- a/test/basic-querying.test.js +++ b/test/basic-querying.test.js @@ -100,7 +100,7 @@ describe('basic-querying', function() { db = getSchema(); var people = [ {name: 'a', vip: true}, - {name: 'b'}, + {name: 'b', vip: null}, {name: 'c'}, {name: 'd', vip: true}, {name: 'e'}, @@ -153,6 +153,20 @@ describe('basic-querying', function() { done(); }); }); + + bdd.itIf(connectorCapabilities.nullDataValueExists !== false, + 'should query by ids to check null property', function(done) { + User.findByIds([ + createdUsers[0].id, + createdUsers[1].id], + {where: {vip: null}}, function(err, users) { + should.not.exist(err); + should.exist(users); + users.length.should.eql(1); + users[0].name.should.eql(createdUsers[1].name); + done(); + }); + }); }); describe('find', function() {