Browse Source

Merge branch 'master' into unit-tests-for-type-mapping-helper

pull/313/head
Stephen Hess 9 years ago
parent
commit
44f335bbe0
  1. 12
      helper/type_mapping.js
  2. 2
      middleware/404.js
  3. 2
      middleware/408.js
  4. 2
      middleware/500.js
  5. 2
      middleware/headers.js
  6. 1
      package.json
  7. 7
      sanitiser/_ids.js
  8. 3
      service/mget.js
  9. 3
      service/search.js
  10. 2
      test/ciao/404.coffee
  11. 2
      test/ciao/index.coffee
  12. 4
      test/ciao/reverse/layers_multiple.coffee
  13. 4
      test/ciao/reverse/layers_single.coffee
  14. 2
      test/ciao/reverse/sources_layers_invalid_combo.coffee
  15. 2
      test/ciao/reverse/sources_layers_valid_combo.coffee
  16. 4
      test/ciao/search/layers_alias_address.coffee
  17. 4
      test/ciao/search/layers_multiple.coffee
  18. 4
      test/ciao/search/layers_single.coffee
  19. 2
      test/ciao/search/sources_layers_invalid_combo.coffee
  20. 2
      test/ciao/search/sources_layers_valid_combo.coffee
  21. 14
      test/unit/sanitiser/_ids.js
  22. 4
      test/unit/sanitiser/_layers.js

12
helper/type_mapping.js

@ -48,13 +48,13 @@ var SOURCE_TO_TYPE = {
*/ */
var LAYER_TO_TYPE = { var LAYER_TO_TYPE = {
'venue': ['geoname','osmnode','osmway'], 'venue': ['geoname','osmnode','osmway'],
'address': ['osmaddress','openaddresses', 'geoname'], 'address': ['osmaddress','openaddresses'],
'country': ['admin0', 'geoname'], 'country': ['admin0'],
'region': ['admin1', 'geoname'], 'region': ['admin1'],
'county': ['admin2', 'geoname'], 'county': ['admin2'],
'locality': ['locality', 'geoname'], 'locality': ['locality'],
'localadmin': ['local_admin'], 'localadmin': ['local_admin'],
'neighbourhood': ['neighborhood', 'geoname'] 'neighbourhood': ['neighborhood']
}; };
var LAYER_ALIASES = { var LAYER_ALIASES = {

2
middleware/404.js

@ -1,7 +1,7 @@
// handle not found errors // handle not found errors
function middleware(req, res) { function middleware(req, res) {
res.header('Cache-Control','public,max-age=300'); // 5 minute cache res.header('Cache-Control','public');
res.status(404).json({ error: 'not found: invalid path' }); res.status(404).json({ error: 'not found: invalid path' });
} }

2
middleware/408.js

@ -1,7 +1,7 @@
// handle time out errors // handle time out errors
function middleware(err, req, res, next) { function middleware(err, req, res, next) {
res.header('Cache-Control','no-cache'); res.header('Cache-Control','public');
var error = (err && err.message) ? err.message : err; var error = (err && err.message) ? err.message : err;
if( res.statusCode === 408 || (error.toLowerCase().indexOf('request timeout') !== -1) ){ if( res.statusCode === 408 || (error.toLowerCase().indexOf('request timeout') !== -1) ){

2
middleware/500.js

@ -3,7 +3,7 @@ var logger = require( 'pelias-logger' ).get( 'middleware-500' );
// handle application errors // handle application errors
function middleware(err, req, res, next) { function middleware(err, req, res, next) {
logger.error( 'Error: `%s`. Stack trace: `%s`.', err, err.stack ); logger.error( 'Error: `%s`. Stack trace: `%s`.', err, err.stack );
res.header('Cache-Control','no-cache'); res.header('Cache-Control','public');
var error = (err && err.message) ? err.message : err; var error = (err && err.message) ? err.message : err;
if( res.statusCode < 400 ){ res.status(500); } if( res.statusCode < 400 ){ res.status(500); }

2
middleware/headers.js

@ -3,7 +3,7 @@ var pkg = require('../package');
function middleware(req, res, next){ function middleware(req, res, next){
res.header('Charset','utf8'); res.header('Charset','utf8');
res.header('Cache-Control','public,max-age=60'); res.header('Cache-Control','public');
res.header('Server', 'Pelias/'+pkg.version); res.header('Server', 'Pelias/'+pkg.version);
res.header('X-Powered-By', 'mapzen'); res.header('X-Powered-By', 'mapzen');
next(); next();

1
package.json

@ -47,7 +47,6 @@
"iso3166-1": "^0.2.3", "iso3166-1": "^0.2.3",
"lodash": "^3.10.1", "lodash": "^3.10.1",
"markdown": "0.5.0", "markdown": "0.5.0",
"microtime": "1.4.0",
"morgan": "1.5.2", "morgan": "1.5.2",
"pelias-config": "^1.0.1", "pelias-config": "^1.0.1",
"pelias-esclient": "0.0.25", "pelias-esclient": "0.0.25",

7
sanitiser/_ids.js

@ -57,13 +57,6 @@ function sanitize( raw, clean ){
// error & warning messages // error & warning messages
var messages = { errors: [], warnings: [] }; var messages = { errors: [], warnings: [] };
// 'raw.ids' can be an array if ids is specified multiple times
// see https://github.com/pelias/api/issues/272
if (check.array( raw.ids )) {
messages.errors.push( '`ids` parameter specified multiple times.' );
return messages;
}
if (!check.unemptyString( raw.ids )) { if (!check.unemptyString( raw.ids )) {
messages.errors.push( lengthError); messages.errors.push( lengthError);
return messages; return messages;

3
service/mget.js

@ -12,7 +12,6 @@
**/ **/
var peliasLogger = require( 'pelias-logger' ).get( 'service/mget' ); var peliasLogger = require( 'pelias-logger' ).get( 'service/mget' );
var microtime = require( 'microtime' );
function service( backend, query, cb ){ function service( backend, query, cb ){
@ -23,10 +22,8 @@ function service( backend, query, cb ){
} }
}; };
var startTime = microtime.nowDouble();
// query new backend // query new backend
backend().client.mget( cmd, function( err, data ){ backend().client.mget( cmd, function( err, data ){
peliasLogger.verbose( 'time elasticsearch query took:', microtime.nowDouble() - startTime );
// handle backend errors // handle backend errors
if( err ){ return cb( err ); } if( err ){ return cb( err ); }

3
service/search.js

@ -6,14 +6,11 @@
**/ **/
var peliasLogger = require( 'pelias-logger' ).get( 'service/search' ); var peliasLogger = require( 'pelias-logger' ).get( 'service/search' );
var microtime = require( 'microtime' );
function service( backend, cmd, cb ){ function service( backend, cmd, cb ){
var startTime = microtime.nowDouble();
// query new backend // query new backend
backend().client.search( cmd, function( err, data ){ backend().client.search( cmd, function( err, data ){
peliasLogger.verbose( 'time elasticsearch query took:', microtime.nowDouble() - startTime );
// handle backend errors // handle backend errors
if( err ){ return cb( err ); } if( err ){ return cb( err ); }

2
test/ciao/404.coffee

@ -9,7 +9,7 @@ response.statusCode.should.be.equal 404
response.should.have.header 'Content-Type','application/json; charset=utf-8' response.should.have.header 'Content-Type','application/json; charset=utf-8'
#? cache-control header correctly set #? cache-control header correctly set
response.should.have.header 'Cache-Control','public,max-age=300' response.should.have.header 'Cache-Control','public'
#? should respond in json with server info #? should respond in json with server info
should.exist json should.exist json

2
test/ciao/index.coffee

@ -12,7 +12,7 @@ response.should.have.header 'Content-Type','text/html; charset=utf-8'
response.should.have.header 'Charset','utf8' response.should.have.header 'Charset','utf8'
#? cache-control header correctly set #? cache-control header correctly set
response.should.have.header 'Cache-Control','public,max-age=60' response.should.have.header 'Cache-Control','public'
#? server header correctly set #? server header correctly set
response.should.have.header 'Server' response.should.have.header 'Server'

4
test/ciao/reverse/layers_multiple.coffee

@ -30,5 +30,5 @@ should.not.exist json.geocoding.warnings
#? inputs #? inputs
json.geocoding.query['size'].should.eql 10 json.geocoding.query['size'].should.eql 10
json.geocoding.query.types['from_layers'].should.eql ["admin0","geoname","admin1"] json.geocoding.query.types['from_layers'].should.eql ["admin0","admin1"]
json.geocoding.query['type'].should.eql ["admin0","geoname","admin1"] json.geocoding.query['type'].should.eql ["admin0","admin1"]

4
test/ciao/reverse/layers_single.coffee

@ -30,5 +30,5 @@ should.not.exist json.geocoding.warnings
#? inputs #? inputs
json.geocoding.query['size'].should.eql 10 json.geocoding.query['size'].should.eql 10
json.geocoding.query.types['from_layers'].should.eql ["admin0","geoname"] json.geocoding.query.types['from_layers'].should.eql ["admin0"]
json.geocoding.query['type'].should.eql ["admin0","geoname"] json.geocoding.query['type'].should.eql ["admin0"]

2
test/ciao/reverse/sources_layers_invalid_combo.coffee

@ -31,6 +31,6 @@ should.not.exist json.geocoding.warnings
#? inputs #? inputs
json.geocoding.query['size'].should.eql 10 json.geocoding.query['size'].should.eql 10
json.geocoding.query.types['from_layers'].should.eql ["osmaddress","openaddresses","geoname"] 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"] json.geocoding.query.types['from_sources'].should.eql ["admin0","admin1","admin2","neighborhood","locality","local_admin"]
should.not.exist json.geocoding.query['type'] should.not.exist json.geocoding.query['type']

2
test/ciao/reverse/sources_layers_valid_combo.coffee

@ -30,5 +30,5 @@ should.not.exist json.geocoding.warnings
#? inputs #? inputs
json.geocoding.query['size'].should.eql 10 json.geocoding.query['size'].should.eql 10
json.geocoding.query.types['from_layers'].should.eql ["osmaddress","openaddresses","geoname"] json.geocoding.query.types['from_layers'].should.eql ["osmaddress","openaddresses"]
json.geocoding.query['type'].should.eql ["openaddresses"] json.geocoding.query['type'].should.eql ["openaddresses"]

4
test/ciao/search/layers_alias_address.coffee

@ -31,5 +31,5 @@ should.not.exist json.geocoding.warnings
#? inputs #? inputs
json.geocoding.query['text'].should.eql 'a' json.geocoding.query['text'].should.eql 'a'
json.geocoding.query['size'].should.eql 10 json.geocoding.query['size'].should.eql 10
json.geocoding.query.types['from_layers'].should.eql ["osmaddress","openaddresses","geoname"] json.geocoding.query.types['from_layers'].should.eql ["osmaddress","openaddresses"]
json.geocoding.query['type'].should.eql ["osmaddress","openaddresses","geoname"] json.geocoding.query['type'].should.eql ["osmaddress","openaddresses"]

4
test/ciao/search/layers_multiple.coffee

@ -31,5 +31,5 @@ should.not.exist json.geocoding.warnings
#? inputs #? inputs
json.geocoding.query['text'].should.eql 'a' json.geocoding.query['text'].should.eql 'a'
json.geocoding.query['size'].should.eql 10 json.geocoding.query['size'].should.eql 10
json.geocoding.query.types['from_layers'].should.eql ["admin0","geoname","admin1"] json.geocoding.query.types['from_layers'].should.eql ["admin0","admin1"]
json.geocoding.query['type'].should.eql ["admin0","geoname","admin1"] json.geocoding.query['type'].should.eql ["admin0","admin1"]

4
test/ciao/search/layers_single.coffee

@ -31,5 +31,5 @@ should.not.exist json.geocoding.warnings
#? inputs #? inputs
json.geocoding.query['text'].should.eql 'a' json.geocoding.query['text'].should.eql 'a'
json.geocoding.query['size'].should.eql 10 json.geocoding.query['size'].should.eql 10
json.geocoding.query.types['from_layers'].should.eql ["admin0","geoname"] json.geocoding.query.types['from_layers'].should.eql ["admin0"]
json.geocoding.query['type'].should.eql ["admin0","geoname"] json.geocoding.query['type'].should.eql ["admin0"]

2
test/ciao/search/sources_layers_invalid_combo.coffee

@ -32,6 +32,6 @@ should.not.exist json.geocoding.warnings
#? inputs #? inputs
json.geocoding.query['text'].should.eql 'a' json.geocoding.query['text'].should.eql 'a'
json.geocoding.query['size'].should.eql 10 json.geocoding.query['size'].should.eql 10
json.geocoding.query.types['from_layers'].should.eql ["osmaddress","openaddresses","geoname"] 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"] json.geocoding.query.types['from_sources'].should.eql ["admin0","admin1","admin2","neighborhood","locality","local_admin"]
should.not.exist json.geocoding.query['type'] should.not.exist json.geocoding.query['type']

2
test/ciao/search/sources_layers_valid_combo.coffee

@ -31,5 +31,5 @@ should.not.exist json.geocoding.warnings
#? inputs #? inputs
json.geocoding.query['text'].should.eql 'a' json.geocoding.query['text'].should.eql 'a'
json.geocoding.query['size'].should.eql 10 json.geocoding.query['size'].should.eql 10
json.geocoding.query.types['from_layers'].should.eql ["osmaddress","openaddresses","geoname"] json.geocoding.query.types['from_layers'].should.eql ["osmaddress","openaddresses"]
json.geocoding.query['type'].should.eql ["openaddresses"] json.geocoding.query['type'].should.eql ["openaddresses"]

14
test/unit/sanitiser/_ids.js

@ -126,20 +126,6 @@ module.exports.tests.valid_ids = function(test, common) {
}); });
}; };
module.exports.tests.array_of_ids = function(test, common) {
// see https://github.com/pelias/api/issues/272
test('array of ids sent by queryparser', function(t) {
var raw = { ids: ['geoname:2', 'oswmay:4'] };
var clean = {};
var messages = sanitize( raw, clean);
t.deepEqual( messages.errors, ['`ids` parameter specified multiple times.'], 'error sent' );
t.deepEqual( clean.ids, undefined, 'response is empty due to error' );
t.end();
});
};
module.exports.tests.multiple_ids = function(test, common) { module.exports.tests.multiple_ids = function(test, common) {
test('multiple ids', function(t) { test('multiple ids', function(t) {
var raw = { ids: 'geonames:venue:1,osm:venue:2' }; var raw = { ids: 'geonames:venue:1,osm:venue:2' };

4
test/unit/sanitiser/_layers.js

@ -43,7 +43,7 @@ module.exports.tests.sanitize_layers = function(test, common) {
t.end(); t.end();
}); });
test('address (alias) layer', function(t) { test('address (alias) layer', function(t) {
var address_layers = ['osmaddress','openaddresses','geoname']; var address_layers = ['osmaddress','openaddresses'];
var raw = { layers: 'address' }; var raw = { layers: 'address' };
var clean = {}; var clean = {};
@ -76,7 +76,7 @@ module.exports.tests.sanitize_layers = function(test, common) {
t.end(); t.end();
}); });
test('address alias layer plus regular layers', function(t) { test('address alias layer plus regular layers', function(t) {
var address_layers = ['osmaddress','openaddresses','geoname']; var address_layers = ['osmaddress','openaddresses'];
var reg_layers = ['admin0', 'locality']; var reg_layers = ['admin0', 'locality'];
var raw = { layers: 'address,country,locality' }; var raw = { layers: 'address,country,locality' };

Loading…
Cancel
Save