Browse Source

added condition that `res.data` must be non-empty to return early

pull/666/head
Stephen Hess 8 years ago
parent
commit
2a9c25f8c4
  1. 2
      controller/search.js
  2. 4
      test/unit/controller/search.js

2
controller/search.js

@ -20,7 +20,7 @@ function setup( config, backend, query ){
// do not run controller if there are already results // do not run controller if there are already results
// this was added during libpostal integration. if the libpostal parse/query // this was added during libpostal integration. if the libpostal parse/query
// doesn't return anything then fallback to old search-engine-y behavior // doesn't return anything then fallback to old search-engine-y behavior
if (res && res.hasOwnProperty('data')) { if (res && res.hasOwnProperty('data') && res.data.length > 0) {
return next(); return next();
} }

4
test/unit/controller/search.js

@ -181,10 +181,10 @@ module.exports.tests.existing_results = function(test, common) {
var req = { }; var req = { };
// the existence of `data` means that there are already results so // the existence of `data` means that there are already results so
// don't call the backend/query // don't call the backend/query
var res = { data: [] }; var res = { data: [{}] };
var next = function() { var next = function() {
t.deepEqual(res, {data: []}); t.deepEqual(res, {data: [{}]});
t.end(); t.end();
}; };
controller(req, res, next); controller(req, res, next);

Loading…
Cancel
Save