mirror of https://github.com/pelias/api.git
Julian Simioni
9 years ago
12 changed files with 184 additions and 33 deletions
@ -0,0 +1,41 @@
|
||||
var _ = require('lodash'); |
||||
|
||||
/** |
||||
In the process of phasing out the 'quattroshapes' source in favour of 'whosonfirst' |
||||
we will emit a warning to users so they can begin upgrading their clients. |
||||
|
||||
In the interim we will automatically rewrite all requests for quattroshapes to whosonfirst. |
||||
|
||||
@todo: this is only temporary |
||||
@see: https://github.com/pelias/api/issues/442
|
||||
**/ |
||||
|
||||
function sanitize( raw, clean, opts ) { |
||||
// error & warning messages
|
||||
var messages = { errors: [], warnings: [] }; |
||||
|
||||
// only applicably when 'sources' param is privided
|
||||
if( raw.hasOwnProperty('sources') ){ |
||||
|
||||
var sources = raw.sources.split(','); |
||||
if (_.includes(sources, 'quattroshapes') || _.includes(sources, 'qs')) { |
||||
|
||||
// emit a warning message so users can transition.
|
||||
messages.warnings.push('You are using Quattroshapes as a data source in this query. ' + |
||||
'Quattroshapes has been disabled as a data source for Mapzen Search, and has been' + |
||||
'replaced by Who\'s on First, an actively maintained data project based on Quattroshapes' + |
||||
'Your existing queries WILL CONTINUE TO WORK for the foreseeable future, but results will ' + |
||||
'be coming from Who\'s on First and `sources=quattroshapes` will be interpreted as ' + |
||||
'`sources=whosonfirst`. If you have any questions, please email search@mapzen.com.'); |
||||
|
||||
// user requested 'quattroshapes', we will give them 'whosonfirst' instead.
|
||||
sources = _.without(sources, 'quattroshapes', 'qs'); |
||||
sources.push('whosonfirst'); |
||||
raw.sources = sources.join(','); |
||||
} |
||||
} |
||||
|
||||
return messages; |
||||
} |
||||
|
||||
module.exports = sanitize; |
@ -1,25 +0,0 @@
|
||||
var _ = require('lodash'); |
||||
|
||||
function setup( paramName, targetMap ) { |
||||
return function( raw, clean ){ |
||||
return sanitize( raw, clean ); |
||||
}; |
||||
} |
||||
|
||||
function sanitize( raw, clean, opts ) { |
||||
// error & warning messages
|
||||
var messages = { errors: [], warnings: [] }; |
||||
|
||||
if (_.includes(raw.sources, 'quattroshapes') || _.includes(raw.sources, 'qs')) { |
||||
messages.warnings.push( 'You are using Quattroshapes as a data source in this query. ' + |
||||
'Quattroshapes will be disabled as a data source for Mapzen Search in the next several ' + |
||||
'weeks, and is being replaced by Who\'s on First, an actively maintained data project ' + |
||||
'based on Quattroshapes. Your existing queries WILL CONTINUE TO WORK for the foreseeable ' + |
||||
'future, but results will be coming from Who\'s on First and `sources=quattroshapes` will ' + |
||||
'be deprecated. If you have any questions, please email search@mapzen.com.'); |
||||
} |
||||
|
||||
return messages; |
||||
} |
||||
|
||||
module.exports = setup; |
@ -0,0 +1,34 @@
|
||||
|
||||
#> quattroshapes is being phased out and so should emit a warning message |
||||
path: '/v1/reverse?point.lat=1&point.lon=2&sources=qs' |
||||
|
||||
#? 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 ['You are using Quattroshapes as a data source in this query. Quattroshapes has been disabled as a data source for Mapzen Search, and has beenreplaced by Who\'s on First, an actively maintained data project based on QuattroshapesYour existing queries WILL CONTINUE TO WORK for the foreseeable future, but results will be coming from Who\'s on First and `sources=quattroshapes` will be interpreted as `sources=whosonfirst`. If you have any questions, please email search@mapzen.com.' ] |
||||
|
||||
#? inputs |
||||
json.geocoding.query['size'].should.eql 10 |
||||
json.geocoding.query.sources.should.eql ['whosonfirst'] # should use 'whosonfirst' instead of 'quattroshapes' |
@ -0,0 +1,35 @@
|
||||
|
||||
#> quattroshapes is being phased out and so should emit a warning message |
||||
path: '/v1/search?sources=qs&text=a' |
||||
|
||||
#? 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 ['You are using Quattroshapes as a data source in this query. Quattroshapes has been disabled as a data source for Mapzen Search, and has beenreplaced by Who\'s on First, an actively maintained data project based on QuattroshapesYour existing queries WILL CONTINUE TO WORK for the foreseeable future, but results will be coming from Who\'s on First and `sources=quattroshapes` will be interpreted as `sources=whosonfirst`. If you have any questions, please email search@mapzen.com.' ] |
||||
|
||||
#? inputs |
||||
json.geocoding.query['size'].should.eql 10 |
||||
json.geocoding.query['text'].should.eql 'a' |
||||
json.geocoding.query.sources.should.eql ['whosonfirst'] # should use 'whosonfirst' instead of 'quattroshapes' |
@ -0,0 +1,65 @@
|
||||
var sanitize = require('../../../sanitiser/_deprecate_quattroshapes'); |
||||
|
||||
module.exports.tests = {}; |
||||
|
||||
module.exports.tests.warning_message_1 = function(test, common) { |
||||
test('[qs] should emit a deprecation warning', function(t) { |
||||
var raw = { sources: 'qs' }; |
||||
var clean = {}; |
||||
|
||||
var messages = sanitize(raw, clean); |
||||
t.deepEquals(messages, { |
||||
errors: [], |
||||
warnings: ['You are using Quattroshapes as a data source in this query. ' + |
||||
'Quattroshapes has been disabled as a data source for Mapzen Search, and has been' + |
||||
'replaced by Who\'s on First, an actively maintained data project based on Quattroshapes' + |
||||
'Your existing queries WILL CONTINUE TO WORK for the foreseeable future, but results will ' + |
||||
'be coming from Who\'s on First and `sources=quattroshapes` will be interpreted as ' + |
||||
'`sources=whosonfirst`. If you have any questions, please email search@mapzen.com.'] |
||||
}, 'warning emitted'); |
||||
|
||||
t.end(); |
||||
}); |
||||
}; |
||||
|
||||
module.exports.tests.warning_message_2 = function(test, common) { |
||||
test('[quattroshapes] should emit a deprecation warning', function(t) { |
||||
var raw = { sources: 'quattroshapes' }; |
||||
var clean = {}; |
||||
|
||||
var messages = sanitize(raw, clean); |
||||
t.deepEquals(messages, { |
||||
errors: [], |
||||
warnings: ['You are using Quattroshapes as a data source in this query. ' + |
||||
'Quattroshapes has been disabled as a data source for Mapzen Search, and has been' + |
||||
'replaced by Who\'s on First, an actively maintained data project based on Quattroshapes' + |
||||
'Your existing queries WILL CONTINUE TO WORK for the foreseeable future, but results will ' + |
||||
'be coming from Who\'s on First and `sources=quattroshapes` will be interpreted as ' + |
||||
'`sources=whosonfirst`. If you have any questions, please email search@mapzen.com.'] |
||||
}, 'warning emitted'); |
||||
|
||||
t.end(); |
||||
}); |
||||
}; |
||||
|
||||
module.exports.tests.rewrite = function(test, common) { |
||||
test('should rewrite qs and quattroshapes to whosonfirst', function(t) { |
||||
var raw = { sources: 'qs,quattroshapes,qs,quattroshapes,osm' }; |
||||
var clean = {}; |
||||
|
||||
sanitize(raw, clean); |
||||
t.equals(raw.sources,'osm,whosonfirst','use wof instead of qs'); |
||||
|
||||
t.end(); |
||||
}); |
||||
}; |
||||
|
||||
module.exports.all = function (tape, common) { |
||||
function test(name, testFunction) { |
||||
return tape('SANTIZE _deprecate_quattroshapes ' + name, testFunction); |
||||
} |
||||
|
||||
for( var testCase in module.exports.tests ){ |
||||
module.exports.tests[testCase](test, common); |
||||
} |
||||
}; |
Loading…
Reference in new issue