Browse Source

Whitespace

pull/230/head
Julian Simioni 9 years ago
parent
commit
040871cbe4
  1. 1
      sanitiser/reverse.js
  2. 6
      test/unit/query/reverse.js
  3. 31
      test/unit/query/search.js
  4. 8
      test/unit/sanitiser/_text.js
  5. 16
      test/unit/sanitiser/reverse.js
  6. 22
      test/unit/sanitiser/search.js

1
sanitiser/reverse.js

@ -1,4 +1,3 @@
var _sanitize = require('../sanitiser/_sanitize'), var _sanitize = require('../sanitiser/_sanitize'),
sanitiser = { sanitiser = {
latlonzoom: function( req ) { latlonzoom: function( req ) {

6
test/unit/query/reverse.js

@ -1,4 +1,3 @@
var generate = require('../../../query/reverse'); var generate = require('../../../query/reverse');
module.exports.tests = {}; module.exports.tests = {};
@ -15,7 +14,7 @@ module.exports.tests.query = function(test, common) {
var query = generate({ var query = generate({
lat: 29.49136, lon: -82.50622 lat: 29.49136, lon: -82.50622
}); });
var compiled = JSON.parse( JSON.stringify( query ) ); var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/reverse_standard'); var expected = require('../fixture/reverse_standard');
@ -38,7 +37,6 @@ module.exports.tests.query = function(test, common) {
}; };
module.exports.all = function (tape, common) { module.exports.all = function (tape, common) {
function test(name, testFunction) { function test(name, testFunction) {
return tape('reverse query ' + name, testFunction); return tape('reverse query ' + name, testFunction);
} }
@ -46,4 +44,4 @@ module.exports.all = function (tape, common) {
for( var testCase in module.exports.tests ){ for( var testCase in module.exports.tests ){
module.exports.tests[testCase](test, common); module.exports.tests[testCase](test, common);
} }
}; };

31
test/unit/query/search.js

@ -1,4 +1,3 @@
var generate = require('../../../query/search'); var generate = require('../../../query/search');
var parser = require('../../../helper/query_parser'); var parser = require('../../../helper/query_parser');
@ -19,9 +18,9 @@ module.exports.tests.query = function(test, common) {
text: 'test', size: 10, text: 'test', size: 10,
lat: 29.49136, lon: -82.50622, lat: 29.49136, lon: -82.50622,
bbox: { bbox: {
top: 47.47, top: 47.47,
right: -61.84, right: -61.84,
bottom: 11.51, bottom: 11.51,
left: -103.16 left: -103.16
}, },
layers: ['test'] layers: ['test']
@ -39,9 +38,9 @@ module.exports.tests.query = function(test, common) {
var query = generate({ var query = generate({
text: 'test', size: 10, text: 'test', size: 10,
bbox: { bbox: {
top: 47.47, top: 47.47,
right: -61.84, right: -61.84,
bottom: 11.51, bottom: 11.51,
left: -103.16 left: -103.16
}, },
layers: ['test'] layers: ['test']
@ -50,7 +49,7 @@ module.exports.tests.query = function(test, common) {
var compiled = JSON.parse( JSON.stringify( query ) ); var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_bbox'); var expected = require('../fixture/search_linguistic_bbox');
expected.sort = sort; expected.sort = sort;
t.deepEqual(compiled, expected, 'valid search query'); t.deepEqual(compiled, expected, 'valid search query');
t.end(); t.end();
}); });
@ -86,9 +85,9 @@ module.exports.tests.query = function(test, common) {
test('valid query with a full valid address', function(t) { test('valid query with a full valid address', function(t) {
var address = '123 main st new york ny 10010 US'; var address = '123 main st new york ny 10010 US';
var query = generate({ text: address, var query = generate({ text: address,
layers: [ 'geoname', 'osmnode', 'osmway', 'admin0', 'admin1', 'admin2', 'neighborhood', layers: [ 'geoname', 'osmnode', 'osmway', 'admin0', 'admin1', 'admin2', 'neighborhood',
'locality', 'local_admin', 'osmaddress', 'openaddresses' ], 'locality', 'local_admin', 'osmaddress', 'openaddresses' ],
size: 10, size: 10,
details: true, details: true,
parsed_text: parser.get_parsed_address(address), parsed_text: parser.get_parsed_address(address),
@ -101,12 +100,12 @@ module.exports.tests.query = function(test, common) {
t.deepEqual(compiled, expected, 'valid search query'); t.deepEqual(compiled, expected, 'valid search query');
t.end(); t.end();
}); });
test('valid query with partial address', function(t) { test('valid query with partial address', function(t) {
var partial_address = 'soho grand, new york'; var partial_address = 'soho grand, new york';
var query = generate({ text: partial_address, var query = generate({ text: partial_address,
layers: [ 'geoname', 'osmnode', 'osmway', 'admin0', 'admin1', 'admin2', 'neighborhood', layers: [ 'geoname', 'osmnode', 'osmway', 'admin0', 'admin1', 'admin2', 'neighborhood',
'locality', 'local_admin', 'osmaddress', 'openaddresses' ], 'locality', 'local_admin', 'osmaddress', 'openaddresses' ],
size: 10, size: 10,
details: true, details: true,
parsed_text: parser.get_parsed_address(partial_address), parsed_text: parser.get_parsed_address(partial_address),
@ -137,11 +136,9 @@ module.exports.tests.query = function(test, common) {
t.deepEqual(compiled, expected, 'valid search query'); t.deepEqual(compiled, expected, 'valid search query');
t.end(); t.end();
}); });
}; };
module.exports.all = function (tape, common) { module.exports.all = function (tape, common) {
function test(name, testFunction) { function test(name, testFunction) {
return tape('search query ' + name, testFunction); return tape('search query ' + name, testFunction);
} }

8
test/unit/sanitiser/_text.js

@ -3,13 +3,13 @@ var text = require('../../../sanitiser/_text'),
parser = require('../../../helper/query_parser'), parser = require('../../../helper/query_parser'),
delim = ',', delim = ',',
defaultError = 'invalid param \'text\': text length, must be >0', defaultError = 'invalid param \'text\': text length, must be >0',
allLayers = [ 'geoname', 'osmnode', 'osmway', 'admin0', 'admin1', 'admin2', 'neighborhood', allLayers = [ 'geoname', 'osmnode', 'osmway', 'admin0', 'admin1', 'admin2', 'neighborhood',
'locality', 'local_admin', 'osmaddress', 'openaddresses' ], 'locality', 'local_admin', 'osmaddress', 'openaddresses' ],
nonAddressLayers = [ 'geoname', 'osmnode', 'osmway', 'admin0', 'admin1', 'admin2', 'neighborhood', nonAddressLayers = [ 'geoname', 'osmnode', 'osmway', 'admin0', 'admin1', 'admin2', 'neighborhood',
'locality', 'local_admin' ], 'locality', 'local_admin' ],
defaultParsed= { }, defaultParsed= { },
defaultClean = { text: 'test', defaultClean = { text: 'test',
layers: allLayers, layers: allLayers,
size: 10, size: 10,
details: true, details: true,
parsed_text: defaultParsed, parsed_text: defaultParsed,

16
test/unit/sanitiser/reverse.js

@ -35,7 +35,7 @@ module.exports.tests.sanitize_lat = function(test, common) {
valid: [ 0, 45, 90, -0, '0', '45', '90', -181, -120, -91, 91, 120, 181 ], valid: [ 0, 45, 90, -0, '0', '45', '90', -181, -120, -91, 91, 120, 181 ],
missing: ['', undefined, null] missing: ['', undefined, null]
}; };
test('invalid lat', function(t) { test('invalid lat', function(t) {
lats.invalid.forEach( function( lat ){ lats.invalid.forEach( function( lat ){
sanitize({ lat: lat, lon: 0 }, function( err, clean ){ sanitize({ lat: lat, lon: 0 }, function( err, clean ){
t.equal(err, 'invalid param \'lat\': must be >-90 and <90', lat + ' is an invalid latitude'); t.equal(err, 'invalid param \'lat\': must be >-90 and <90', lat + ' is an invalid latitude');
@ -44,7 +44,7 @@ module.exports.tests.sanitize_lat = function(test, common) {
}); });
t.end(); t.end();
}); });
test('valid lat', function(t) { test('valid lat', function(t) {
lats.valid.forEach( function( lat ){ lats.valid.forEach( function( lat ){
sanitize({ lat: lat, lon: 0 }, function( err, clean ){ sanitize({ lat: lat, lon: 0 }, function( err, clean ){
var expected = JSON.parse(JSON.stringify( defaultClean )); var expected = JSON.parse(JSON.stringify( defaultClean ));
@ -55,7 +55,7 @@ module.exports.tests.sanitize_lat = function(test, common) {
}); });
t.end(); t.end();
}); });
test('missing lat', function(t) { test('missing lat', function(t) {
lats.missing.forEach( function( lat ){ lats.missing.forEach( function( lat ){
sanitize({ lat: lat, lon: 0 }, function( err, clean ){ sanitize({ lat: lat, lon: 0 }, function( err, clean ){
t.equal(err, 'missing param \'lat\'', 'latitude is a required field'); t.equal(err, 'missing param \'lat\'', 'latitude is a required field');
@ -71,7 +71,7 @@ module.exports.tests.sanitize_lon = function(test, common) {
valid: [ -360, -181, 181, -180, -1, -0, 0, 45, 90, '-180', '0', '180' ], valid: [ -360, -181, 181, -180, -1, -0, 0, 45, 90, '-180', '0', '180' ],
missing: ['', undefined, null] missing: ['', undefined, null]
}; };
test('valid lon', function(t) { test('valid lon', function(t) {
lons.valid.forEach( function( lon ){ lons.valid.forEach( function( lon ){
sanitize({ lat: 0, lon: lon }, function( err, clean ){ sanitize({ lat: 0, lon: lon }, function( err, clean ){
var expected = JSON.parse(JSON.stringify( defaultClean )); var expected = JSON.parse(JSON.stringify( defaultClean ));
@ -82,7 +82,7 @@ module.exports.tests.sanitize_lon = function(test, common) {
}); });
t.end(); t.end();
}); });
test('missing lon', function(t) { test('missing lon', function(t) {
lons.missing.forEach( function( lon ){ lons.missing.forEach( function( lon ){
sanitize({ lat: 0, lon: lon }, function( err, clean ){ sanitize({ lat: 0, lon: lon }, function( err, clean ){
t.equal(err, 'missing param \'lon\'', 'longitude is a required field'); t.equal(err, 'missing param \'lon\'', 'longitude is a required field');
@ -123,7 +123,7 @@ module.exports.tests.sanitize_details = function(test, common) {
t.equal(clean.details, false, 'details set to false'); t.equal(clean.details, false, 'details set to false');
t.end(); t.end();
}); });
}); });
}); });
var valid_values = [true, 'true', 1, '1', 'yes', 'y']; var valid_values = [true, 'true', 1, '1', 'yes', 'y'];
@ -133,7 +133,7 @@ module.exports.tests.sanitize_details = function(test, common) {
t.equal(clean.details, true, 'details set to true'); t.equal(clean.details, true, 'details set to true');
t.end(); t.end();
}); });
}); });
}); });
test('test default behavior', function(t) { test('test default behavior', function(t) {
@ -150,7 +150,7 @@ module.exports.tests.sanitize_details = function(test, common) {
t.equal(clean.details, false, 'details set to false'); t.equal(clean.details, false, 'details set to false');
t.end(); t.end();
}); });
}); });
}); });
}; };

22
test/unit/sanitiser/search.js

@ -7,7 +7,7 @@ var search = require('../../../sanitiser/search'),
middleware = search.middleware, middleware = search.middleware,
delim = ',', delim = ',',
defaultError = 'invalid param \'text\': text length, must be >0', defaultError = 'invalid param \'text\': text length, must be >0',
defaultClean = { text: 'test', defaultClean = { text: 'test',
types: { types: {
}, },
size: 10, size: 10,
@ -32,7 +32,7 @@ module.exports.tests.interface = function(test, common) {
}; };
module.exports.tests.sanitize_invalid_text = function(test, common) { module.exports.tests.sanitize_invalid_text = function(test, common) {
test('invalid text', function(t) { test('invalid text', function(t) {
var invalid = [ '', 100, null, undefined, new Date() ]; var invalid = [ '', 100, null, undefined, new Date() ];
invalid.forEach( function( text ){ invalid.forEach( function( text ){
sanitize({ text: text }, function( err, clean ){ sanitize({ text: text }, function( err, clean ){
@ -91,7 +91,7 @@ module.exports.tests.sanitize_lat = function(test, common) {
invalid: [], invalid: [],
valid: [ 0, 45, 90, -0, '0', '45', '90', -181, -120, -91, 91, 120, 181 ] valid: [ 0, 45, 90, -0, '0', '45', '90', -181, -120, -91, 91, 120, 181 ]
}; };
test('invalid lat', function(t) { test('invalid lat', function(t) {
lats.invalid.forEach( function( lat ){ lats.invalid.forEach( function( lat ){
sanitize({ text: 'test', lat: lat, lon: 0 }, function( err, clean ){ sanitize({ text: 'test', lat: lat, lon: 0 }, function( err, clean ){
t.equal(err, 'invalid param \'lat\': must be >-90 and <90', lat + ' is an invalid latitude'); t.equal(err, 'invalid param \'lat\': must be >-90 and <90', lat + ' is an invalid latitude');
@ -100,7 +100,7 @@ module.exports.tests.sanitize_lat = function(test, common) {
}); });
t.end(); t.end();
}); });
test('valid lat', function(t) { test('valid lat', function(t) {
lats.valid.forEach( function( lat ){ lats.valid.forEach( function( lat ){
sanitize({ text: 'test', lat: lat, lon: 0 }, function( err, clean ){ sanitize({ text: 'test', lat: lat, lon: 0 }, function( err, clean ){
var expected = JSON.parse(JSON.stringify( defaultClean )); var expected = JSON.parse(JSON.stringify( defaultClean ));
@ -117,7 +117,7 @@ module.exports.tests.sanitize_lon = function(test, common) {
var lons = { var lons = {
valid: [ -381, -181, -180, -1, -0, 0, 45, 90, '-180', '0', '180', 181 ] valid: [ -381, -181, -180, -1, -0, 0, 45, 90, '-180', '0', '180', 181 ]
}; };
test('valid lon', function(t) { test('valid lon', function(t) {
lons.valid.forEach( function( lon ){ lons.valid.forEach( function( lon ){
sanitize({ text: 'test', lat: 0, lon: lon }, function( err, clean ){ sanitize({ text: 'test', lat: 0, lon: lon }, function( err, clean ){
var expected = JSON.parse(JSON.stringify( defaultClean )); var expected = JSON.parse(JSON.stringify( defaultClean ));
@ -183,9 +183,9 @@ module.exports.tests.sanitize_bbox = function(test, common) {
'91, -181,-91,11', '91, -181,-91,11',
'91, -11,-91,181' '91, -11,-91,181'
] ]
}; };
test('invalid bbox', function(t) { test('invalid bbox', function(t) {
bboxes.invalid.forEach( function( bbox ){ bboxes.invalid.forEach( function( bbox ){
sanitize({ text: 'test', bbox: bbox }, function( err, clean ){ sanitize({ text: 'test', bbox: bbox }, function( err, clean ){
t.equal(err, undefined, 'no error'); t.equal(err, undefined, 'no error');
@ -194,7 +194,7 @@ module.exports.tests.sanitize_bbox = function(test, common) {
}); });
t.end(); t.end();
}); });
test('valid bbox', function(t) { test('valid bbox', function(t) {
bboxes.valid.forEach( function( bbox ){ bboxes.valid.forEach( function( bbox ){
sanitize({ text: 'test', bbox: bbox }, function( err, clean ){ sanitize({ text: 'test', bbox: bbox }, function( err, clean ){
var bboxArray = bbox.split(',').map(function(i) { var bboxArray = bbox.split(',').map(function(i) {
@ -264,7 +264,7 @@ module.exports.tests.sanitize_details = function(test, common) {
t.equal(clean.details, false, 'default details set (to false)'); t.equal(clean.details, false, 'default details set (to false)');
t.end(); t.end();
}); });
}); });
}); });
var valid_values = ['true', true, 1, '1', 'yes', 'y']; var valid_values = ['true', true, 1, '1', 'yes', 'y'];
@ -274,7 +274,7 @@ module.exports.tests.sanitize_details = function(test, common) {
t.equal(clean.details, true, 'details set to true'); t.equal(clean.details, true, 'details set to true');
t.end(); t.end();
}); });
}); });
}); });
var valid_false_values = ['false', false, 0, '0', 'no', 'n']; var valid_false_values = ['false', false, 0, '0', 'no', 'n'];
@ -284,7 +284,7 @@ module.exports.tests.sanitize_details = function(test, common) {
t.equal(clean.details, false, 'details set to false'); t.equal(clean.details, false, 'details set to false');
t.end(); t.end();
}); });
}); });
}); });
test('test default behavior', function(t) { test('test default behavior', function(t) {

Loading…
Cancel
Save