|
|
|
@ -1,3 +1,5 @@
|
|
|
|
|
'use strict'; |
|
|
|
|
|
|
|
|
|
const sanitize = require('../../../sanitizer/_geo_reverse'); |
|
|
|
|
const defaults = require('../../../query/reverse_defaults'); |
|
|
|
|
|
|
|
|
@ -60,121 +62,44 @@ module.exports.tests.warning_situations = (test, common) => {
|
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
module.exports.tests.non_coarse_reverse = (test, common) => { |
|
|
|
|
test('boundary.circle.lat/lon should be overridden with point.lat/lon when non-coarse layers', (t) => { |
|
|
|
|
[[], ['venue', 'locality'], ['address', 'county'], ['street', 'country']].forEach((layers) => { |
|
|
|
|
const raw = { |
|
|
|
|
'point.lat': '12.121212', |
|
|
|
|
'point.lon': '21.212121', |
|
|
|
|
'boundary.circle.lat': '13.131313', |
|
|
|
|
'boundary.circle.lon': '31.313131' |
|
|
|
|
}; |
|
|
|
|
const clean = { |
|
|
|
|
layers: layers |
|
|
|
|
}; |
|
|
|
|
const errorsAndWarnings = sanitize(raw, clean); |
|
|
|
|
|
|
|
|
|
t.equals(raw['boundary.circle.lat'], 12.121212, 'should be set to point.lat'); |
|
|
|
|
t.equals(raw['boundary.circle.lon'], 21.212121, 'should be set to point.lon'); |
|
|
|
|
t.equals(clean['boundary.circle.lat'], 12.121212, 'should be set to point.lat'); |
|
|
|
|
t.equals(clean['boundary.circle.lon'], 21.212121, 'should be set to point.lon'); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('no boundary.circle.radius supplied should be set to default when non-coarse layers', (t) => { |
|
|
|
|
[[], ['venue', 'locality'], ['address', 'county'], ['street', 'country']].forEach((layers) => { |
|
|
|
|
const raw = { |
|
|
|
|
'point.lat': '12.121212', |
|
|
|
|
'point.lon': '21.212121' |
|
|
|
|
}; |
|
|
|
|
const clean = { |
|
|
|
|
layers: layers |
|
|
|
|
}; |
|
|
|
|
const errorsAndWarnings = sanitize(raw, clean); |
|
|
|
|
|
|
|
|
|
t.equals(raw['boundary.circle.radius'], defaults['boundary:circle:radius'], 'should be from defaults'); |
|
|
|
|
t.equals(clean['boundary.circle.radius'], parseFloat(defaults['boundary:circle:radius']), 'should be same as raw'); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('explicit boundary.circle.radius should be used instead of default', (t) => { |
|
|
|
|
[[], ['venue', 'locality'], ['address', 'county'], ['street', 'country']].forEach((layers) => { |
|
|
|
|
const raw = { |
|
|
|
|
'point.lat': '12.121212', |
|
|
|
|
'point.lon': '21.212121', |
|
|
|
|
'boundary.circle.radius': '3248732857km' // this will never be the default
|
|
|
|
|
}; |
|
|
|
|
const clean = { |
|
|
|
|
layers: layers |
|
|
|
|
}; |
|
|
|
|
const errorsAndWarnings = sanitize(raw, clean); |
|
|
|
|
|
|
|
|
|
t.equals(raw['boundary.circle.radius'], '3248732857km', 'should be parsed float'); |
|
|
|
|
t.equals(clean['boundary.circle.radius'], 3248732857.0, 'should be copied from raw'); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
module.exports.tests.coarse_reverse = (test, common) => { |
|
|
|
|
test('coarse layers should not set boundary.circle things since they\'re not applicable', (t) => { |
|
|
|
|
['coarse', 'neighbourhood', 'borough', 'locality', 'localadmin', 'county', |
|
|
|
|
'macrocounty', 'region', 'macroregion', 'dependency', 'country'].forEach((layer) => { |
|
|
|
|
const raw = { |
|
|
|
|
'point.lat': '12.121212', |
|
|
|
|
'point.lon': '21.212121' |
|
|
|
|
}; |
|
|
|
|
const clean = { layers: [layer] }; |
|
|
|
|
const errorsAndWarnings = sanitize(raw, clean); |
|
|
|
|
|
|
|
|
|
t.notOk(raw['boundary.circle.lat']); |
|
|
|
|
t.notOk(raw['boundary.circle.lon']); |
|
|
|
|
t.notOk(raw['boundary.circle.radius']); |
|
|
|
|
t.notOk(clean['boundary.circle.lat']); |
|
|
|
|
t.notOk(clean['boundary.circle.lon']); |
|
|
|
|
t.notOk(clean['boundary.circle.radius']); |
|
|
|
|
|
|
|
|
|
t.deepEquals(errorsAndWarnings, { errors: [], warnings: [] }); |
|
|
|
|
module.exports.tests.success_conditions = (test, common) => { |
|
|
|
|
test('boundary.circle.radius specified in request should override default', (t) => { |
|
|
|
|
const raw = { |
|
|
|
|
'point.lat': '12.121212', |
|
|
|
|
'point.lon': '21.212121', |
|
|
|
|
'boundary.circle.radius': '3248732857km' // this will never be the default
|
|
|
|
|
}; |
|
|
|
|
const clean = {}; |
|
|
|
|
const errorsAndWarnings = sanitize(raw, clean); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
t.equals(raw['boundary.circle.lat'], 12.121212); |
|
|
|
|
t.equals(raw['boundary.circle.lon'], 21.212121); |
|
|
|
|
t.equals(raw['boundary.circle.radius'], '3248732857km'); |
|
|
|
|
t.equals(clean['boundary.circle.lat'], 12.121212); |
|
|
|
|
t.equals(clean['boundary.circle.lon'], 21.212121); |
|
|
|
|
t.equals(clean['boundary.circle.radius'], 3248732857.0); |
|
|
|
|
|
|
|
|
|
t.deepEquals(errorsAndWarnings, { errors: [], warnings: [] }); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('coarse layers should not use explicit boundary.circle.radius since it\'s not applicable', (t) => { |
|
|
|
|
['coarse', 'neighbourhood', 'borough', 'locality', 'localadmin', 'county', |
|
|
|
|
'macrocounty', 'region', 'macroregion', 'dependency', 'country'].forEach((layer) => { |
|
|
|
|
const raw = { |
|
|
|
|
'point.lat': '12.121212', |
|
|
|
|
'point.lon': '21.212121', |
|
|
|
|
'boundary.circle.radius': '3248732857km' // this will never be the default
|
|
|
|
|
}; |
|
|
|
|
const clean = { layers: [layer] }; |
|
|
|
|
const errorsAndWarnings = sanitize(raw, clean); |
|
|
|
|
|
|
|
|
|
t.notOk(raw['boundary.circle.lat'], 'should not have been copied'); |
|
|
|
|
t.notOk(raw['boundary.circle.lon'], 'should not have been copied'); |
|
|
|
|
t.notOk(clean['boundary.circle.lat'], 'should not have been copied'); |
|
|
|
|
t.notOk(clean['boundary.circle.lon'], 'should not have been copied'); |
|
|
|
|
t.notOk(clean['boundary.circle.radius'], 'should not have been copied'); |
|
|
|
|
|
|
|
|
|
t.deepEquals(errorsAndWarnings, { errors: [], warnings: [] }); |
|
|
|
|
test('boundary.circle.radius not specified should use default', (t) => { |
|
|
|
|
const raw = { |
|
|
|
|
'point.lat': '12.121212', |
|
|
|
|
'point.lon': '21.212121' |
|
|
|
|
}; |
|
|
|
|
const clean = {}; |
|
|
|
|
const errorsAndWarnings = sanitize(raw, clean); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
t.equals(raw['boundary.circle.lat'], 12.121212); |
|
|
|
|
t.equals(raw['boundary.circle.lon'], 21.212121); |
|
|
|
|
t.equals(raw['boundary.circle.radius'], defaults['boundary:circle:radius'], 'should be from defaults'); |
|
|
|
|
t.equals(clean['boundary.circle.lat'], 12.121212); |
|
|
|
|
t.equals(clean['boundary.circle.lon'], 21.212121); |
|
|
|
|
t.equals(clean['boundary.circle.radius'], parseFloat(defaults['boundary:circle:radius']), 'should be same as raw'); |
|
|
|
|
|
|
|
|
|
t.deepEquals(errorsAndWarnings, { errors: [], warnings: [] }); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
@ -183,10 +108,10 @@ module.exports.tests.coarse_reverse = (test, common) => {
|
|
|
|
|
|
|
|
|
|
module.exports.all = (tape, common) => { |
|
|
|
|
function test(name, testFunction) { |
|
|
|
|
return tape('SANTIZE _geo_reverse ' + name, testFunction); |
|
|
|
|
return tape(`SANTIZE _geo_reverse ${name}`, testFunction); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for( var testCase in module.exports.tests ){ |
|
|
|
|
for( const testCase in module.exports.tests ){ |
|
|
|
|
module.exports.tests[testCase](test, common); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|