From bc6401842c9046af3ea5984523f6b8d111becfb2 Mon Sep 17 00:00:00 2001 From: Julian Simioni Date: Mon, 23 Oct 2017 16:16:30 -0400 Subject: [PATCH] Add friendly, coarse specific error message to reverse This error message is updated to mention the coarse-reverse only nature of Geonames support removal. It also links to the [tracking ticket](https://github.com/pelias/acceptance-tests/pull/447) for Geonames removal which should help provide more context to users. --- sanitizer/_geonames_deprecation.js | 8 ++++---- test/unit/sanitizer/_geonames_deprecation.js | 8 +++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/sanitizer/_geonames_deprecation.js b/sanitizer/_geonames_deprecation.js index f6608e96..2cdef1d1 100644 --- a/sanitizer/_geonames_deprecation.js +++ b/sanitizer/_geonames_deprecation.js @@ -7,6 +7,8 @@ const _ = require('lodash'); * _non-coarse_ reverse. **/ +const coarse_reverse_message ='coarse /reverse does not support geonames. See https://github.com/pelias/pelias/issues/675 for more info'; + function _sanitize( raw, clean, opts ) { // error & warning messages const messages = { errors: [], warnings: [] }; @@ -15,18 +17,16 @@ function _sanitize( raw, clean, opts ) { 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'); + messages.errors.push(coarse_reverse_message); } else if (_.includes(clean.sources, 'geonames') || _.includes(clean.sources, 'gn')) { clean.sources = _.without(clean.sources, 'geonames', 'gn'); - messages.warnings.push('/reverse does not support geonames'); - + messages.warnings.push(coarse_reverse_message); } return messages; diff --git a/test/unit/sanitizer/_geonames_deprecation.js b/test/unit/sanitizer/_geonames_deprecation.js index 707c6774..13461e15 100644 --- a/test/unit/sanitizer/_geonames_deprecation.js +++ b/test/unit/sanitizer/_geonames_deprecation.js @@ -2,6 +2,8 @@ const sanitizer = require('../../../sanitizer/_geonames_deprecation')(); module.exports.tests = {}; +const coarse_reverse_message ='coarse /reverse does not support geonames. See https://github.com/pelias/pelias/issues/675 for more info'; + module.exports.tests.no_warnings_or_errors_conditions = (test, common) => { test('undefined sources should add neither warnings nor errors', (t) => { const clean = {}; @@ -52,7 +54,7 @@ module.exports.tests.error_conditions = (test, common) => { const messages = sanitizer.sanitize(undefined, clean); t.deepEquals(clean.sources, [sources]); - t.deepEquals(messages.errors, ['/reverse does not support geonames']); + t.deepEquals(messages.errors, [ coarse_reverse_message ]); t.deepEquals(messages.warnings, []); }); @@ -70,7 +72,7 @@ module.exports.tests.error_conditions = (test, common) => { const messages = sanitizer.sanitize(undefined, clean); t.deepEquals(clean.sources, [sources]); - t.deepEquals(messages.errors, ['/reverse does not support geonames']); + t.deepEquals(messages.errors, [ coarse_reverse_message ]); t.deepEquals(messages.warnings, []); }); @@ -91,7 +93,7 @@ module.exports.tests.warning_conditions = (test, common) => { t.deepEquals(clean.sources, ['another source', 'yet another source']); t.deepEquals(messages.errors, []); - t.deepEquals(messages.warnings, ['/reverse does not support geonames']); + t.deepEquals(messages.warnings, [ coarse_reverse_message ]); });