Browse Source

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.
pull/1045/head
Julian Simioni 7 years ago
parent
commit
bc6401842c
No known key found for this signature in database
GPG Key ID: 6DAD08919FDBF563
  1. 8
      sanitizer/_geonames_deprecation.js
  2. 8
      test/unit/sanitizer/_geonames_deprecation.js

8
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;

8
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 ]);
});

Loading…
Cancel
Save