Browse Source

renamed predicates to be more accurate

pull/810/head
Stephen Hess 8 years ago
parent
commit
f06704985e
  1. 0
      controller/predicates/has_request_errors.js
  2. 0
      controller/predicates/has_response_data.js
  3. 20
      routes/v1.js
  4. 12
      test/unit/controller/predicates/has_request_errors.js
  5. 12
      test/unit/controller/predicates/has_response_data.js
  6. 4
      test/unit/run.js

0
controller/predicates/has_errors.js → controller/predicates/has_request_errors.js

0
controller/predicates/has_data.js → controller/predicates/has_response_data.js

20
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

12
test/unit/controller/predicates/has_errors.js → 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 ){

12
test/unit/controller/predicates/has_data.js → 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 ){

4
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'),

Loading…
Cancel
Save