|
|
|
@ -2,6 +2,7 @@
|
|
|
|
|
|
|
|
|
|
const setup = require('../../../controller/coarse_reverse'); |
|
|
|
|
const proxyquire = require('proxyquire').noCallThru(); |
|
|
|
|
const _ = require('lodash'); |
|
|
|
|
|
|
|
|
|
module.exports.tests = {}; |
|
|
|
|
|
|
|
|
@ -15,12 +16,13 @@ module.exports.tests.interface = (test, common) => {
|
|
|
|
|
|
|
|
|
|
module.exports.tests.early_exit_conditions = (test, common) => { |
|
|
|
|
test('should_execute returning false should not call service', (t) => { |
|
|
|
|
t.plan(2); |
|
|
|
|
|
|
|
|
|
const service = () => { |
|
|
|
|
throw Error('service should not have been called'); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const should_execute = () => { return false; }; |
|
|
|
|
const controller = setup(service, should_execute); |
|
|
|
|
const controller = setup(service, _.constant(false)); |
|
|
|
|
|
|
|
|
|
const req = { |
|
|
|
|
clean: { |
|
|
|
@ -30,14 +32,12 @@ module.exports.tests.early_exit_conditions = (test, common) => {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// verify that next was called
|
|
|
|
|
let next_was_called = false; |
|
|
|
|
const next = () => { |
|
|
|
|
next_was_called = true; |
|
|
|
|
t.pass('next() was called'); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// passing res=undefined verifies that it wasn't interacted with
|
|
|
|
|
t.doesNotThrow(controller.bind(null, req, undefined, next)); |
|
|
|
|
t.ok(next_was_called); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
@ -46,6 +46,8 @@ module.exports.tests.early_exit_conditions = (test, common) => {
|
|
|
|
|
|
|
|
|
|
module.exports.tests.error_conditions = (test, common) => { |
|
|
|
|
test('service error should log and call next', (t) => { |
|
|
|
|
t.plan(3); |
|
|
|
|
|
|
|
|
|
const service = (req, callback) => { |
|
|
|
|
t.deepEquals(req, { clean: { layers: ['locality'] } } ); |
|
|
|
|
callback('this is an error'); |
|
|
|
@ -53,10 +55,9 @@ module.exports.tests.error_conditions = (test, common) => {
|
|
|
|
|
|
|
|
|
|
const logger = require('pelias-mock-logger')(); |
|
|
|
|
|
|
|
|
|
const should_execute = () => { return true; }; |
|
|
|
|
const controller = proxyquire('../../../controller/coarse_reverse', { |
|
|
|
|
'pelias-logger': logger |
|
|
|
|
})(service, should_execute); |
|
|
|
|
})(service, _.constant(true)); |
|
|
|
|
|
|
|
|
|
const req = { |
|
|
|
|
clean: { |
|
|
|
@ -65,16 +66,14 @@ module.exports.tests.error_conditions = (test, common) => {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// verify that next was called
|
|
|
|
|
let next_was_called = false; |
|
|
|
|
const next = () => { |
|
|
|
|
next_was_called = true; |
|
|
|
|
t.pass('next() was called'); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
// passing res=undefined verifies that it wasn't interacted with
|
|
|
|
|
controller(req, undefined, next); |
|
|
|
|
|
|
|
|
|
t.ok(logger.isErrorMessage('this is an error')); |
|
|
|
|
t.ok(next_was_called); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
@ -83,6 +82,8 @@ module.exports.tests.error_conditions = (test, common) => {
|
|
|
|
|
|
|
|
|
|
module.exports.tests.success_conditions = (test, common) => { |
|
|
|
|
test('service returning results should use first entry for each layer', (t) => { |
|
|
|
|
t.plan(4); |
|
|
|
|
|
|
|
|
|
const service = (req, callback) => { |
|
|
|
|
t.deepEquals(req, { clean: { layers: ['neighbourhood'] } } ); |
|
|
|
|
|
|
|
|
@ -143,10 +144,9 @@ module.exports.tests.success_conditions = (test, common) => {
|
|
|
|
|
|
|
|
|
|
const logger = require('pelias-mock-logger')(); |
|
|
|
|
|
|
|
|
|
const should_execute = () => { return true; }; |
|
|
|
|
const controller = proxyquire('../../../controller/coarse_reverse', { |
|
|
|
|
'pelias-logger': logger |
|
|
|
|
})(service, should_execute); |
|
|
|
|
})(service, _.constant(true)); |
|
|
|
|
|
|
|
|
|
const req = { |
|
|
|
|
clean: { |
|
|
|
@ -157,9 +157,8 @@ module.exports.tests.success_conditions = (test, common) => {
|
|
|
|
|
const res = { }; |
|
|
|
|
|
|
|
|
|
// verify that next was called
|
|
|
|
|
let next_was_called = false; |
|
|
|
|
const next = () => { |
|
|
|
|
next_was_called = true; |
|
|
|
|
t.pass('next() was called'); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
controller(req, res, next); |
|
|
|
@ -221,14 +220,14 @@ module.exports.tests.success_conditions = (test, common) => {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
t.deepEquals(res, expected); |
|
|
|
|
|
|
|
|
|
t.notOk(logger.hasErrorMessages()); |
|
|
|
|
t.ok(next_was_called); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('layers missing from results should be ignored', (t) => { |
|
|
|
|
t.plan(4); |
|
|
|
|
|
|
|
|
|
const service = (req, callback) => { |
|
|
|
|
t.deepEquals(req, { clean: { layers: ['neighbourhood'] } } ); |
|
|
|
|
|
|
|
|
@ -251,10 +250,9 @@ module.exports.tests.success_conditions = (test, common) => {
|
|
|
|
|
|
|
|
|
|
const logger = require('pelias-mock-logger')(); |
|
|
|
|
|
|
|
|
|
const should_execute = () => { return true; }; |
|
|
|
|
const controller = proxyquire('../../../controller/coarse_reverse', { |
|
|
|
|
'pelias-logger': logger |
|
|
|
|
})(service, should_execute); |
|
|
|
|
})(service, _.constant(true)); |
|
|
|
|
|
|
|
|
|
const req = { |
|
|
|
|
clean: { |
|
|
|
@ -265,9 +263,8 @@ module.exports.tests.success_conditions = (test, common) => {
|
|
|
|
|
const res = { }; |
|
|
|
|
|
|
|
|
|
// verify that next was called
|
|
|
|
|
let next_was_called = false; |
|
|
|
|
const next = () => { |
|
|
|
|
next_was_called = true; |
|
|
|
|
t.pass('next() was called'); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
controller(req, res, next); |
|
|
|
@ -302,14 +299,14 @@ module.exports.tests.success_conditions = (test, common) => {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
t.deepEquals(res, expected); |
|
|
|
|
|
|
|
|
|
t.notOk(logger.hasErrorMessages()); |
|
|
|
|
t.ok(next_was_called); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('most granular layer missing centroid should not set', (t) => { |
|
|
|
|
t.plan(4); |
|
|
|
|
|
|
|
|
|
const service = (req, callback) => { |
|
|
|
|
t.deepEquals(req, { clean: { layers: ['neighbourhood'] } } ); |
|
|
|
|
|
|
|
|
@ -329,10 +326,9 @@ module.exports.tests.success_conditions = (test, common) => {
|
|
|
|
|
|
|
|
|
|
const logger = require('pelias-mock-logger')(); |
|
|
|
|
|
|
|
|
|
const should_execute = () => { return true; }; |
|
|
|
|
const controller = proxyquire('../../../controller/coarse_reverse', { |
|
|
|
|
'pelias-logger': logger |
|
|
|
|
})(service, should_execute); |
|
|
|
|
})(service, _.constant(true)); |
|
|
|
|
|
|
|
|
|
const req = { |
|
|
|
|
clean: { |
|
|
|
@ -343,9 +339,8 @@ module.exports.tests.success_conditions = (test, common) => {
|
|
|
|
|
const res = { }; |
|
|
|
|
|
|
|
|
|
// verify that next was called
|
|
|
|
|
let next_was_called = false; |
|
|
|
|
const next = () => { |
|
|
|
|
next_was_called = true; |
|
|
|
|
t.pass('next() was called'); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
controller(req, res, next); |
|
|
|
@ -376,14 +371,14 @@ module.exports.tests.success_conditions = (test, common) => {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
t.deepEquals(res, expected); |
|
|
|
|
|
|
|
|
|
t.notOk(logger.hasErrorMessages()); |
|
|
|
|
t.ok(next_was_called); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('most granular layer missing bounding_box should not set', (t) => { |
|
|
|
|
t.plan(4); |
|
|
|
|
|
|
|
|
|
const service = (req, callback) => { |
|
|
|
|
t.deepEquals(req, { clean: { layers: ['neighbourhood'] } } ); |
|
|
|
|
|
|
|
|
@ -406,10 +401,9 @@ module.exports.tests.success_conditions = (test, common) => {
|
|
|
|
|
|
|
|
|
|
const logger = require('pelias-mock-logger')(); |
|
|
|
|
|
|
|
|
|
const should_execute = () => { return true; }; |
|
|
|
|
const controller = proxyquire('../../../controller/coarse_reverse', { |
|
|
|
|
'pelias-logger': logger |
|
|
|
|
})(service, should_execute); |
|
|
|
|
})(service, _.constant(true)); |
|
|
|
|
|
|
|
|
|
const req = { |
|
|
|
|
clean: { |
|
|
|
@ -420,9 +414,8 @@ module.exports.tests.success_conditions = (test, common) => {
|
|
|
|
|
const res = { }; |
|
|
|
|
|
|
|
|
|
// verify that next was called
|
|
|
|
|
let next_was_called = false; |
|
|
|
|
const next = () => { |
|
|
|
|
next_was_called = true; |
|
|
|
|
t.pass('next() was called'); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
controller(req, res, next); |
|
|
|
@ -456,9 +449,7 @@ module.exports.tests.success_conditions = (test, common) => {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
t.deepEquals(res, expected); |
|
|
|
|
|
|
|
|
|
t.notOk(logger.hasErrorMessages()); |
|
|
|
|
t.ok(next_was_called); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
@ -469,10 +460,9 @@ module.exports.tests.success_conditions = (test, common) => {
|
|
|
|
|
|
|
|
|
|
// by plan'ing the number of tests, we can verify that next() was called w/o
|
|
|
|
|
// additional bookkeeping
|
|
|
|
|
t.plan(5); |
|
|
|
|
t.plan(4); |
|
|
|
|
|
|
|
|
|
const service = (point, do_not_track, callback) => { |
|
|
|
|
t.equals(do_not_track, 'do_not_track value'); |
|
|
|
|
const service = (req, callback) => { |
|
|
|
|
const results = { |
|
|
|
|
neighbourhood: [ |
|
|
|
|
{ |
|
|
|
@ -488,15 +478,9 @@ module.exports.tests.success_conditions = (test, common) => {
|
|
|
|
|
|
|
|
|
|
const logger = require('pelias-mock-logger')(); |
|
|
|
|
|
|
|
|
|
const should_execute = () => { return true; }; |
|
|
|
|
const controller = proxyquire('../../../controller/coarse_reverse', { |
|
|
|
|
'pelias-logger': logger, |
|
|
|
|
'../helper/logging': { |
|
|
|
|
isDNT: () => { |
|
|
|
|
return 'do_not_track value'; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
})(service, should_execute); |
|
|
|
|
'pelias-logger': logger |
|
|
|
|
})(service, _.constant(true)); |
|
|
|
|
|
|
|
|
|
const req = { |
|
|
|
|
clean: { |
|
|
|
@ -553,15 +537,14 @@ module.exports.tests.success_conditions = (test, common) => {
|
|
|
|
|
// this test is used to test coarse reverse fallback for when non-coarse reverse
|
|
|
|
|
// was requested but no non-coarse results were found
|
|
|
|
|
const non_coarse_layers = ['venue', 'address', 'street']; |
|
|
|
|
const tests_per_non_coarse_layer = 5; |
|
|
|
|
const tests_per_non_coarse_layer = 4; |
|
|
|
|
|
|
|
|
|
// by plan'ing the number of tests, we can verify that next() was called w/o
|
|
|
|
|
// additional bookkeeping
|
|
|
|
|
t.plan(non_coarse_layers.length * tests_per_non_coarse_layer); |
|
|
|
|
|
|
|
|
|
non_coarse_layers.forEach((non_coarse_layer) => { |
|
|
|
|
const service = (point, do_not_track, callback) => { |
|
|
|
|
t.equals(do_not_track, 'do_not_track value'); |
|
|
|
|
const service = (req, callback) => { |
|
|
|
|
const results = { |
|
|
|
|
neighbourhood: [ |
|
|
|
|
{ |
|
|
|
@ -577,15 +560,9 @@ module.exports.tests.success_conditions = (test, common) => {
|
|
|
|
|
|
|
|
|
|
const logger = require('pelias-mock-logger')(); |
|
|
|
|
|
|
|
|
|
const should_execute = () => { return true; }; |
|
|
|
|
const controller = proxyquire('../../../controller/coarse_reverse', { |
|
|
|
|
'pelias-logger': logger, |
|
|
|
|
'../helper/logging': { |
|
|
|
|
isDNT: () => { |
|
|
|
|
return 'do_not_track value'; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
})(service, should_execute); |
|
|
|
|
'pelias-logger': logger |
|
|
|
|
})(service, _.constant(true)); |
|
|
|
|
|
|
|
|
|
const req = { |
|
|
|
|
clean: { |
|
|
|
@ -644,15 +621,14 @@ module.exports.tests.success_conditions = (test, common) => {
|
|
|
|
|
// this test is used to test coarse reverse fallback for when non-coarse reverse
|
|
|
|
|
// was requested but no non-coarse results were found
|
|
|
|
|
const non_coarse_layers = ['venue', 'address', 'street']; |
|
|
|
|
const tests_per_non_coarse_layer = 5; |
|
|
|
|
const tests_per_non_coarse_layer = 4; |
|
|
|
|
|
|
|
|
|
// by plan'ing the number of tests, we can verify that next() was called w/o
|
|
|
|
|
// additional bookkeeping
|
|
|
|
|
t.plan(non_coarse_layers.length * tests_per_non_coarse_layer); |
|
|
|
|
|
|
|
|
|
non_coarse_layers.forEach((non_coarse_layer) => { |
|
|
|
|
const service = (point, do_not_track, callback) => { |
|
|
|
|
t.equals(do_not_track, 'do_not_track value'); |
|
|
|
|
const service = (req, callback) => { |
|
|
|
|
const results = { |
|
|
|
|
neighbourhood: [ |
|
|
|
|
{ |
|
|
|
@ -668,15 +644,9 @@ module.exports.tests.success_conditions = (test, common) => {
|
|
|
|
|
|
|
|
|
|
const logger = require('pelias-mock-logger')(); |
|
|
|
|
|
|
|
|
|
const should_execute = () => { return true; }; |
|
|
|
|
const controller = proxyquire('../../../controller/coarse_reverse', { |
|
|
|
|
'pelias-logger': logger, |
|
|
|
|
'../helper/logging': { |
|
|
|
|
isDNT: () => { |
|
|
|
|
return 'do_not_track value'; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
})(service, should_execute); |
|
|
|
|
'pelias-logger': logger |
|
|
|
|
})(service, _.constant(true)); |
|
|
|
|
|
|
|
|
|
const req = { |
|
|
|
|
clean: { |
|
|
|
@ -735,6 +705,8 @@ module.exports.tests.success_conditions = (test, common) => {
|
|
|
|
|
|
|
|
|
|
module.exports.tests.failure_conditions = (test, common) => { |
|
|
|
|
test('service returning 0 results at the requested layer should return nothing', (t) => { |
|
|
|
|
t.plan(4); |
|
|
|
|
|
|
|
|
|
const service = (req, callback) => { |
|
|
|
|
t.deepEquals(req, { clean: { layers: ['neighbourhood'] } } ); |
|
|
|
|
|
|
|
|
@ -783,10 +755,9 @@ module.exports.tests.failure_conditions = (test, common) => {
|
|
|
|
|
|
|
|
|
|
const logger = require('pelias-mock-logger')(); |
|
|
|
|
|
|
|
|
|
const should_execute = () => { return true; }; |
|
|
|
|
const controller = proxyquire('../../../controller/coarse_reverse', { |
|
|
|
|
'pelias-logger': logger |
|
|
|
|
})(service, should_execute); |
|
|
|
|
})(service, _.constant(true)); |
|
|
|
|
|
|
|
|
|
const req = { |
|
|
|
|
clean: { |
|
|
|
@ -797,9 +768,8 @@ module.exports.tests.failure_conditions = (test, common) => {
|
|
|
|
|
const res = { }; |
|
|
|
|
|
|
|
|
|
// verify that next was called
|
|
|
|
|
let next_was_called = false; |
|
|
|
|
const next = () => { |
|
|
|
|
next_was_called = true; |
|
|
|
|
t.pass('next() was called'); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
controller(req, res, next); |
|
|
|
@ -810,9 +780,7 @@ module.exports.tests.failure_conditions = (test, common) => {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
t.deepEquals(res, expected); |
|
|
|
|
|
|
|
|
|
t.notOk(logger.hasErrorMessages()); |
|
|
|
|
t.ok(next_was_called); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|