Browse Source

feat: Merge pull request #854 from pelias/pass-do-not-track-to-service

actually pass do-not-track flag to service
pull/855/head v3.25.0
Stephen K Hess 8 years ago committed by GitHub
parent
commit
51f8b4eace
  1. 3
      controller/coarse_reverse.js
  2. 60
      test/unit/controller/coarse_reverse.js

3
controller/coarse_reverse.js

@ -1,6 +1,7 @@
const logger = require('pelias-logger').get('coarse_reverse'); const logger = require('pelias-logger').get('coarse_reverse');
const _ = require('lodash'); const _ = require('lodash');
const Document = require('pelias-model').Document; const Document = require('pelias-model').Document;
const isDNT = require('../helper/logging').isDNT;
const granularities = [ const granularities = [
'neighbourhood', 'neighbourhood',
@ -88,7 +89,7 @@ function setup(service, should_execute) {
lon: req.clean['point.lon'] lon: req.clean['point.lon']
}; };
service(centroid, (err, results) => { service(centroid, isDNT(req), (err, results) => {
// if there's an error, log it and bail // if there's an error, log it and bail
if (err) { if (err) {
logger.error(err); logger.error(err);

60
test/unit/controller/coarse_reverse.js

@ -46,7 +46,8 @@ module.exports.tests.early_exit_conditions = (test, common) => {
module.exports.tests.error_conditions = (test, common) => { module.exports.tests.error_conditions = (test, common) => {
test('service error should log and call next', (t) => { test('service error should log and call next', (t) => {
const service = (point, callback) => { const service = (point, do_not_track, callback) => {
t.equals(do_not_track, 'do_not_track value');
callback('this is an error'); callback('this is an error');
}; };
@ -54,7 +55,12 @@ module.exports.tests.error_conditions = (test, common) => {
const should_execute = () => { return true; }; const should_execute = () => { return true; };
const controller = proxyquire('../../../controller/coarse_reverse', { const controller = proxyquire('../../../controller/coarse_reverse', {
'pelias-logger': logger 'pelias-logger': logger,
'../helper/logging': {
isDNT: () => {
return 'do_not_track value';
}
}
})(service, should_execute); })(service, should_execute);
const req = { const req = {
@ -86,7 +92,8 @@ module.exports.tests.error_conditions = (test, common) => {
module.exports.tests.success_conditions = (test, common) => { module.exports.tests.success_conditions = (test, common) => {
test('service returning results should use first entry for each layer', (t) => { test('service returning results should use first entry for each layer', (t) => {
const service = (point, callback) => { const service = (point, do_not_track, callback) => {
t.equals(do_not_track, 'do_not_track value');
const results = { const results = {
neighbourhood: [ neighbourhood: [
{ {
@ -146,7 +153,12 @@ module.exports.tests.success_conditions = (test, common) => {
const should_execute = () => { return true; }; const should_execute = () => { return true; };
const controller = proxyquire('../../../controller/coarse_reverse', { const controller = proxyquire('../../../controller/coarse_reverse', {
'pelias-logger': logger 'pelias-logger': logger,
'../helper/logging': {
isDNT: () => {
return 'do_not_track value';
}
}
})(service, should_execute); })(service, should_execute);
const req = { const req = {
@ -235,7 +247,8 @@ module.exports.tests.success_conditions = (test, common) => {
}); });
test('layers missing from results should be ignored', (t) => { test('layers missing from results should be ignored', (t) => {
const service = (point, callback) => { const service = (point, do_not_track, callback) => {
t.equals(do_not_track, 'do_not_track value');
const results = { const results = {
neighbourhood: [ neighbourhood: [
{ {
@ -258,7 +271,12 @@ module.exports.tests.success_conditions = (test, common) => {
const should_execute = () => { return true; }; const should_execute = () => { return true; };
const controller = proxyquire('../../../controller/coarse_reverse', { const controller = proxyquire('../../../controller/coarse_reverse', {
'pelias-logger': logger 'pelias-logger': logger,
'../helper/logging': {
isDNT: () => {
return 'do_not_track value';
}
}
})(service, should_execute); })(service, should_execute);
const req = { const req = {
@ -319,7 +337,8 @@ module.exports.tests.success_conditions = (test, common) => {
}); });
test('most granular layer missing centroid should not set', (t) => { test('most granular layer missing centroid should not set', (t) => {
const service = (point, callback) => { const service = (point, do_not_track, callback) => {
t.equals(do_not_track, 'do_not_track value');
const results = { const results = {
neighbourhood: [ neighbourhood: [
{ {
@ -338,7 +357,12 @@ module.exports.tests.success_conditions = (test, common) => {
const should_execute = () => { return true; }; const should_execute = () => { return true; };
const controller = proxyquire('../../../controller/coarse_reverse', { const controller = proxyquire('../../../controller/coarse_reverse', {
'pelias-logger': logger 'pelias-logger': logger,
'../helper/logging': {
isDNT: () => {
return 'do_not_track value';
}
}
})(service, should_execute); })(service, should_execute);
const req = { const req = {
@ -395,7 +419,8 @@ module.exports.tests.success_conditions = (test, common) => {
}); });
test('most granular layer missing bounding_box should not set', (t) => { test('most granular layer missing bounding_box should not set', (t) => {
const service = (point, callback) => { const service = (point, do_not_track, callback) => {
t.equals(do_not_track, 'do_not_track value');
const results = { const results = {
neighbourhood: [ neighbourhood: [
{ {
@ -417,7 +442,12 @@ module.exports.tests.success_conditions = (test, common) => {
const should_execute = () => { return true; }; const should_execute = () => { return true; };
const controller = proxyquire('../../../controller/coarse_reverse', { const controller = proxyquire('../../../controller/coarse_reverse', {
'pelias-logger': logger 'pelias-logger': logger,
'../helper/logging': {
isDNT: () => {
return 'do_not_track value';
}
}
})(service, should_execute); })(service, should_execute);
const req = { const req = {
@ -480,7 +510,8 @@ module.exports.tests.success_conditions = (test, common) => {
module.exports.tests.failure_conditions = (test, common) => { module.exports.tests.failure_conditions = (test, common) => {
test('service returning 0 results at the requested layer should return nothing', (t) => { test('service returning 0 results at the requested layer should return nothing', (t) => {
const service = (point, callback) => { const service = (point, do_not_track, callback) => {
t.equals(do_not_track, 'do_not_track value');
// response without neighbourhood results // response without neighbourhood results
const results = { const results = {
borough: [ borough: [
@ -528,7 +559,12 @@ module.exports.tests.failure_conditions = (test, common) => {
const should_execute = () => { return true; }; const should_execute = () => { return true; };
const controller = proxyquire('../../../controller/coarse_reverse', { const controller = proxyquire('../../../controller/coarse_reverse', {
'pelias-logger': logger 'pelias-logger': logger,
'../helper/logging': {
isDNT: () => {
return 'do_not_track value';
}
}
})(service, should_execute); })(service, should_execute);
const req = { const req = {

Loading…
Cancel
Save