Browse Source

Merge pull request #333 from pelias/http_status_codes

http friendly status codes
pull/335/head
Peter Johnson a.k.a. insertcoffee 9 years ago
parent
commit
a03a18ef67
  1. 3
      app.js
  2. 2
      controller/place.js
  3. 2
      controller/search.js
  4. 2
      middleware/404.js
  5. 15
      middleware/408.js
  6. 37
      middleware/sendJSON.js
  7. 2
      routes/v1.js
  8. 2
      sanitiser/sanitizeAll.js
  9. 4
      test/ciao/autocomplete/focus_point_invalid_lat.coffee
  10. 4
      test/ciao/autocomplete/focus_point_invalid_lon.coffee
  11. 2
      test/ciao/autocomplete/focus_point_missing_lat.coffee
  12. 2
      test/ciao/autocomplete/focus_point_missing_lon.coffee
  13. 4
      test/ciao/autocomplete/no_params.coffee
  14. 4
      test/ciao/autocomplete/text_invalid.coffee
  15. 2
      test/ciao/place/missing_id.coffee
  16. 2
      test/ciao/reverse/boundary_circle_invalid_radius.coffee
  17. 4
      test/ciao/reverse/boundary_country_invalid_alpha2.coffee
  18. 4
      test/ciao/reverse/boundary_country_invalid_alpha3.coffee
  19. 4
      test/ciao/reverse/boundary_country_invalid_iso3166.coffee
  20. 2
      test/ciao/reverse/duplicate_parameter_name.coffee
  21. 2
      test/ciao/reverse/layers_invalid.coffee
  22. 2
      test/ciao/reverse/layers_mix_invalid_valid.coffee
  23. 2
      test/ciao/reverse/non_scalar_parameter.coffee
  24. 4
      test/ciao/reverse/point_invalid_lat.coffee
  25. 4
      test/ciao/reverse/point_invalid_lon.coffee
  26. 2
      test/ciao/reverse/point_missing_lat.coffee
  27. 2
      test/ciao/reverse/point_missing_lon.coffee
  28. 4
      test/ciao/reverse/sources_invalid.coffee
  29. 2
      test/ciao/reverse/sources_layers_invalid_combo.coffee
  30. 4
      test/ciao/search/boundary_circle_invalid_lat_lon_types.coffee
  31. 2
      test/ciao/search/boundary_circle_invalid_radius.coffee
  32. 2
      test/ciao/search/boundary_circle_missing_lat.coffee
  33. 2
      test/ciao/search/boundary_circle_missing_lon.coffee
  34. 4
      test/ciao/search/boundary_country_invalid_alpha2.coffee
  35. 4
      test/ciao/search/boundary_country_invalid_alpha3.coffee
  36. 4
      test/ciao/search/boundary_country_invalid_iso3166.coffee
  37. 2
      test/ciao/search/boundary_rect_partially_specified.coffee
  38. 4
      test/ciao/search/focus_point_invalid_lat.coffee
  39. 4
      test/ciao/search/focus_point_invalid_lon.coffee
  40. 2
      test/ciao/search/focus_point_missing_lat.coffee
  41. 2
      test/ciao/search/focus_point_missing_lon.coffee
  42. 2
      test/ciao/search/layers_invalid.coffee
  43. 2
      test/ciao/search/layers_mix_invalid_valid.coffee
  44. 4
      test/ciao/search/no_params.coffee
  45. 4
      test/ciao/search/sources_invalid.coffee
  46. 2
      test/ciao/search/sources_layers_invalid_combo.coffee
  47. 4
      test/ciao/search/text_invalid.coffee
  48. 2
      test/ciao/search/text_valid.coffee

3
app.js

@ -26,7 +26,6 @@ v1.addRoutes(app, peliasConfig);
/** ----------------------- error middleware ----------------------- **/
app.use( require('./middleware/404') );
app.use( require('./middleware/408') );
app.use( require('./middleware/500') );
module.exports = app;
module.exports = app;

2
controller/place.js

@ -29,7 +29,7 @@ function setup( backend ){
// error handler
if( err ){
req.errors.push( err.message ? err.message : err );
req.errors.push( err );
}
// set response data
else {

2
controller/search.js

@ -31,7 +31,7 @@ function setup( backend, query ){
// error handler
if( err ){
req.errors.push( err.message ? err.message : err );
req.errors.push( err );
}
// set response data
else {

2
middleware/404.js

@ -5,4 +5,4 @@ function middleware(req, res) {
res.status(404).json({ error: 'not found: invalid path' });
}
module.exports = middleware;
module.exports = middleware;

15
middleware/408.js

@ -1,15 +0,0 @@
// handle time out errors
function middleware(err, req, res, next) {
res.header('Cache-Control','public');
var error = (err && err.message) ? err.message : err;
if( res.statusCode === 408 || (error.toLowerCase().indexOf('request timeout') !== -1) ){
res.status(408);
res.json({ error: typeof error === 'string' ? error : 'request timeout' });
} else {
next(err);
}
}
module.exports = middleware;

37
middleware/sendJSON.js

@ -1,12 +1,43 @@
var check = require('check-types');
function sendJSONResponse(req, res, next) {
// do nothing if no result data set
if (!res || !res.body) {
if (!res || !check.object(res.body) || !check.object(res.body.geocoding)) {
return next();
}
// default status
var statusCode = 200;
// vary status code whenever an error was reported
var geocoding = res.body.geocoding;
if( check.array( geocoding.errors ) && geocoding.errors.length ){
// default status for errors is 400 Bad Request
statusCode = 400; // 400 Bad Request
// iterate over all reported errors
geocoding.errors.forEach( function( err ){
// custom status codes for instances of the Error() object.
if( err instanceof Error ){
// we can extract the error type from the constructor name
switch( err.constructor.name ){
// elasticsearch errors
// see: https://github.com/elastic/elasticsearch-js/blob/master/src/lib/errors.js
case 'RequestTimeout': statusCode = 408; break; // 408 Request Timeout
case 'NoConnections': statusCode = 502; break; // 502 Bad Gateway
case 'ConnectionFault': statusCode = 502; break; // 502 Bad Gateway
case 'Serialization': statusCode = 500; break; // 500 Internal Server Error
case 'Generic': statusCode = 500; break; // 500 Internal Server Error
default: statusCode = 500; // 500 Internal Server Error
}
}
});
}
// respond
return res.status(200).json(res.body);
return res.status(statusCode).json(res.body);
}
module.exports = sendJSONResponse;
module.exports = sendJSONResponse;

2
routes/v1.js

@ -17,7 +17,7 @@ var middleware = {
/** ----------------------- controllers ----------------------- **/
var controllers = {
var controllers = {
mdToHTML: require('../controller/markdownToHtml'),
place: require('../controller/place'),
search: require('../controller/search'),

2
sanitiser/sanitizeAll.js

@ -36,4 +36,4 @@ function sanitize( req, sanitizers, cb ){
}
// export function
module.exports = sanitize;
module.exports = sanitize;

4
test/ciao/autocomplete/focus_point_invalid_lat.coffee

@ -3,7 +3,7 @@
path: '/v1/autocomplete?text=a&focus.point.lat=foo&focus.point.lon=-73.990342'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'
@ -33,4 +33,4 @@ should.not.exist json.geocoding.warnings
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']
should.not.exist json.geocoding.query['focus.point.lon']

4
test/ciao/autocomplete/focus_point_invalid_lon.coffee

@ -3,7 +3,7 @@
path: '/v1/autocomplete?text=a&focus.point.lat=40.744243&focus.point.lon='
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'
@ -33,4 +33,4 @@ should.not.exist json.geocoding.warnings
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']
should.not.exist json.geocoding.query['focus.point.lon']

2
test/ciao/autocomplete/focus_point_missing_lat.coffee

@ -3,7 +3,7 @@
path: '/v1/autocomplete?text=a&focus.point.lon=-73.990342'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'

2
test/ciao/autocomplete/focus_point_missing_lon.coffee

@ -3,7 +3,7 @@
path: '/v1/autocomplete?text=a&focus.point.lat=40.744243'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'

4
test/ciao/autocomplete/no_params.coffee

@ -3,7 +3,7 @@
path: '/v1/autocomplete'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'
@ -30,4 +30,4 @@ json.geocoding.errors.should.eql [ 'invalid param \'text\': text length, must be
should.not.exist json.geocoding.warnings
#? inputs
json.geocoding.query['size'].should.eql 10
json.geocoding.query['size'].should.eql 10

4
test/ciao/autocomplete/text_invalid.coffee

@ -3,7 +3,7 @@
path: '/v1/autocomplete?text='
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'
@ -31,4 +31,4 @@ should.not.exist json.geocoding.warnings
#? inputs
should.not.exist json.geocoding.query['text']
json.geocoding.query['size'].should.eql 10
json.geocoding.query['size'].should.eql 10

2
test/ciao/place/missing_id.coffee

@ -3,7 +3,7 @@
path: '/v1/place'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'

2
test/ciao/reverse/boundary_circle_invalid_radius.coffee

@ -3,7 +3,7 @@
path: '/v1/reverse?point.lat=40.744243&point.lon=-73.990342&boundary.circle.radius=foo'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'

4
test/ciao/reverse/boundary_country_invalid_alpha2.coffee

@ -3,7 +3,7 @@
path: '/v1/reverse?point.lat=1&point.lon=1&boundary.country=ZZ'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'
@ -31,4 +31,4 @@ should.not.exist json.geocoding.warnings
#? inputs
json.geocoding.query['size'].should.eql 10
should.not.exist json.geocoding.query['boundary.country']
should.not.exist json.geocoding.query['boundary.country']

4
test/ciao/reverse/boundary_country_invalid_alpha3.coffee

@ -3,7 +3,7 @@
path: '/v1/reverse?point.lat=1&point.lon=1&boundary.country=ZZZ'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'
@ -31,4 +31,4 @@ should.not.exist json.geocoding.warnings
#? inputs
json.geocoding.query['size'].should.eql 10
should.not.exist json.geocoding.query['boundary.country']
should.not.exist json.geocoding.query['boundary.country']

4
test/ciao/reverse/boundary_country_invalid_iso3166.coffee

@ -3,7 +3,7 @@
path: '/v1/reverse?point.lat=1&point.lon=1&boundary.country=FOOBAR'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'
@ -31,4 +31,4 @@ should.not.exist json.geocoding.warnings
#? inputs
json.geocoding.query['size'].should.eql 10
should.not.exist json.geocoding.query['boundary.country']
should.not.exist json.geocoding.query['boundary.country']

2
test/ciao/reverse/duplicate_parameter_name.coffee

@ -3,7 +3,7 @@
path: '/v1/reverse?point.lat=1&point.lon=1&param=value1&param=value2'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'

2
test/ciao/reverse/layers_invalid.coffee

@ -3,7 +3,7 @@
path: '/v1/reverse?point.lat=1&point.lon=2&layers=notlayer'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'

2
test/ciao/reverse/layers_mix_invalid_valid.coffee

@ -3,7 +3,7 @@
path: '/v1/reverse?point.lat=1&point.lon=2&layers=country,notlayer'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'

2
test/ciao/reverse/non_scalar_parameter.coffee

@ -3,7 +3,7 @@
path: '/v1/reverse?point.lat=1&point.lon=1&parameter[idx]=value'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'

4
test/ciao/reverse/point_invalid_lat.coffee

@ -3,7 +3,7 @@
path: '/v1/reverse?point.lat=foo&point.lon=-73.990342'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'
@ -32,4 +32,4 @@ should.not.exist json.geocoding.warnings
#? inputs
json.geocoding.query['size'].should.eql 10
should.not.exist json.geocoding.query['point.lat']
should.not.exist json.geocoding.query['point.lon']
should.not.exist json.geocoding.query['point.lon']

4
test/ciao/reverse/point_invalid_lon.coffee

@ -3,7 +3,7 @@
path: '/v1/reverse?point.lat=40.744243&point.lon='
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'
@ -32,4 +32,4 @@ should.not.exist json.geocoding.warnings
#? inputs
json.geocoding.query['size'].should.eql 10
json.geocoding.query['point.lat'].should.eql 40.744243
should.not.exist json.geocoding.query['point.lon']
should.not.exist json.geocoding.query['point.lon']

2
test/ciao/reverse/point_missing_lat.coffee

@ -3,7 +3,7 @@
path: '/v1/reverse?point.lon=-73.990342'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'

2
test/ciao/reverse/point_missing_lon.coffee

@ -3,7 +3,7 @@
path: '/v1/reverse?point.lat=40.744243'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'

4
test/ciao/reverse/sources_invalid.coffee

@ -3,7 +3,7 @@
path: '/v1/reverse?point.lat=1&point.lon=2&sources=openstreetmap,notasource'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'
@ -32,4 +32,4 @@ 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']
should.not.exist json.geocoding.query['type']

2
test/ciao/reverse/sources_layers_invalid_combo.coffee

@ -3,7 +3,7 @@
path: '/v1/reverse?point.lat=1&point.lon=2&sources=quattroshapes&layers=address'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'

4
test/ciao/search/boundary_circle_invalid_lat_lon_types.coffee

@ -3,7 +3,7 @@
path: '/v1/search?text=a&boundary.circle.lat=foo&boundary.circle.lon=bar'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'
@ -34,4 +34,4 @@ json.geocoding.query['text'].should.eql 'a'
json.geocoding.query['size'].should.eql 10
should.not.exist json.geocoding.query['boundary.circle.lat']
should.not.exist json.geocoding.query['boundary.circle.lon']
should.not.exist json.geocoding.query['boundary.circle.radius']
should.not.exist json.geocoding.query['boundary.circle.radius']

2
test/ciao/search/boundary_circle_invalid_radius.coffee

@ -3,7 +3,7 @@
path: '/v1/search?text=a&boundary.circle.lat=40.744243&boundary.circle.lon=-73.990342&boundary.circle.radius=foo'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'

2
test/ciao/search/boundary_circle_missing_lat.coffee

@ -3,7 +3,7 @@
path: '/v1/search?text=a&boundary.circle.lon=-73.990342&boundary.circle.radius=100'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'

2
test/ciao/search/boundary_circle_missing_lon.coffee

@ -3,7 +3,7 @@
path: '/v1/search?text=a&boundary.circle.lat=40.744243&boundary.circle.radius=100'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'

4
test/ciao/search/boundary_country_invalid_alpha2.coffee

@ -3,7 +3,7 @@
path: '/v1/search?text=a&boundary.country=ZZ'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'
@ -32,4 +32,4 @@ 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['boundary.country']
should.not.exist json.geocoding.query['boundary.country']

4
test/ciao/search/boundary_country_invalid_alpha3.coffee

@ -3,7 +3,7 @@
path: '/v1/search?text=a&boundary.country=ZZZ'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'
@ -32,4 +32,4 @@ 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['boundary.country']
should.not.exist json.geocoding.query['boundary.country']

4
test/ciao/search/boundary_country_invalid_iso3166.coffee

@ -3,7 +3,7 @@
path: '/v1/search?text=a&boundary.country=FOOBAR'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'
@ -32,4 +32,4 @@ 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['boundary.country']
should.not.exist json.geocoding.query['boundary.country']

2
test/ciao/search/boundary_rect_partially_specified.coffee

@ -3,7 +3,7 @@
path: '/v1/search?text=a&boundary.rect.min_lat=-40.659'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'

4
test/ciao/search/focus_point_invalid_lat.coffee

@ -3,7 +3,7 @@
path: '/v1/search?text=a&focus.point.lat=foo&focus.point.lon=-73.990342'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'
@ -33,4 +33,4 @@ should.not.exist json.geocoding.warnings
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']
should.not.exist json.geocoding.query['focus.point.lon']

4
test/ciao/search/focus_point_invalid_lon.coffee

@ -3,7 +3,7 @@
path: '/v1/search?text=a&focus.point.lat=40.744243&focus.point.lon='
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'
@ -33,4 +33,4 @@ should.not.exist json.geocoding.warnings
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']
should.not.exist json.geocoding.query['focus.point.lon']

2
test/ciao/search/focus_point_missing_lat.coffee

@ -3,7 +3,7 @@
path: '/v1/search?text=a&focus.point.lon=-73.990342'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'

2
test/ciao/search/focus_point_missing_lon.coffee

@ -3,7 +3,7 @@
path: '/v1/search?text=a&focus.point.lat=40.744243'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'

2
test/ciao/search/layers_invalid.coffee

@ -3,7 +3,7 @@
path: '/v1/search?text=a&layers=notlayer'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'

2
test/ciao/search/layers_mix_invalid_valid.coffee

@ -3,7 +3,7 @@
path: '/v1/search?text=a&layers=country,notlayer'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'

4
test/ciao/search/no_params.coffee

@ -3,7 +3,7 @@
path: '/v1/search'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'
@ -30,4 +30,4 @@ json.geocoding.errors.should.eql [ 'invalid param \'text\': text length, must be
should.not.exist json.geocoding.warnings
#? inputs
json.geocoding.query['size'].should.eql 10
json.geocoding.query['size'].should.eql 10

4
test/ciao/search/sources_invalid.coffee

@ -3,7 +3,7 @@
path: '/v1/search?text=a&sources=openstreetmap,notasource'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'
@ -33,4 +33,4 @@ should.not.exist json.geocoding.warnings
json.geocoding.query['text'].should.eql 'a'
json.geocoding.query['size'].should.eql 10
should.not.exist json.geocoding.query['types']
should.not.exist json.geocoding.query['type']
should.not.exist json.geocoding.query['type']

2
test/ciao/search/sources_layers_invalid_combo.coffee

@ -3,7 +3,7 @@
path: '/v1/search?text=a&sources=quattroshapes&layers=address'
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'

4
test/ciao/search/text_invalid.coffee

@ -3,7 +3,7 @@
path: '/v1/search?text='
#? 200 ok
response.statusCode.should.be.equal 200
response.statusCode.should.be.equal 400
response.should.have.header 'charset', 'utf8'
response.should.have.header 'content-type', 'application/json; charset=utf-8'
@ -31,4 +31,4 @@ should.not.exist json.geocoding.warnings
#? inputs
should.not.exist json.geocoding.query['text']
json.geocoding.query['size'].should.eql 10
json.geocoding.query['size'].should.eql 10

2
test/ciao/search/text_valid.coffee

@ -30,4 +30,4 @@ should.not.exist json.geocoding.warnings
#? inputs
json.geocoding.query['text'].should.eql 'a'
json.geocoding.query['size'].should.eql 10
json.geocoding.query['size'].should.eql 10

Loading…
Cancel
Save