From f06704985ecea5317df4e3ef0dfd60c19bbfff12 Mon Sep 17 00:00:00 2001 From: Stephen Hess Date: Wed, 15 Mar 2017 11:08:57 -0400 Subject: [PATCH] renamed predicates to be more accurate --- .../{has_errors.js => has_request_errors.js} | 0 .../{has_data.js => has_response_data.js} | 0 routes/v1.js | 20 +++++++++---------- .../{has_errors.js => has_request_errors.js} | 12 +++++------ .../{has_data.js => has_response_data.js} | 12 +++++------ test/unit/run.js | 4 ++-- 6 files changed, 24 insertions(+), 24 deletions(-) rename controller/predicates/{has_errors.js => has_request_errors.js} (100%) rename controller/predicates/{has_data.js => has_response_data.js} (100%) rename test/unit/controller/predicates/{has_errors.js => has_request_errors.js} (71%) rename test/unit/controller/predicates/{has_data.js => has_response_data.js} (71%) diff --git a/controller/predicates/has_errors.js b/controller/predicates/has_request_errors.js similarity index 100% rename from controller/predicates/has_errors.js rename to controller/predicates/has_request_errors.js diff --git a/controller/predicates/has_data.js b/controller/predicates/has_response_data.js similarity index 100% rename from controller/predicates/has_data.js rename to controller/predicates/has_response_data.js diff --git a/routes/v1.js b/routes/v1.js index 545506d6..60e48172 100644 --- a/routes/v1.js +++ b/routes/v1.js @@ -61,12 +61,12 @@ var postProc = { }; // predicates that drive whether controller/search runs -const hasData = require('../controller/predicates/has_data'); -const hasErrors = require('../controller/predicates/has_errors'); +const hasResponseData = require('../controller/predicates/has_response_data'); +const hasRequestErrors = require('../controller/predicates/has_request_errors'); const isCoarseReverse = require('../controller/predicates/is_coarse_reverse'); // shorthand for standard early-exit conditions -const hasDataOrErrors = any(hasData, hasErrors); +const hasResponseDataOrRequestErrors = any(hasResponseData, hasRequestErrors); /** * Append routes to app @@ -81,14 +81,14 @@ function addRoutes(app, peliasConfig) { const pipService = require('../service/pointinpolygon')(peliasConfig.api.pipService); const coarse_reverse_should_execute = all( - not(hasErrors), isPipServiceEnabled, isCoarseReverse + not(hasRequestErrors), isPipServiceEnabled, isCoarseReverse ); // execute under the following conditions: // - there are no errors or data // - request is not coarse OR pip service is disabled const original_reverse_should_execute = all( - not(hasDataOrErrors), + not(hasResponseDataOrRequestErrors), any( not(isCoarseReverse), not(isPipServiceEnabled) @@ -111,9 +111,9 @@ function addRoutes(app, peliasConfig) { middleware.calcSize(), // 3rd parameter is which query module to use, use fallback/geodisambiguation // first, then use original search strategy if first query didn't return anything - controllers.search(peliasConfig.api, esclient, queries.libpostal, not(hasDataOrErrors)), + controllers.search(peliasConfig.api, esclient, queries.libpostal, not(hasResponseDataOrRequestErrors)), sanitizers.search_fallback.middleware, - controllers.search(peliasConfig.api, esclient, queries.fallback_to_old_prod, not(hasDataOrErrors)), + controllers.search(peliasConfig.api, esclient, queries.fallback_to_old_prod, not(hasResponseDataOrRequestErrors)), postProc.trimByGranularity(), postProc.distances('focus.point.'), postProc.confidenceScores(peliasConfig.api), @@ -132,7 +132,7 @@ function addRoutes(app, peliasConfig) { structured: createRouter([ sanitizers.structured_geocoding.middleware, middleware.calcSize(), - controllers.search(peliasConfig.api, esclient, queries.structured_geocoding, not(hasDataOrErrors)), + controllers.search(peliasConfig.api, esclient, queries.structured_geocoding, not(hasResponseDataOrRequestErrors)), postProc.trimByGranularityStructured(), postProc.distances('focus.point.'), postProc.confidenceScores(peliasConfig.api), @@ -150,7 +150,7 @@ function addRoutes(app, peliasConfig) { ]), autocomplete: createRouter([ sanitizers.autocomplete.middleware, - controllers.search(peliasConfig.api, esclient, queries.autocomplete, not(hasDataOrErrors)), + controllers.search(peliasConfig.api, esclient, queries.autocomplete, not(hasResponseDataOrRequestErrors)), postProc.distances('focus.point.'), postProc.confidenceScores(peliasConfig.api), postProc.dedupe(), @@ -185,7 +185,7 @@ function addRoutes(app, peliasConfig) { nearby: createRouter([ sanitizers.nearby.middleware, middleware.calcSize(), - controllers.search(peliasConfig.api, esclient, queries.reverse, not(hasDataOrErrors)), + controllers.search(peliasConfig.api, esclient, queries.reverse, not(hasResponseDataOrRequestErrors)), postProc.distances('point.'), // reverse confidence scoring depends on distance from origin // so it must be calculated first diff --git a/test/unit/controller/predicates/has_errors.js b/test/unit/controller/predicates/has_request_errors.js similarity index 71% rename from test/unit/controller/predicates/has_errors.js rename to test/unit/controller/predicates/has_request_errors.js index 88c255ca..bd1868aa 100644 --- a/test/unit/controller/predicates/has_errors.js +++ b/test/unit/controller/predicates/has_request_errors.js @@ -1,13 +1,13 @@ 'use strict'; const _ = require('lodash'); -const has_errors = require('../../../../controller/predicates/has_errors'); +const has_request_errors = require('../../../../controller/predicates/has_request_errors'); module.exports.tests = {}; module.exports.tests.interface = (test, common) => { test('valid interface', (t) => { - t.equal(typeof has_errors, 'function', 'has_errors is a function'); + t.equal(typeof has_request_errors, 'function', 'has_request_errors is a function'); t.end(); }); }; @@ -19,7 +19,7 @@ module.exports.tests.true_conditions = (test, common) => { }; const res = {}; - t.ok(has_errors(req, res)); + t.ok(has_request_errors(req, res)); t.end(); }); @@ -31,7 +31,7 @@ module.exports.tests.false_conditions = (test, common) => { const req = {}; const res = {}; - t.notOk(has_errors(req, res)); + t.notOk(has_request_errors(req, res)); t.end(); }); @@ -42,7 +42,7 @@ module.exports.tests.false_conditions = (test, common) => { }; const res = {}; - t.notOk(has_errors(req, res)); + t.notOk(has_request_errors(req, res)); t.end(); }); @@ -51,7 +51,7 @@ module.exports.tests.false_conditions = (test, common) => { module.exports.all = (tape, common) => { function test(name, testFunction) { - return tape(`GET /has_errors ${name}`, testFunction); + return tape(`GET /has_request_errors ${name}`, testFunction); } for( const testCase in module.exports.tests ){ diff --git a/test/unit/controller/predicates/has_data.js b/test/unit/controller/predicates/has_response_data.js similarity index 71% rename from test/unit/controller/predicates/has_data.js rename to test/unit/controller/predicates/has_response_data.js index 48d35e67..f073fc4d 100644 --- a/test/unit/controller/predicates/has_data.js +++ b/test/unit/controller/predicates/has_response_data.js @@ -1,13 +1,13 @@ 'use strict'; const _ = require('lodash'); -const has_data = require('../../../../controller/predicates/has_data'); +const has_response_data = require('../../../../controller/predicates/has_response_data'); module.exports.tests = {}; module.exports.tests.interface = (test, common) => { test('valid interface', (t) => { - t.equal(typeof has_data, 'function', 'has_data is a function'); + t.equal(typeof has_response_data, 'function', 'has_response_data is a function'); t.end(); }); }; @@ -19,7 +19,7 @@ module.exports.tests.true_conditions = (test, common) => { data: [1] }; - t.ok(has_data(req, res)); + t.ok(has_response_data(req, res)); t.end(); }); @@ -31,7 +31,7 @@ module.exports.tests.false_conditions = (test, common) => { const req = {}; const res = {}; - t.notOk(has_data(req, res)); + t.notOk(has_response_data(req, res)); t.end(); }); @@ -42,7 +42,7 @@ module.exports.tests.false_conditions = (test, common) => { data: [] }; - t.notOk(has_data(req, res)); + t.notOk(has_response_data(req, res)); t.end(); }); @@ -51,7 +51,7 @@ module.exports.tests.false_conditions = (test, common) => { module.exports.all = (tape, common) => { function test(name, testFunction) { - return tape(`GET /has_data ${name}`, testFunction); + return tape(`GET /has_response_data ${name}`, testFunction); } for( const testCase in module.exports.tests ){ diff --git a/test/unit/run.js b/test/unit/run.js index b746d979..a16fb18e 100644 --- a/test/unit/run.js +++ b/test/unit/run.js @@ -15,8 +15,8 @@ var tests = [ require('./controller/index'), require('./controller/place'), require('./controller/search'), - require('./controller/predicates/has_data'), - require('./controller/predicates/has_errors'), + require('./controller/predicates/has_response_data'), + require('./controller/predicates/has_request_errors'), require('./controller/predicates/is_coarse_reverse'), require('./controller/predicates/is_pip_service_enabled'), require('./helper/diffPlaces'),