diff --git a/controller/place.js b/controller/place.js index 97461e71..8622f234 100644 --- a/controller/place.js +++ b/controller/place.js @@ -22,11 +22,15 @@ function setup( backend ){ }); service.mget( backend, query, function( err, docs ) { - // error handler - if( err ){ return next( err ); } + // error handler + if( err ){ + req.errors.push( err.message ? err.message : err ); + } // set response data - res.data = docs; + else { + res.data = docs; + } next(); }); diff --git a/controller/search.js b/controller/search.js index 2495c37a..28fa3837 100644 --- a/controller/search.js +++ b/controller/search.js @@ -30,11 +30,13 @@ function setup( backend, query ){ service.search( backend, cmd, function( err, docs, meta ){ // error handler - if( err ){ return next( err ); } - + if( err ){ + req.errors.push( err.message ? err.message : err ); + } // set response data - res.data = docs; - res.meta = meta; + else { + res.data = docs; + } next(); }); diff --git a/query/autocomplete.js b/query/autocomplete.js index 5c956785..7d45aea3 100644 --- a/query/autocomplete.js +++ b/query/autocomplete.js @@ -32,7 +32,8 @@ function generateQuery( clean ){ vs.var( 'size', 10 ); // focus point - if( check.number(clean['focus.point.lat']) && check.number(clean['focus.point.lon']) ){ + if( check.number(clean['focus.point.lat']) && + check.number(clean['focus.point.lon']) ){ vs.set({ 'focus:point:lat': clean['focus.point.lat'], 'focus:point:lon': clean['focus.point.lon'] diff --git a/sanitiser/_geo_autocomplete.js b/sanitiser/_geo_autocomplete.js index b053e4b7..04fc0b0d 100644 --- a/sanitiser/_geo_autocomplete.js +++ b/sanitiser/_geo_autocomplete.js @@ -8,8 +8,7 @@ module.exports = function sanitize( raw, clean ){ var messages = { errors: [], warnings: [] }; try { - geo_common.sanitize_coord( 'focus.point.lat', clean, raw['focus.point.lat'], LAT_LON_IS_REQUIRED ); - geo_common.sanitize_coord( 'focus.point.lon', clean, raw['focus.point.lon'], LAT_LON_IS_REQUIRED ); + geo_common.sanitize_point( 'focus.point', clean, raw, LAT_LON_IS_REQUIRED ); } catch (err) { messages.errors.push( err.message ); diff --git a/test/ciao/autocomplete/focus_point_invalid_lat.coffee b/test/ciao/autocomplete/focus_point_invalid_lat.coffee new file mode 100644 index 00000000..37a86593 --- /dev/null +++ b/test/ciao/autocomplete/focus_point_invalid_lat.coffee @@ -0,0 +1,36 @@ + +#> focus point +path: '/v1/autocomplete?text=a&focus.point.lat=foo&focus.point.lon=-73.990342' + +#? 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.exist json.geocoding.errors +json.geocoding.errors.should.eql [ 'missing param \'focus.point.lat\'' ] + +#? expected warnings +should.not.exist json.geocoding.warnings + +#? inputs +json.geocoding.query['text'].should.eql 'a' +json.geocoding.query['size'].should.eql 10 +should.not.exist json.geocoding.query['focus.point.lat'] +should.not.exist json.geocoding.query['focus.point.lon'] \ No newline at end of file diff --git a/test/ciao/autocomplete/focus_point_invalid_lon.coffee b/test/ciao/autocomplete/focus_point_invalid_lon.coffee new file mode 100644 index 00000000..74779437 --- /dev/null +++ b/test/ciao/autocomplete/focus_point_invalid_lon.coffee @@ -0,0 +1,36 @@ + +#> focus point +path: '/v1/autocomplete?text=a&focus.point.lat=40.744243&focus.point.lon=' + +#? 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.exist json.geocoding.errors +json.geocoding.errors.should.eql [ 'missing param \'focus.point.lon\'' ] + +#? expected warnings +should.not.exist json.geocoding.warnings + +#? inputs +json.geocoding.query['text'].should.eql 'a' +json.geocoding.query['size'].should.eql 10 +json.geocoding.query['focus.point.lat'].should.eql 40.744243 +should.not.exist json.geocoding.query['focus.point.lon'] \ No newline at end of file diff --git a/test/ciao/autocomplete/focus_point_missing_lat.coffee b/test/ciao/autocomplete/focus_point_missing_lat.coffee new file mode 100644 index 00000000..a3da2f8a --- /dev/null +++ b/test/ciao/autocomplete/focus_point_missing_lat.coffee @@ -0,0 +1,36 @@ + +#> focus point +path: '/v1/autocomplete?text=a&focus.point.lon=-73.990342' + +#? 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.exist json.geocoding.errors +json.geocoding.errors.should.eql [ 'missing point param \'focus.point\' requires all of: \'lat\',\'lon\' to be present' ] + +#? expected warnings +should.not.exist json.geocoding.warnings + +#? inputs +json.geocoding.query['text'].should.eql 'a' +json.geocoding.query['size'].should.eql 10 +should.not.exist json.geocoding.query['focus.point.lat'] +should.not.exist json.geocoding.query['focus.point.lon'] \ No newline at end of file diff --git a/test/ciao/autocomplete/focus_point_missing_lon.coffee b/test/ciao/autocomplete/focus_point_missing_lon.coffee new file mode 100644 index 00000000..8c9a8f48 --- /dev/null +++ b/test/ciao/autocomplete/focus_point_missing_lon.coffee @@ -0,0 +1,36 @@ + +#> focus point +path: '/v1/autocomplete?text=a&focus.point.lat=40.744243' + +#? 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.exist json.geocoding.errors +json.geocoding.errors.should.eql [ 'missing point param \'focus.point\' requires all of: \'lat\',\'lon\' to be present' ] + +#? expected warnings +should.not.exist json.geocoding.warnings + +#? inputs +json.geocoding.query['text'].should.eql 'a' +json.geocoding.query['size'].should.eql 10 +should.not.exist json.geocoding.query['focus.point.lat'] +should.not.exist json.geocoding.query['focus.point.lon'] \ No newline at end of file diff --git a/test/ciao/autocomplete/null_island.coffee b/test/ciao/autocomplete/focus_point_null_island.coffee similarity index 88% rename from test/ciao/autocomplete/null_island.coffee rename to test/ciao/autocomplete/focus_point_null_island.coffee index 10331700..e0911b5b 100644 --- a/test/ciao/autocomplete/null_island.coffee +++ b/test/ciao/autocomplete/focus_point_null_island.coffee @@ -1,5 +1,5 @@ -#> null island +#> focus point null island path: '/v1/autocomplete?text=a&focus.point.lat=0&focus.point.lon=0' #? 200 ok @@ -30,6 +30,6 @@ should.not.exist json.geocoding.warnings #? inputs json.geocoding.query['text'].should.eql 'a' +json.geocoding.query['size'].should.eql 10 json.geocoding.query['focus.point.lat'].should.eql 0 -json.geocoding.query['focus.point.lon'].should.eql 0 -json.geocoding.query['size'].should.eql 10 \ No newline at end of file +json.geocoding.query['focus.point.lon'].should.eql 0 \ No newline at end of file diff --git a/test/ciao/autocomplete/focus_point_valid_duo.coffee b/test/ciao/autocomplete/focus_point_valid_duo.coffee new file mode 100644 index 00000000..2395fe10 --- /dev/null +++ b/test/ciao/autocomplete/focus_point_valid_duo.coffee @@ -0,0 +1,35 @@ + +#> focus point +path: '/v1/autocomplete?text=a&focus.point.lat=40.744243&focus.point.lon=-73.990342' + +#? 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.not.exist json.geocoding.warnings + +#? inputs +json.geocoding.query['text'].should.eql 'a' +json.geocoding.query['size'].should.eql 10 +json.geocoding.query['focus.point.lat'].should.eql 40.744243 +json.geocoding.query['focus.point.lon'].should.eql -73.990342 \ No newline at end of file diff --git a/test/ciao/autocomplete/no_params.coffee b/test/ciao/autocomplete/no_params.coffee new file mode 100644 index 00000000..5feb9923 --- /dev/null +++ b/test/ciao/autocomplete/no_params.coffee @@ -0,0 +1,33 @@ + +#> no params specified +path: '/v1/autocomplete' + +#? 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.exist json.geocoding.errors +json.geocoding.errors.should.eql [ 'invalid param \'text\': text length, must be >0' ] + +#? expected warnings +should.not.exist json.geocoding.warnings + +#? inputs +json.geocoding.query['size'].should.eql 10 \ No newline at end of file diff --git a/test/ciao/autocomplete/text_invalid.coffee b/test/ciao/autocomplete/text_invalid.coffee new file mode 100644 index 00000000..8b0e5dc6 --- /dev/null +++ b/test/ciao/autocomplete/text_invalid.coffee @@ -0,0 +1,34 @@ + +#> basic autocomplete +path: '/v1/autocomplete?text=' + +#? 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.exist json.geocoding.errors +json.geocoding.errors.should.eql [ 'invalid param \'text\': text length, must be >0' ] + +#? expected warnings +should.not.exist json.geocoding.warnings + +#? inputs +should.not.exist json.geocoding.query['text'] +json.geocoding.query['size'].should.eql 10 \ No newline at end of file diff --git a/test/ciao/autocomplete/basic_autocomplete.coffee b/test/ciao/autocomplete/text_valid.coffee similarity index 100% rename from test/ciao/autocomplete/basic_autocomplete.coffee rename to test/ciao/autocomplete/text_valid.coffee diff --git a/test/ciao/reverse/layers_alias_coarse.coffee b/test/ciao/reverse/layers_alias_coarse.coffee new file mode 100644 index 00000000..13671a05 --- /dev/null +++ b/test/ciao/reverse/layers_alias_coarse.coffee @@ -0,0 +1,34 @@ + +#> layer alias +path: '/v1/reverse?point.lat=1&point.lon=2&layers=coarse' + +#? 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.not.exist json.geocoding.warnings + +#? inputs +json.geocoding.query['size'].should.eql 10 +json.geocoding.query.types['from_layers'].should.eql ["admin0","admin1","admin2","neighborhood","locality","local_admin"] +json.geocoding.query['type'].should.eql ["admin0","admin1","admin2","neighborhood","locality","local_admin"] \ No newline at end of file diff --git a/test/ciao/reverse/layers_invalid.coffee b/test/ciao/reverse/layers_invalid.coffee new file mode 100644 index 00000000..0da5790e --- /dev/null +++ b/test/ciao/reverse/layers_invalid.coffee @@ -0,0 +1,35 @@ + +#> layer alias +path: '/v1/reverse?point.lat=1&point.lon=2&layers=notlayer' + +#? 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.exist json.geocoding.errors +json.geocoding.errors.should.eql [ '\'notlayer\' is an invalid layers parameter. Valid options: venue,address,country,region,county,locality,localadmin,neighbourhood,coarse' ] + +#? expected warnings +should.not.exist json.geocoding.warnings + +#? inputs +json.geocoding.query['size'].should.eql 10 +should.not.exist json.geocoding.query['types'] +should.not.exist json.geocoding.query['type'] \ No newline at end of file diff --git a/test/ciao/reverse/layers_mix_invalid_valid.coffee b/test/ciao/reverse/layers_mix_invalid_valid.coffee new file mode 100644 index 00000000..daa7bc2d --- /dev/null +++ b/test/ciao/reverse/layers_mix_invalid_valid.coffee @@ -0,0 +1,35 @@ + +#> layer alias +path: '/v1/reverse?point.lat=1&point.lon=2&layers=country,notlayer' + +#? 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.exist json.geocoding.errors +json.geocoding.errors.should.eql [ '\'notlayer\' is an invalid layers parameter. Valid options: venue,address,country,region,county,locality,localadmin,neighbourhood,coarse' ] + +#? expected warnings +should.not.exist json.geocoding.warnings + +#? inputs +json.geocoding.query['size'].should.eql 10 +should.not.exist json.geocoding.query['types'] +should.not.exist json.geocoding.query['type'] \ No newline at end of file diff --git a/test/ciao/reverse/layers_multiple.coffee b/test/ciao/reverse/layers_multiple.coffee new file mode 100644 index 00000000..efa27e83 --- /dev/null +++ b/test/ciao/reverse/layers_multiple.coffee @@ -0,0 +1,34 @@ + +#> layer alias +path: '/v1/reverse?point.lat=1&point.lon=2&layers=country,region' + +#? 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.not.exist json.geocoding.warnings + +#? inputs +json.geocoding.query['size'].should.eql 10 +json.geocoding.query.types['from_layers'].should.eql ["admin0","admin1"] +json.geocoding.query['type'].should.eql ["admin0","admin1"] \ No newline at end of file diff --git a/test/ciao/reverse/layers_single.coffee b/test/ciao/reverse/layers_single.coffee new file mode 100644 index 00000000..641edad1 --- /dev/null +++ b/test/ciao/reverse/layers_single.coffee @@ -0,0 +1,34 @@ + +#> layer alias +path: '/v1/reverse?point.lat=1&point.lon=2&layers=country' + +#? 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.not.exist json.geocoding.warnings + +#? inputs +json.geocoding.query['size'].should.eql 10 +json.geocoding.query.types['from_layers'].should.eql ["admin0"] +json.geocoding.query['type'].should.eql ["admin0"] \ No newline at end of file diff --git a/test/ciao/reverse/privacy_false.coffee b/test/ciao/reverse/privacy_false.coffee new file mode 100644 index 00000000..020a6c70 --- /dev/null +++ b/test/ciao/reverse/privacy_false.coffee @@ -0,0 +1,33 @@ + +#> accept privacy var +path: '/v1/reverse?point.lat=1&point.lon=2&private=false' + +#? 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.not.exist json.geocoding.warnings + +#? inputs +json.geocoding.query['size'].should.eql 10 +json.geocoding.query['private'].should.eql false \ No newline at end of file diff --git a/test/ciao/reverse/privacy_true.coffee b/test/ciao/reverse/privacy_true.coffee new file mode 100644 index 00000000..fbe2f89e --- /dev/null +++ b/test/ciao/reverse/privacy_true.coffee @@ -0,0 +1,33 @@ + +#> accept privacy var +path: '/v1/reverse?point.lat=1&point.lon=2&private=true' + +#? 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.not.exist json.geocoding.warnings + +#? inputs +json.geocoding.query['size'].should.eql 10 +json.geocoding.query['private'].should.eql true \ No newline at end of file diff --git a/test/ciao/reverse/sources_invalid.coffee b/test/ciao/reverse/sources_invalid.coffee new file mode 100644 index 00000000..e464cfe4 --- /dev/null +++ b/test/ciao/reverse/sources_invalid.coffee @@ -0,0 +1,35 @@ + +#> sources filter +path: '/v1/reverse?point.lat=1&point.lon=2&sources=openstreetmap,notasource' + +#? 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.exist json.geocoding.errors +json.geocoding.errors.should.eql [ '\'notasource\' is an invalid sources parameter. Valid options: gn,geonames,oa,openaddresses,qs,quattroshapes,osm,openstreetmap' ] + +#? expected warnings +should.not.exist json.geocoding.warnings + +#? inputs +json.geocoding.query['size'].should.eql 10 +should.not.exist json.geocoding.query['types'] +should.not.exist json.geocoding.query['type'] \ No newline at end of file diff --git a/test/ciao/reverse/sources_layers_invalid_combo.coffee b/test/ciao/reverse/sources_layers_invalid_combo.coffee new file mode 100644 index 00000000..06d18c37 --- /dev/null +++ b/test/ciao/reverse/sources_layers_invalid_combo.coffee @@ -0,0 +1,36 @@ + +#> sources and layers specified (invalid combo) +path: '/v1/reverse?point.lat=1&point.lon=2&sources=quattroshapes&layers=address' + +#? 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.exist json.geocoding.errors +json.geocoding.errors.should.eql [ 'You have specified both the `sources` and `layers` parameters in a combination that will return no results.' ] + +#? expected warnings +should.not.exist json.geocoding.warnings + +#? inputs +json.geocoding.query['size'].should.eql 10 +json.geocoding.query.types['from_layers'].should.eql ["osmaddress","openaddresses"] +json.geocoding.query.types['from_sources'].should.eql ["admin0","admin1","admin2","neighborhood","locality","local_admin"] +should.not.exist json.geocoding.query['type'] \ No newline at end of file diff --git a/test/ciao/reverse/sources_layers_valid_combo.coffee b/test/ciao/reverse/sources_layers_valid_combo.coffee new file mode 100644 index 00000000..286d4916 --- /dev/null +++ b/test/ciao/reverse/sources_layers_valid_combo.coffee @@ -0,0 +1,34 @@ + +#> sources and layers specified +path: '/v1/reverse?point.lat=1&point.lon=2&sources=openaddresses&layers=address' + +#? 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.not.exist json.geocoding.warnings + +#? inputs +json.geocoding.query['size'].should.eql 10 +json.geocoding.query.types['from_layers'].should.eql ["osmaddress","openaddresses"] +json.geocoding.query['type'].should.eql ["openaddresses"] \ No newline at end of file diff --git a/test/ciao/reverse/sources_multiple.coffee b/test/ciao/reverse/sources_multiple.coffee new file mode 100644 index 00000000..9de6389f --- /dev/null +++ b/test/ciao/reverse/sources_multiple.coffee @@ -0,0 +1,34 @@ + +#> sources filter +path: '/v1/reverse?point.lat=1&point.lon=2&sources=openstreetmap,geonames' + +#? 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.not.exist json.geocoding.warnings + +#? inputs +json.geocoding.query['size'].should.eql 10 +json.geocoding.query.types['from_sources'].should.eql ["osmaddress","osmnode","osmway","geoname"] +json.geocoding.query['type'].should.eql ["osmaddress","osmnode","osmway","geoname"] \ No newline at end of file diff --git a/test/ciao/reverse/sources_single.coffee b/test/ciao/reverse/sources_single.coffee new file mode 100644 index 00000000..ad4628f4 --- /dev/null +++ b/test/ciao/reverse/sources_single.coffee @@ -0,0 +1,34 @@ + +#> sources filter +path: '/v1/reverse?point.lat=1&point.lon=2&sources=openstreetmap' + +#? 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.not.exist json.geocoding.warnings + +#? inputs +json.geocoding.query['size'].should.eql 10 +json.geocoding.query.types['from_sources'].should.eql ["osmaddress","osmnode","osmway"] +json.geocoding.query['type'].should.eql ["osmaddress","osmnode","osmway"] \ No newline at end of file diff --git a/test/ciao/search/text_invalid.coffee b/test/ciao/search/text_invalid.coffee new file mode 100644 index 00000000..d50f6dea --- /dev/null +++ b/test/ciao/search/text_invalid.coffee @@ -0,0 +1,34 @@ + +#> basic search +path: '/v1/search?text=' + +#? 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.exist json.geocoding.errors +json.geocoding.errors.should.eql [ 'invalid param \'text\': text length, must be >0' ] + +#? expected warnings +should.not.exist json.geocoding.warnings + +#? inputs +should.not.exist json.geocoding.query['text'] +json.geocoding.query['size'].should.eql 10 \ No newline at end of file diff --git a/test/ciao/search/basic_search.coffee b/test/ciao/search/text_valid.coffee similarity index 100% rename from test/ciao/search/basic_search.coffee rename to test/ciao/search/text_valid.coffee diff --git a/test/unit/controller/place.js b/test/unit/controller/place.js index ba72de9e..1fde7942 100644 --- a/test/unit/controller/place.js +++ b/test/unit/controller/place.js @@ -57,11 +57,12 @@ module.exports.tests.functional_success = function(test, common) { t.deepEqual(json.features, expected, 'values correctly mapped'); } }; + var req = { clean: { ids: [ {'id' : 123, 'type': 'a' } ] }, errors: [], warnings: [] }; var next = function next() { - t.equal(arguments.length, 0, 'next was called without error'); + t.equal(req.errors.length, 0, 'next was called without error'); t.end(); }; - controller( { clean: { ids: [ {'id' : 123, 'type': 'a' } ] } }, res, next ); + controller(req, res, next ); }); }; @@ -72,11 +73,12 @@ module.exports.tests.functional_failure = function(test, common) { t.deepEqual(cmd, { body: { docs: [ { _id: 123, _index: 'pelias', _type: 'b' } ] } }, 'correct backend command'); }); var controller = setup( backend ); + var req = { clean: { ids: [ {'id' : 123, 'type': 'b' } ] }, errors: [], warnings: [] }; var next = function( message ){ - t.equal(message,'a backend error occurred','error passed to errorHandler'); + t.equal(req.errors[0],'a backend error occurred','error passed to errorHandler'); t.end(); }; - controller( { clean: { ids: [ {'id' : 123, 'type': 'b' } ] } }, undefined, next ); + controller(req, undefined, next ); }); }; diff --git a/test/unit/controller/search.js b/test/unit/controller/search.js index 94873027..9a21f4c7 100644 --- a/test/unit/controller/search.js +++ b/test/unit/controller/search.js @@ -63,11 +63,12 @@ module.exports.tests.functional_success = function(test, common) { t.deepEqual(json.features, expected, 'values correctly mapped'); } }; + var req = { clean: { a: 'b' }, errors: [], warnings: [] }; var next = function next() { - t.equal(arguments.length, 0, 'next was called without error'); + t.equal(req.errors.length, 0, 'next was called without error'); t.end(); }; - controller({clean: {a: 'b'}}, res, next); + controller(req, res, next); }); }; @@ -78,11 +79,12 @@ module.exports.tests.functional_failure = function(test, common) { t.deepEqual(cmd, { body: { a: 'b' }, index: 'pelias', searchType: 'dfs_query_then_fetch' }, 'correct backend command'); }); var controller = setup( backend, mockQuery() ); - var next = function( message ){ - t.equal(message,'a backend error occurred','error passed to errorHandler'); + var req = { clean: { a: 'b' }, errors: [], warnings: [] }; + var next = function(){ + t.equal(req.errors[0],'a backend error occurred'); t.end(); }; - controller( { clean: { a: 'b' } }, undefined, next ); + controller(req, undefined, next ); }); };