Browse Source

more conformance

pull/282/head
Peter Johnson 9 years ago
parent
commit
348d2e70e2
  1. 10
      controller/place.js
  2. 10
      controller/search.js
  3. 3
      query/autocomplete.js
  4. 3
      sanitiser/_geo_autocomplete.js
  5. 36
      test/ciao/autocomplete/focus_point_invalid_lat.coffee
  6. 36
      test/ciao/autocomplete/focus_point_invalid_lon.coffee
  7. 36
      test/ciao/autocomplete/focus_point_missing_lat.coffee
  8. 36
      test/ciao/autocomplete/focus_point_missing_lon.coffee
  9. 4
      test/ciao/autocomplete/focus_point_null_island.coffee
  10. 35
      test/ciao/autocomplete/focus_point_valid_duo.coffee
  11. 33
      test/ciao/autocomplete/no_params.coffee
  12. 34
      test/ciao/autocomplete/text_invalid.coffee
  13. 0
      test/ciao/autocomplete/text_valid.coffee
  14. 34
      test/ciao/reverse/layers_alias_coarse.coffee
  15. 35
      test/ciao/reverse/layers_invalid.coffee
  16. 35
      test/ciao/reverse/layers_mix_invalid_valid.coffee
  17. 34
      test/ciao/reverse/layers_multiple.coffee
  18. 34
      test/ciao/reverse/layers_single.coffee
  19. 33
      test/ciao/reverse/privacy_false.coffee
  20. 33
      test/ciao/reverse/privacy_true.coffee
  21. 35
      test/ciao/reverse/sources_invalid.coffee
  22. 36
      test/ciao/reverse/sources_layers_invalid_combo.coffee
  23. 34
      test/ciao/reverse/sources_layers_valid_combo.coffee
  24. 34
      test/ciao/reverse/sources_multiple.coffee
  25. 34
      test/ciao/reverse/sources_single.coffee
  26. 34
      test/ciao/search/text_invalid.coffee
  27. 0
      test/ciao/search/text_valid.coffee
  28. 10
      test/unit/controller/place.js
  29. 12
      test/unit/controller/search.js

10
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();
});

10
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();
});

3
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']

3
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 );

36
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']

36
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']

36
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']

36
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']

4
test/ciao/autocomplete/null_island.coffee → 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

35
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

33
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

34
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

0
test/ciao/autocomplete/basic_autocomplete.coffee → test/ciao/autocomplete/text_valid.coffee

34
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"]

35
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']

35
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']

34
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"]

34
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"]

33
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

33
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

35
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']

36
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']

34
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"]

34
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"]

34
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"]

34
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

0
test/ciao/search/basic_search.coffee → test/ciao/search/text_valid.coffee

10
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 );
});
};

12
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 );
});
};

Loading…
Cancel
Save