Browse Source

Merge pull request #49 from pelias/codestyle-v2

Codestyles/ precommit hook
pull/52/head
Harish Krishna 10 years ago
parent
commit
77871efba6
  1. 1
      .jshintignore
  2. 21
      .jshintrc
  3. 2
      controller/suggest.js
  4. 6
      helper/geojsonify.js
  5. 2
      helper/outputGenerator.js
  6. 6
      index.js
  7. 2
      package.json
  8. 8
      sanitiser/_id.js
  9. 6
      sanitiser/_layers.js
  10. 2
      sanitiser/_size.js
  11. 2
      sanitiser/doc.js
  12. 2
      sanitiser/reverse.js
  13. 2
      sanitiser/suggest.js
  14. 2
      service/suggest.js
  15. 21
      test/unit/controller/suggest.js
  16. 7
      test/unit/controller/suggest_nearby.js
  17. 242
      test/unit/helper/geojsonify.js
  18. 9
      test/unit/helper/outputSchema.js
  19. 54
      test/unit/query/search.js
  20. 4
      test/unit/sanitiser/doc.js
  21. 10
      test/unit/sanitiser/suggest.js
  22. 2
      test/unit/service/mget.js
  23. 2
      test/unit/service/search.js
  24. 2
      test/unit/service/suggest.js

1
.jshintignore

@ -0,0 +1 @@
node_modules

21
.jshintrc

@ -0,0 +1,21 @@
{
"node": true,
"curly": true,
"eqeqeq": true,
"freeze": true,
"immed": true,
"indent": 2,
"latedef": false,
"newcap": true,
"noarg": true,
"noempty": true,
"nonbsp": true,
"nonew": true,
"plusplus": false,
"quotmark": "single",
"undef": true,
"unused": false,
"maxparams": 4,
"maxdepth": 4,
"maxlen": 140
}

2
controller/suggest.js

@ -35,7 +35,7 @@ function setup( backend, query ){
var dedup = function(combined) { var dedup = function(combined) {
var unique_ids = []; var unique_ids = [];
return combined.filter(function(item, pos) { return combined.filter(function(item, pos) {
if (unique_ids.indexOf(item.text) == -1) { if (unique_ids.indexOf(item.text) === -1) {
unique_ids.push(item.text); unique_ids.push(item.text);
return true; return true;
} }

6
helper/geojsonify.js

@ -16,7 +16,7 @@ function search( docs ){
var geodata = docs.map( function( doc ){ var geodata = docs.map( function( doc ){
// something went very wrong // something went very wrong
if( !doc ) return warning(); if( !doc ) { return warning(); }
var output = {}; var output = {};
@ -26,12 +26,12 @@ function search( docs ){
output.layer = doc._type; output.layer = doc._type;
// map center_point // map center_point
if( !doc.center_point ) return warning(); if( !doc.center_point ) { return warning(); }
output.lat = parseFloat( doc.center_point.lat ); output.lat = parseFloat( doc.center_point.lat );
output.lng = parseFloat( doc.center_point.lon ); output.lng = parseFloat( doc.center_point.lon );
// map name // map name
if( !doc.name || !doc.name.default ) return warning(); if( !doc.name || !doc.name.default ) { return warning(); }
output.name = doc.name.default; output.name = doc.name.default;
// map admin values // map admin values

2
helper/outputGenerator.js

@ -30,7 +30,7 @@ module.exports = function( record ){
// de-dupe outputs // de-dupe outputs
outputs = outputs.filter( function( i, pos ) { outputs = outputs.filter( function( i, pos ) {
return outputs.indexOf( i ) == pos; return outputs.indexOf( i ) === pos;
}); });
return outputs.join(', ').trim(); return outputs.join(', ').trim();

6
index.js

@ -5,13 +5,13 @@ var cluster = require('cluster'),
port = ( process.env.PORT || 3100 ); port = ( process.env.PORT || 3100 );
/** cluster webserver across all cores **/ /** cluster webserver across all cores **/
if( multicore ){ // if( multicore ){
// @todo: not finished yet // @todo: not finished yet
// cluster(app) // cluster(app)
// .use(cluster.stats()) // .use(cluster.stats())
// .listen( process.env.PORT || 3100 ); // .listen( process.env.PORT || 3100 );
} // }
else { if (!multicore){
console.log( 'listening on ' + port ); console.log( 'listening on ' + port );
app.listen( process.env.PORT || 3100 ); app.listen( process.env.PORT || 3100 );
} }

2
package.json

@ -42,6 +42,8 @@
}, },
"devDependencies": { "devDependencies": {
"ciao": "^0.3.4", "ciao": "^0.3.4",
"jshint": "^2.5.6",
"precommit-hook": "^1.0.7",
"tape": "^2.13.4", "tape": "^2.13.4",
"tap-spec": "^0.2.0", "tap-spec": "^0.2.0",
"nsp": "^0.3.0" "nsp": "^0.3.0"

8
sanitiser/_id.js

@ -18,7 +18,7 @@ function sanitize( req ){
return { return {
'error': true, 'error': true,
'message': message || ('invalid param \''+ fieldname + '\': text length, must be >0') 'message': message || ('invalid param \''+ fieldname + '\': text length, must be >0')
} };
}; };
if(('string' === typeof params.id && !params.id.length) || params.id === undefined){ if(('string' === typeof params.id && !params.id.length) || params.id === undefined){
@ -31,7 +31,7 @@ function sanitize( req ){
// de-dupe // de-dupe
params.ids = params.ids.filter(function(item, pos) { params.ids = params.ids.filter(function(item, pos) {
return params.ids.indexOf(item) == pos; return params.ids.indexOf(item) === pos;
}); });
for (var i=0; i<params.ids.length; i++) { for (var i=0; i<params.ids.length; i++) {
@ -55,8 +55,8 @@ function sanitize( req ){
return errormessage(thisparam); return errormessage(thisparam);
} }
// type text must be one of the indeces // type text must be one of the indeces
if(indeces.indexOf(type) == -1){ if(indeces.indexOf(type) === -1){
return errormessage('type', type + ' is invalid. It must be one of these values - [' + indeces.join(", ") + ']'); return errormessage('type', type + ' is invalid. It must be one of these values - [' + indeces.join(', ') + ']');
} }
req.clean.ids.push({ req.clean.ids.push({
id: id, id: id,

6
sanitiser/_layers.js

@ -25,7 +25,7 @@ function sanitize( req ){
return { return {
'error': true, 'error': true,
'message': 'invalid param \'layer\': must be one or more of ' + alias_indeces.join(',') 'message': 'invalid param \'layer\': must be one or more of ' + alias_indeces.join(',')
} };
} }
} }
var expand_aliases = function(alias, layers, layer_indeces) { var expand_aliases = function(alias, layers, layer_indeces) {
@ -35,14 +35,14 @@ function sanitize( req ){
layers = layers.concat(layer_indeces); layers = layers.concat(layer_indeces);
} }
return layers; return layers;
} };
layers = expand_aliases('poi', layers, ['geoname','osmnode','osmway']); layers = expand_aliases('poi', layers, ['geoname','osmnode','osmway']);
layers = expand_aliases('admin', layers, ['admin0','admin1','admin2','neighborhood']); layers = expand_aliases('admin', layers, ['admin0','admin1','admin2','neighborhood']);
// de-dup // de-dup
layers = layers.filter(function(item, pos) { layers = layers.filter(function(item, pos) {
return layers.indexOf(item) == pos; return layers.indexOf(item) === pos;
}); });
clean.layers = layers; clean.layers = layers;

2
sanitiser/_size.js

@ -4,7 +4,7 @@ function sanitize( req, default_size){
var clean = req.clean || {}; var clean = req.clean || {};
var params= req.query; var params= req.query;
var default_size = default_size || 10; default_size = default_size || 10;
// ensure the input params are a valid object // ensure the input params are a valid object
if( Object.prototype.toString.call( params ) !== '[object Object]' ){ if( Object.prototype.toString.call( params ) !== '[object Object]' ){

2
sanitiser/doc.js

@ -5,7 +5,7 @@ var logger = require('../src/logger'),
id: require('../sanitiser/_id') id: require('../sanitiser/_id')
}; };
var sanitize = function(req, cb) { _sanitize(req, sanitizers, cb); } var sanitize = function(req, cb) { _sanitize(req, sanitizers, cb); };
// export sanitize for testing // export sanitize for testing
module.exports.sanitize = sanitize; module.exports.sanitize = sanitize;

2
sanitiser/reverse.js

@ -9,7 +9,7 @@ var logger = require('../src/logger'),
} }
}; };
var sanitize = function(req, cb) { _sanitize(req, sanitiser, cb); } var sanitize = function(req, cb) { _sanitize(req, sanitiser, cb); };
// export sanitize for testing // export sanitize for testing
module.exports.sanitize = sanitize; module.exports.sanitize = sanitize;

2
sanitiser/suggest.js

@ -8,7 +8,7 @@ var logger = require('../src/logger'),
latlonzoom: require('../sanitiser/_latlonzoom') latlonzoom: require('../sanitiser/_latlonzoom')
}; };
var sanitize = function(req, cb) { _sanitize(req, sanitizers, cb); } var sanitize = function(req, cb) { _sanitize(req, sanitizers, cb); };
// export sanitize for testing // export sanitize for testing
module.exports.sanitize = sanitize; module.exports.sanitize = sanitize;

2
service/suggest.js

@ -16,7 +16,7 @@ function service( backend, cmd, cb ){
// map returned documents // map returned documents
var docs = []; var docs = [];
if( data && Array.isArray( data.pelias ) && data.pelias.length ){ if( data && Array.isArray( data.pelias ) && data.pelias.length ){
docs = data['pelias'][0].options || []; docs = data.pelias[0].options || [];
} }
// fire callback // fire callback

21
test/unit/controller/suggest.js

@ -55,10 +55,20 @@ module.exports.tests.functional_success = function(test, common) {
var backend = mockBackend( 'client/suggest/ok/1', function( cmd ){ var backend = mockBackend( 'client/suggest/ok/1', function( cmd ){
// the backend executes suggest (vanilla and admin-only) and mget, so we check them all based on cmd // the backend executes suggest (vanilla and admin-only) and mget, so we check them all based on cmd
if( cmd.body.docs ){ if( cmd.body.docs ){
t.deepEqual(cmd, { body: { docs: [ { _id: 'mockid1', _index: 'pelias', _type: 'mocktype' } , { _id: 'mockid2', _index: 'pelias', _type: 'mocktype' }] } }, 'correct mget command'); t.deepEqual(cmd, {
body: { docs: [
{ _id: 'mockid1', _index: 'pelias', _type: 'mocktype' },
{ _id: 'mockid2', _index: 'pelias', _type: 'mocktype' }
]}
}, 'correct mget command');
} else if (cmd.body.layers) { } else if (cmd.body.layers) {
// layers are set exclusively for admin: test for admin-only layers // layers are set exclusively for admin: test for admin-only layers
t.deepEqual(cmd, { body: { input: 'b', layers: [ 'admin0', 'admin1', 'admin2' ] }, index: 'pelias' }, 'correct suggest/admin command'); t.deepEqual(cmd, {
body: {
input: 'b',
layers: [ 'admin0', 'admin1', 'admin2' ]
}, index: 'pelias'
}, 'correct suggest/admin command');
} else { } else {
t.deepEqual(cmd, { body: { input: 'b' }, index: 'pelias' }, 'correct suggest command'); t.deepEqual(cmd, { body: { input: 'b' }, index: 'pelias' }, 'correct suggest command');
} }
@ -87,7 +97,12 @@ module.exports.tests.functional_failure = function(test, common) {
test('functional failure', function(t) { test('functional failure', function(t) {
var backend = mockBackend( 'client/suggest/fail/1', function( cmd ){ var backend = mockBackend( 'client/suggest/fail/1', function( cmd ){
if( cmd.body.docs ){ if( cmd.body.docs ){
t.deepEqual(cmd, { body: { docs: [ { _id: 'mockid1', _index: 'pelias', _type: 'mocktype' } , { _id: 'mockid2', _index: 'pelias', _type: 'mocktype' }] } }, 'correct mget command'); t.deepEqual(cmd, {
body: { docs: [
{ _id: 'mockid1', _index: 'pelias', _type: 'mocktype' },
{ _id: 'mockid2', _index: 'pelias', _type: 'mocktype' }]
}
}, 'correct mget command');
} else if (cmd.body.layers) { } else if (cmd.body.layers) {
// layers are set exclusively for admin: test for admin-only layers // layers are set exclusively for admin: test for admin-only layers
t.deepEqual(cmd, { body: { a: 'b', layers: [ 'admin0', 'admin1', 'admin2' ] }, index: 'pelias' }, 'correct suggest/admin command'); t.deepEqual(cmd, { body: { a: 'b', layers: [ 'admin0', 'admin1', 'admin2' ] }, index: 'pelias' }, 'correct suggest/admin command');

7
test/unit/controller/suggest_nearby.js

@ -58,7 +58,12 @@ module.exports.tests.functional_success = function(test, common) {
if( ++i === 1 ){ if( ++i === 1 ){
t.deepEqual(cmd, { body: { a: 'b' }, index: 'pelias' }, 'correct suggest command'); t.deepEqual(cmd, { body: { a: 'b' }, index: 'pelias' }, 'correct suggest command');
} else { } else {
t.deepEqual(cmd, { body: { docs: [ { _id: 'mockid1', _index: 'pelias', _type: 'mocktype' }, { _id: 'mockid2', _index: 'pelias', _type: 'mocktype' } ] } }, 'correct mget command'); t.deepEqual(cmd, {
body: { docs: [
{ _id: 'mockid1', _index: 'pelias', _type: 'mocktype' },
{ _id: 'mockid2', _index: 'pelias', _type: 'mocktype' } ]
}
}, 'correct mget command');
} }
}); });
var controller = setup( backend, mockQuery() ); var controller = setup( backend, mockQuery() );

242
test/unit/helper/geojsonify.js

@ -15,167 +15,167 @@ module.exports.tests.search = function(test, common) {
var input = [ var input = [
{ {
"_id": "id1", '_id': 'id1',
"_type": "type1", '_type': 'type1',
"center_point": { 'center_point': {
"lat": 51.5337144, 'lat': 51.5337144,
"lon": -0.1069716 'lon': -0.1069716
}, },
"name": { 'name': {
"default": "'Round Midnight Jazz and Blues Bar" 'default': '\'Round Midnight Jazz and Blues Bar'
}, },
"type": "node", 'type': 'node',
"address": { 'address': {
"number": "13", 'number': '13',
"street": "Liverpool Road", 'street': 'Liverpool Road',
"zip": "N1 0RW" 'zip': 'N1 0RW'
}, },
"alpha3": "GBR", 'alpha3': 'GBR',
"admin0": "United Kingdom", 'admin0': 'United Kingdom',
"admin1": "Islington", 'admin1': 'Islington',
"admin1_abbr": "ISL", 'admin1_abbr': 'ISL',
"admin2": "Angel", 'admin2': 'Angel',
"local_admin": "test1", 'local_admin': 'test1',
"locality": "test2", 'locality': 'test2',
"neighborhood": "test3", 'neighborhood': 'test3',
"suggest": { 'suggest': {
"input": [ 'input': [
"'round midnight jazz and blues bar" '\'round midnight jazz and blues bar'
], ],
"output": "osmnode:2208150035" 'output': 'osmnode:2208150035'
} }
}, },
{ {
"_id": "id2", '_id': 'id2',
"_type": "type2", '_type': 'type2',
"type": "way", 'type': 'way',
"name": { 'name': {
"default": "Blues Cafe" 'default': 'Blues Cafe'
}, },
"center_point": { 'center_point': {
"lat": "51.517806", 'lat': '51.517806',
"lon": "-0.101795" 'lon': '-0.101795'
}, },
"alpha3": "GBR", 'alpha3': 'GBR',
"admin0": "United Kingdom", 'admin0': 'United Kingdom',
"admin1": "City And County Of The City Of London", 'admin1': 'City And County Of The City Of London',
"admin1_abbr": "COL", 'admin1_abbr': 'COL',
"admin2": "Smithfield", 'admin2': 'Smithfield',
"local_admin": "test1", 'local_admin': 'test1',
"locality": "test2", 'locality': 'test2',
"neighborhood": "test3", 'neighborhood': 'test3',
"suggest": { 'suggest': {
"input": [ 'input': [
"blues cafe" 'blues cafe'
], ],
"output": "osmway:147495160" 'output': 'osmway:147495160'
} }
}, },
{ {
"_id": "34633854", '_id': '34633854',
"_type": "osmway", '_type': 'osmway',
"type": "osmway", 'type': 'osmway',
"name": { 'name': {
"default": "Empire State Building" 'default': 'Empire State Building'
}, },
"center_point": { 'center_point': {
"lat": "40.748432", 'lat': '40.748432',
"lon": "-73.985656" 'lon': '-73.985656'
}, },
"alpha3": "USA", 'alpha3': 'USA',
"admin0": "United States", 'admin0': 'United States',
"admin1": "New York", 'admin1': 'New York',
"admin1_abbr": "NY", 'admin1_abbr': 'NY',
"admin2": "New York", 'admin2': 'New York',
"local_admin": "Manhattan", 'local_admin': 'Manhattan',
"locality": "New York", 'locality': 'New York',
"neighborhood": "Koreatown", 'neighborhood': 'Koreatown',
"suggest": { 'suggest': {
"input": [ 'input': [
"empire state building" 'empire state building'
], ],
"output": "osmway:34633854" 'output': 'osmway:34633854'
} }
} }
]; ];
var expected = { var expected = {
"type": "FeatureCollection", 'type': 'FeatureCollection',
"bbox": [ -73.985656, 40.748432, -0.101795, 51.5337144 ], 'bbox': [ -73.985656, 40.748432, -0.101795, 51.5337144 ],
"features": [ 'features': [
{ {
"type": "Feature", 'type': 'Feature',
"geometry": { 'geometry': {
"type": "Point", 'type': 'Point',
"coordinates": [ 'coordinates': [
-0.1069716, -0.1069716,
51.5337144 51.5337144
] ]
}, },
"properties": { 'properties': {
"id": "id1", 'id': 'id1',
"type": "type1", 'type': 'type1',
"layer": "type1", 'layer': 'type1',
"text": "'Round Midnight Jazz and Blues Bar, test3, Angel", 'text': '\'Round Midnight Jazz and Blues Bar, test3, Angel',
"name": "'Round Midnight Jazz and Blues Bar", 'name': '\'Round Midnight Jazz and Blues Bar',
"alpha3": "GBR", 'alpha3': 'GBR',
"admin0": "United Kingdom", 'admin0': 'United Kingdom',
"admin1": "Islington", 'admin1': 'Islington',
"admin1_abbr": "ISL", 'admin1_abbr': 'ISL',
"admin2": "Angel", 'admin2': 'Angel',
"local_admin": "test1", 'local_admin': 'test1',
"locality": "test2", 'locality': 'test2',
"neighborhood": "test3" 'neighborhood': 'test3'
} }
}, },
{ {
"type": "Feature", 'type': 'Feature',
"geometry": { 'geometry': {
"type": "Point", 'type': 'Point',
"coordinates": [ 'coordinates': [
-0.101795, -0.101795,
51.517806 51.517806
] ]
}, },
"properties": { 'properties': {
"id": "id2", 'id': 'id2',
"type": "type2", 'type': 'type2',
"layer": "type2", 'layer': 'type2',
"text": "Blues Cafe, test3, Smithfield", 'text': 'Blues Cafe, test3, Smithfield',
"name": "Blues Cafe", 'name': 'Blues Cafe',
"alpha3": "GBR", 'alpha3': 'GBR',
"admin0": "United Kingdom", 'admin0': 'United Kingdom',
"admin1": "City And County Of The City Of London", 'admin1': 'City And County Of The City Of London',
"admin1_abbr": "COL", 'admin1_abbr': 'COL',
"admin2": "Smithfield", 'admin2': 'Smithfield',
"local_admin": "test1", 'local_admin': 'test1',
"locality": "test2", 'locality': 'test2',
"neighborhood": "test3" 'neighborhood': 'test3'
} }
}, },
{ {
"type": "Feature", 'type': 'Feature',
"geometry": { 'geometry': {
"type": "Point", 'type': 'Point',
"coordinates": [ 'coordinates': [
-73.985656, -73.985656,
40.748432 40.748432
] ]
}, },
"properties": { 'properties': {
"id": "34633854", 'id': '34633854',
"type": "osmway", 'type': 'osmway',
"layer": "osmway", 'layer': 'osmway',
"text": "Empire State Building, Manhattan, NY", 'text': 'Empire State Building, Manhattan, NY',
"name": "Empire State Building", 'name': 'Empire State Building',
"alpha3": "USA", 'alpha3': 'USA',
"admin0": "United States", 'admin0': 'United States',
"admin1": "New York", 'admin1': 'New York',
"admin1_abbr": "NY", 'admin1_abbr': 'NY',
"admin2": "New York", 'admin2': 'New York',
"local_admin": "Manhattan", 'local_admin': 'Manhattan',
"locality": "New York", 'locality': 'New York',
"neighborhood": "Koreatown" 'neighborhood': 'Koreatown'
} }
} }
] ]

9
test/unit/helper/outputSchema.js

@ -21,14 +21,14 @@ module.exports.tests.valid = function(test, common) {
var isValid = function(keys, schema) { var isValid = function(keys, schema) {
test('valid key/object (' + keys + ')' , function(t) { test('valid key/object (' + keys + ')' , function(t) {
if (keys=="default") { if (keys === 'default') {
t.deepEqual(schema, default_schema, 'valid default schema'); t.deepEqual(schema, default_schema, 'valid default schema');
} else { } else {
t.equal(alpha3.hasOwnProperty(keys), true, 'valid key'); t.equal(alpha3.hasOwnProperty(keys), true, 'valid key');
} }
t.equal(typeof schema, 'object', 'valid object'); t.equal(typeof schema, 'object', 'valid object');
t.notEqual(Object.getOwnPropertyNames(schema).length, 0, 'object not empty'); t.notEqual(Object.getOwnPropertyNames(schema).length, 0, 'object not empty');
for (levels in schema) { for (var levels in schema) {
t.equal(Object.prototype.toString.call(schema[levels]), '[object Array]', levels+' is an array'); t.equal(Object.prototype.toString.call(schema[levels]), '[object Array]', levels+' is an array');
for (var i=0;i<schema[levels].length;i++) { for (var i=0;i<schema[levels].length;i++) {
var key = schema[levels][i]; var key = schema[levels][i];
@ -37,8 +37,9 @@ module.exports.tests.valid = function(test, common) {
} }
t.end(); t.end();
}); });
} };
for (keys in schemas) {
for (var keys in schemas) {
isValid(keys, schemas[keys]); isValid(keys, schemas[keys]);
} }
}; };

54
test/unit/query/search.js

@ -29,29 +29,29 @@ module.exports.tests.query = function(test, common) {
}); });
var expected = { var expected = {
"query": { 'query': {
"filtered": { 'filtered': {
"query": { 'query': {
"query_string": { 'query_string': {
"query": "test", 'query': 'test',
"fields": [ 'fields': [
"name.default" 'name.default'
], ],
"default_operator": "OR" 'default_operator': 'OR'
} }
}, },
"filter": { 'filter': {
"bool": { 'bool': {
"must": [ 'must': [
{ {
"geo_distance": { 'geo_distance': {
"distance": "50km", 'distance': '50km',
"distance_type": "plane", 'distance_type': 'plane',
"optimize_bbox": "indexed", 'optimize_bbox': 'indexed',
"_cache": true, '_cache': true,
"center_point": { 'center_point': {
"lat": "29.49", 'lat': '29.49',
"lon": "-82.51" 'lon': '-82.51'
} }
} }
} }
@ -60,19 +60,19 @@ module.exports.tests.query = function(test, common) {
} }
} }
}, },
"sort": [ 'sort': [
{ {
"_geo_distance": { '_geo_distance': {
"center_point": { 'center_point': {
"lat": 29.49136, 'lat': 29.49136,
"lon": -82.50622 'lon': -82.50622
}, },
"order": "asc", 'order': 'asc',
"unit": "km" 'unit': 'km'
} }
} }
], ],
"size": 10 'size': 10
}; };
t.deepEqual(query, expected, 'valid search query'); t.deepEqual(query, expected, 'valid search query');

4
test/unit/sanitiser/doc.js

@ -4,12 +4,12 @@ var doc = require('../../../sanitiser/doc'),
middleware = doc.middleware, middleware = doc.middleware,
indeces = require('../../../query/indeces'), indeces = require('../../../query/indeces'),
delimiter = ':', delimiter = ':',
defaultLengthError = function(input) { return 'invalid param \''+ input + '\': text length, must be >0' }, defaultLengthError = function(input) { return 'invalid param \''+ input + '\': text length, must be >0'; },
defaultFormatError = 'invalid: must be of the format type:id for ex: \'geoname:4163334\'', defaultFormatError = 'invalid: must be of the format type:id for ex: \'geoname:4163334\'',
defaultError = 'invalid param \'id\': text length, must be >0', defaultError = 'invalid param \'id\': text length, must be >0',
defaultMissingTypeError = function(input) { defaultMissingTypeError = function(input) {
var type = input.split(delimiter)[0]; var type = input.split(delimiter)[0];
return type + ' is invalid. It must be one of these values - [' + indeces.join(", ") + ']'}, return type + ' is invalid. It must be one of these values - [' + indeces.join(', ') + ']'; },
defaultClean = { ids: [ { id: '123', type: 'geoname' } ] }, defaultClean = { ids: [ { id: '123', type: 'geoname' } ] },
sanitize = function(query, cb) { _sanitize({'query':query}, cb); }, sanitize = function(query, cb) { _sanitize({'query':query}, cb); },
inputs = { inputs = {

10
test/unit/sanitiser/suggest.js

@ -3,8 +3,14 @@ var suggest = require('../../../sanitiser/suggest'),
_sanitize = suggest.sanitize, _sanitize = suggest.sanitize,
middleware = suggest.middleware, middleware = suggest.middleware,
defaultError = 'invalid param \'input\': text length, must be >0', defaultError = 'invalid param \'input\': text length, must be >0',
defaultClean = { input: 'test', lat: 0, layers: [ 'geoname', 'osmnode', 'osmway', 'admin0', 'admin1', 'admin2', 'neighborhood' ], lon: 0, size: 10, zoom: 10 }, defaultClean = { input: 'test',
sanitize = function(query, cb) { _sanitize({'query':query}, cb); } lat: 0,
layers: [ 'geoname', 'osmnode', 'osmway', 'admin0', 'admin1', 'admin2', 'neighborhood' ],
lon: 0,
size: 10,
zoom: 10
},
sanitize = function(query, cb) { _sanitize({'query':query}, cb); };
module.exports.tests = {}; module.exports.tests = {};

2
test/unit/service/mget.js

@ -40,7 +40,7 @@ module.exports.tests.functional_success = function(test, common) {
data.forEach(function(d) { data.forEach(function(d) {
t.true(typeof d === 'object', 'valid object'); t.true(typeof d === 'object', 'valid object');
}); });
t.deepEqual(data, expected, 'values correctly mapped') t.deepEqual(data, expected, 'values correctly mapped');
t.end(); t.end();
}); });
}); });

2
test/unit/service/search.js

@ -42,7 +42,7 @@ module.exports.tests.functional_success = function(test, common) {
data.forEach(function(d) { data.forEach(function(d) {
t.true(typeof d === 'object', 'valid object'); t.true(typeof d === 'object', 'valid object');
}); });
t.deepEqual(data, expected, 'values correctly mapped') t.deepEqual(data, expected, 'values correctly mapped');
t.end(); t.end();
}); });
}); });

2
test/unit/service/suggest.js

@ -30,7 +30,7 @@ module.exports.tests.functional_success = function(test, common) {
data.forEach(function(d) { data.forEach(function(d) {
t.true(typeof d === 'object', 'valid object'); t.true(typeof d === 'object', 'valid object');
}); });
t.deepEqual(data, expected, 'values correctly mapped') t.deepEqual(data, expected, 'values correctly mapped');
t.end(); t.end();
}); });
}); });

Loading…
Cancel
Save