diff --git a/sanitizer/_geonames_deprecation.js b/sanitizer/_geonames_deprecation.js index b3cc8185..f6608e96 100644 --- a/sanitizer/_geonames_deprecation.js +++ b/sanitizer/_geonames_deprecation.js @@ -1,14 +1,25 @@ const _ = require('lodash'); /** -with the release of coarse reverse as a separate thing and ES reverse only -handling venues, addresses, and streets, geonames make no sense in the reverse context + * Now that we have the pip-service, we have stopped supporting returning Geonames for coarse reverse. + * + * However, until the `/nearby` endpoint is finalized, we still want to support Geonames for + * _non-coarse_ reverse. **/ function _sanitize( raw, clean, opts ) { // error & warning messages const messages = { errors: [], warnings: [] }; + // return taking no action unless this is a coarse-only reverse request + const non_coarse_layers = ['address', 'street', 'venue']; + const is_coarse_reverse = !_.isEmpty(clean.layers) && + _.isEmpty(_.intersection(clean.layers, non_coarse_layers)); + + if (!is_coarse_reverse) { + return messages; + } + if (_.isEqual(clean.sources, ['geonames']) || _.isEqual(clean.sources, ['gn'])) { messages.errors.push('/reverse does not support geonames'); diff --git a/test/unit/sanitizer/_geonames_deprecation.js b/test/unit/sanitizer/_geonames_deprecation.js index 41bd86c6..707c6774 100644 --- a/test/unit/sanitizer/_geonames_deprecation.js +++ b/test/unit/sanitizer/_geonames_deprecation.js @@ -27,13 +27,26 @@ module.exports.tests.no_warnings_or_errors_conditions = (test, common) => { }); + test('geonames/gn in sources with layers=venue should add neither warnings nor errors', (t) => { + const clean = { + sources: ['geonames'], + layers: ['venue'] + }; + + const messages = sanitizer.sanitize(undefined, clean); + + t.deepEquals(clean.sources, ['geonames']); + t.deepEquals(messages, { errors: [], warnings: [] }); + t.end(); + }); }; module.exports.tests.error_conditions = (test, common) => { - test('only geonames in sources should not modify clean.sources and add error message', (t) => { + test('only geonames in sources with layers=coarse should not modify clean.sources and add error message', (t) => { ['gn', 'geonames'].forEach((sources) => { const clean = { - sources: [sources] + sources: [sources], + layers: ['coarse'] }; const messages = sanitizer.sanitize(undefined, clean); @@ -45,16 +58,33 @@ module.exports.tests.error_conditions = (test, common) => { }); t.end(); - }); + test('only geonames in sources with layers=locality should not modify clean.sources and add error message', (t) => { + ['gn', 'geonames'].forEach((sources) => { + const clean = { + sources: [sources], + layers: ['locality'] + }; + + const messages = sanitizer.sanitize(undefined, clean); + + t.deepEquals(clean.sources, [sources]); + t.deepEquals(messages.errors, ['/reverse does not support geonames']); + t.deepEquals(messages.warnings, []); + + }); + + t.end(); + }); }; module.exports.tests.warning_conditions = (test, common) => { - test('only geonames in sources should not modify clean.sources and add error message', (t) => { + test('only geonames in sources and layers=coarse should not modify clean.sources and add error message', (t) => { ['gn', 'geonames'].forEach((sources) => { const clean = { - sources: ['another source', sources, 'yet another source'] + sources: ['another source', sources, 'yet another source'], + layers: ['coarse'] }; const messages = sanitizer.sanitize(undefined, clean);