mirror of https://github.com/pelias/api.git
Stephen K Hess
8 years ago
committed by
GitHub
19 changed files with 296 additions and 91 deletions
@ -0,0 +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 |
||||||
|
**/ |
||||||
|
|
||||||
|
function sanitize( raw, clean, opts ) { |
||||||
|
// error & warning messages
|
||||||
|
const messages = { errors: [], warnings: [] }; |
||||||
|
|
||||||
|
if (_.isEqual(clean.sources, ['geonames']) || _.isEqual(clean.sources, ['gn'])) { |
||||||
|
messages.errors.push('/reverse does not support geonames'); |
||||||
|
|
||||||
|
} 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'); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
return messages; |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
module.exports = sanitize; |
@ -0,0 +1,39 @@ |
|||||||
|
|
||||||
|
#> bounding circle |
||||||
|
path: '/v1/reverse?layers=coarse&point.lat=40.744243&point.lon=-73.990342&boundary.circle.radius=999.9' |
||||||
|
|
||||||
|
#? 200 ok |
||||||
|
response.statusCode.should.be.equal 200 |
||||||
|
response.should.have.header 'charset', 'utf8' |
||||||
|
response.should.have.header 'content-type', 'application/json; charset=utf-8' |
||||||
|
|
||||||
|
#? valid geocoding block |
||||||
|
should.exist json.geocoding |
||||||
|
should.exist json.geocoding.version |
||||||
|
should.exist json.geocoding.attribution |
||||||
|
should.exist json.geocoding.query |
||||||
|
should.exist json.geocoding.engine |
||||||
|
should.exist json.geocoding.engine.name |
||||||
|
should.exist json.geocoding.engine.author |
||||||
|
should.exist json.geocoding.engine.version |
||||||
|
should.exist json.geocoding.timestamp |
||||||
|
|
||||||
|
#? valid geojson |
||||||
|
json.type.should.be.equal 'FeatureCollection' |
||||||
|
json.features.should.be.instanceof Array |
||||||
|
|
||||||
|
#? expected errors |
||||||
|
should.not.exist json.geocoding.errors |
||||||
|
|
||||||
|
#? expected warnings |
||||||
|
should.exist json.geocoding.warnings |
||||||
|
json.geocoding.warnings.should.eql [ 'boundary.circle.radius is not applicable for coarse reverse' ] |
||||||
|
|
||||||
|
#? inputs |
||||||
|
json.geocoding.query['size'].should.eql 10 |
||||||
|
json.geocoding.query['layers'].should.eql 'coarse' |
||||||
|
json.geocoding.query['point.lat'].should.eql 40.744243 |
||||||
|
json.geocoding.query['point.lon'].should.eql -73.990342 |
||||||
|
json.geocoding.query['boundary.circle.lat'].should.eql 40.744243 |
||||||
|
json.geocoding.query['boundary.circle.lon'].should.eql -73.990342 |
||||||
|
json.geocoding.query['boundary.circle.radius'].should.eql 999.9 |
@ -0,0 +1,82 @@ |
|||||||
|
const geonames_deprecation = require('../../../sanitizer/_geonames_deprecation'); |
||||||
|
|
||||||
|
module.exports.tests = {}; |
||||||
|
|
||||||
|
module.exports.tests.no_warnings_or_errors_conditions = (test, common) => { |
||||||
|
test('undefined sources should add neither warnings nor errors', (t) => { |
||||||
|
const clean = {}; |
||||||
|
|
||||||
|
const messages = geonames_deprecation(undefined, clean); |
||||||
|
|
||||||
|
t.deepEquals(clean, {}); |
||||||
|
t.deepEquals(messages, { errors: [], warnings: [] }); |
||||||
|
t.end(); |
||||||
|
|
||||||
|
}); |
||||||
|
|
||||||
|
test('geonames/gn not in sources should add neither warnings nor errors', (t) => { |
||||||
|
const clean = { |
||||||
|
sources: ['source 1', 'source 2'], |
||||||
|
}; |
||||||
|
|
||||||
|
const messages = geonames_deprecation(undefined, clean); |
||||||
|
|
||||||
|
t.deepEquals(clean.sources, ['source 1', 'source 2']); |
||||||
|
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) => { |
||||||
|
['gn', 'geonames'].forEach((sources) => { |
||||||
|
const clean = { |
||||||
|
sources: [sources] |
||||||
|
}; |
||||||
|
|
||||||
|
const messages = geonames_deprecation(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) => { |
||||||
|
['gn', 'geonames'].forEach((sources) => { |
||||||
|
const clean = { |
||||||
|
sources: ['another source', sources, 'yet another source'] |
||||||
|
}; |
||||||
|
|
||||||
|
const messages = geonames_deprecation(undefined, clean); |
||||||
|
|
||||||
|
t.deepEquals(clean.sources, ['another source', 'yet another source']); |
||||||
|
t.deepEquals(messages.errors, []); |
||||||
|
t.deepEquals(messages.warnings, ['/reverse does not support geonames']); |
||||||
|
|
||||||
|
}); |
||||||
|
|
||||||
|
t.end(); |
||||||
|
|
||||||
|
}); |
||||||
|
|
||||||
|
}; |
||||||
|
|
||||||
|
module.exports.all = (tape, common) => { |
||||||
|
function test(name, testFunction) { |
||||||
|
return tape(`SANTIZE _geonames_deprecation ${name}`, testFunction); |
||||||
|
} |
||||||
|
|
||||||
|
for( var testCase in module.exports.tests ){ |
||||||
|
module.exports.tests[testCase](test, common); |
||||||
|
} |
||||||
|
}; |
Loading…
Reference in new issue