|
|
|
@ -1,190 +1,503 @@
|
|
|
|
|
var generate = require('../../../query/reverse'); |
|
|
|
|
const generate = require('../../../query/reverse'); |
|
|
|
|
const _ = require('lodash'); |
|
|
|
|
const proxyquire = require('proxyquire').noCallThru(); |
|
|
|
|
const MockQuery = require('./MockQuery'); |
|
|
|
|
const all_layers = require('../../../helper/type_mapping').layers; |
|
|
|
|
|
|
|
|
|
// helper for canned views
|
|
|
|
|
const views = { |
|
|
|
|
boundary_country: 'boundary_country view', |
|
|
|
|
boundary_circle: 'boundary_circle view', |
|
|
|
|
sources: 'sources view', |
|
|
|
|
layers: 'layers view', |
|
|
|
|
categories: 'categories view', |
|
|
|
|
sort_distance: 'sort_distance view' |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
module.exports.tests = {}; |
|
|
|
|
|
|
|
|
|
module.exports.tests.interface = function(test, common) { |
|
|
|
|
test('valid interface', function(t) { |
|
|
|
|
module.exports.tests.interface = (test, common) => { |
|
|
|
|
test('valid interface', t => { |
|
|
|
|
t.equal(typeof generate, 'function', 'valid function'); |
|
|
|
|
t.end(); |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
module.exports.tests.query = function(test, common) { |
|
|
|
|
test('valid query', function(t) { |
|
|
|
|
var query = generate({ |
|
|
|
|
'point.lat': 29.49136, |
|
|
|
|
'point.lon': -82.50622, |
|
|
|
|
'boundary.circle.lat': 29.49136, |
|
|
|
|
'boundary.circle.lon': -82.50622, |
|
|
|
|
'boundary.circle.radius': 3 |
|
|
|
|
}); |
|
|
|
|
module.exports.tests.query = (test, common) => { |
|
|
|
|
test('base no frills', t => { |
|
|
|
|
const clean = {}; |
|
|
|
|
|
|
|
|
|
const query = proxyquire('../../../query/reverse', { |
|
|
|
|
'pelias-query': { |
|
|
|
|
layout: { |
|
|
|
|
FilteredBooleanQuery: MockQuery |
|
|
|
|
}, |
|
|
|
|
view: views, |
|
|
|
|
Vars: require('pelias-query').Vars |
|
|
|
|
}, |
|
|
|
|
'./reverse_defaults': { |
|
|
|
|
default_parameter_1: 'first default parameter', |
|
|
|
|
default_parameter_2: 'second default parameter' |
|
|
|
|
} |
|
|
|
|
})(clean); |
|
|
|
|
|
|
|
|
|
t.equals(query.type, 'reverse', 'query type set'); |
|
|
|
|
t.deepEquals(query.body.vs.var('default_parameter_1').toString(), 'first default parameter'); |
|
|
|
|
t.deepEquals(query.body.vs.var('default_parameter_2').toString(), 'second default parameter'); |
|
|
|
|
t.notOk(query.body.vs.isset('size')); |
|
|
|
|
t.notOk(query.body.vs.isset('sources')); |
|
|
|
|
t.notOk(query.body.vs.isset('layers')); |
|
|
|
|
t.notOk(query.body.vs.isset('focus:point:lat')); |
|
|
|
|
t.notOk(query.body.vs.isset('focus:point:lon')); |
|
|
|
|
t.notOk(query.body.vs.isset('boundary:circle:lat')); |
|
|
|
|
t.notOk(query.body.vs.isset('boundary:circle:lon')); |
|
|
|
|
t.notOk(query.body.vs.isset('boundary:circle:radius')); |
|
|
|
|
t.notOk(query.body.vs.isset('boundary:country')); |
|
|
|
|
t.notOk(query.body.vs.isset('input:categories')); |
|
|
|
|
|
|
|
|
|
t.deepEquals(query.body.score_functions, [ |
|
|
|
|
'boundary_country view' |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
t.deepEquals(query.body.filter_functions, [ |
|
|
|
|
'boundary_circle view', |
|
|
|
|
'sources view', |
|
|
|
|
'layers view', |
|
|
|
|
'categories view' |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
t.deepEquals(query.body.sort_functions, [ |
|
|
|
|
'sort_distance view' |
|
|
|
|
]); |
|
|
|
|
|
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
var compiled = JSON.parse( JSON.stringify( query ) ); |
|
|
|
|
var expected = require('../fixture/reverse_standard'); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
t.deepEqual(compiled.type, 'reverse', 'query type set'); |
|
|
|
|
t.deepEqual(compiled.body, expected, 'reverse_standard'); |
|
|
|
|
test('clean.querySize should set size parameter', t => { |
|
|
|
|
const clean = { |
|
|
|
|
querySize: 17 |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const query = proxyquire('../../../query/reverse', { |
|
|
|
|
'pelias-query': { |
|
|
|
|
layout: { |
|
|
|
|
FilteredBooleanQuery: MockQuery |
|
|
|
|
}, |
|
|
|
|
view: views, |
|
|
|
|
Vars: require('pelias-query').Vars |
|
|
|
|
}, |
|
|
|
|
'./reverse_defaults': {} |
|
|
|
|
})(clean); |
|
|
|
|
|
|
|
|
|
t.deepEquals(query.body.vs.var('size').toString(), 17); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('valid query - null island', function(t) { |
|
|
|
|
var query = generate({ |
|
|
|
|
'point.lat': 0, |
|
|
|
|
'point.lon': 0, |
|
|
|
|
'boundary.circle.lat': 0, |
|
|
|
|
'boundary.circle.lon': 0, |
|
|
|
|
'boundary.circle.radius': 3 |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var compiled = JSON.parse( JSON.stringify( query ) ); |
|
|
|
|
var expected = require('../fixture/reverse_null_island'); |
|
|
|
|
module.exports.tests.sources = (test, common) => { |
|
|
|
|
test('non-array clean.sources should not set sources in vs', t => { |
|
|
|
|
const clean = { |
|
|
|
|
sources: 'this is not an array' |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
t.deepEqual(compiled.type, 'reverse', 'query type set'); |
|
|
|
|
t.deepEqual(compiled.body, expected, 'reverse_null_island'); |
|
|
|
|
const query = proxyquire('../../../query/reverse', { |
|
|
|
|
'pelias-query': { |
|
|
|
|
layout: { |
|
|
|
|
FilteredBooleanQuery: MockQuery |
|
|
|
|
}, |
|
|
|
|
view: views, |
|
|
|
|
Vars: require('pelias-query').Vars |
|
|
|
|
}, |
|
|
|
|
'./reverse_defaults': {} |
|
|
|
|
})(clean); |
|
|
|
|
|
|
|
|
|
t.notOk(query.body.vs.isset('sources')); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('valid query with radius', function(t) { |
|
|
|
|
var query = generate({ |
|
|
|
|
'point.lat': 29.49136, |
|
|
|
|
'point.lon': -82.50622, |
|
|
|
|
'boundary.circle.lat': 29.49136, |
|
|
|
|
'boundary.circle.lon': -82.50622, |
|
|
|
|
'boundary.circle.radius': 123 |
|
|
|
|
}); |
|
|
|
|
test('empty array clean.sources should not set sources in vs', t => { |
|
|
|
|
const clean = { |
|
|
|
|
sources: [] |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const query = proxyquire('../../../query/reverse', { |
|
|
|
|
'pelias-query': { |
|
|
|
|
layout: { |
|
|
|
|
FilteredBooleanQuery: MockQuery |
|
|
|
|
}, |
|
|
|
|
view: views, |
|
|
|
|
Vars: require('pelias-query').Vars |
|
|
|
|
}, |
|
|
|
|
'./reverse_defaults': {} |
|
|
|
|
})(clean); |
|
|
|
|
|
|
|
|
|
t.notOk(query.body.vs.isset('sources')); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
var compiled = JSON.parse( JSON.stringify( query ) ); |
|
|
|
|
var expected = '123km'; |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('non-empty array clean.sources should set sources in vs', t => { |
|
|
|
|
const clean = { |
|
|
|
|
sources: ['source 1', 'source 2'] |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
t.deepEqual(compiled.type, 'reverse', 'query type set'); |
|
|
|
|
t.deepEqual(compiled.body.query.bool.filter[0].geo_distance.distance, expected, 'distance set to boundary circle radius'); |
|
|
|
|
const query = proxyquire('../../../query/reverse', { |
|
|
|
|
'pelias-query': { |
|
|
|
|
layout: { |
|
|
|
|
FilteredBooleanQuery: MockQuery |
|
|
|
|
}, |
|
|
|
|
view: views, |
|
|
|
|
Vars: require('pelias-query').Vars |
|
|
|
|
}, |
|
|
|
|
'./reverse_defaults': {} |
|
|
|
|
})(clean); |
|
|
|
|
|
|
|
|
|
t.deepEquals(query.body.vs.var('sources').toString(), ['source 1', 'source 2']); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
// for coarse reverse cases where boundary circle radius isn't used
|
|
|
|
|
test('undefined radius set to default radius', function(t) { |
|
|
|
|
var query = generate({ |
|
|
|
|
'point.lat': 12.12121, |
|
|
|
|
'point.lon': 21.21212, |
|
|
|
|
'boundary.circle.lat': 12.12121, |
|
|
|
|
'boundary.circle.lon': 21.21212 |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var compiled = JSON.parse( JSON.stringify( query ) ); |
|
|
|
|
var expected = '1km'; |
|
|
|
|
module.exports.tests.layers = (test, common) => { |
|
|
|
|
test('non-array clean.layers should not set sources in vs', t => { |
|
|
|
|
const clean = { |
|
|
|
|
layers: 'this is not an array' |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
t.deepEqual(compiled.type, 'reverse', 'query type set'); |
|
|
|
|
t.deepEqual(compiled.body.query.bool.filter[0].geo_distance.distance, expected, 'distance set to default boundary circle radius'); |
|
|
|
|
const query = proxyquire('../../../query/reverse', { |
|
|
|
|
'pelias-query': { |
|
|
|
|
layout: { |
|
|
|
|
FilteredBooleanQuery: MockQuery |
|
|
|
|
}, |
|
|
|
|
view: views, |
|
|
|
|
Vars: require('pelias-query').Vars |
|
|
|
|
}, |
|
|
|
|
'./reverse_defaults': {} |
|
|
|
|
})(clean); |
|
|
|
|
|
|
|
|
|
t.notOk(query.body.vs.isset('layers')); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('boundary.circle lat/lon/radius - overrides point.lat/lon when set', function(t) { |
|
|
|
|
var clean = { |
|
|
|
|
'point.lat': 29.49136, |
|
|
|
|
'point.lon': -82.50622, |
|
|
|
|
'boundary.circle.lat': 111, |
|
|
|
|
'boundary.circle.lon': 333, |
|
|
|
|
'boundary.circle.radius': 3 |
|
|
|
|
test('empty array clean.layers should not set sources in vs', t => { |
|
|
|
|
const clean = { |
|
|
|
|
layers: [] |
|
|
|
|
}; |
|
|
|
|
var query = generate(clean); |
|
|
|
|
var compiled = JSON.parse( JSON.stringify( query ) ); |
|
|
|
|
|
|
|
|
|
// this should not equal `point.lat` and `point.lon` as it was explitely specified
|
|
|
|
|
var expected = { lat: clean['boundary.circle.lat'], lon: clean['boundary.circle.lon'] }; |
|
|
|
|
var centroid = compiled.body.query.bool.filter[0].geo_distance.center_point; |
|
|
|
|
const query = proxyquire('../../../query/reverse', { |
|
|
|
|
'pelias-query': { |
|
|
|
|
layout: { |
|
|
|
|
FilteredBooleanQuery: MockQuery |
|
|
|
|
}, |
|
|
|
|
view: views, |
|
|
|
|
Vars: require('pelias-query').Vars |
|
|
|
|
}, |
|
|
|
|
'./reverse_defaults': {} |
|
|
|
|
})(clean); |
|
|
|
|
|
|
|
|
|
t.notOk(query.body.vs.isset('layers')); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('non-empty array clean.layers should only set non-coarse layers in vs', t => { |
|
|
|
|
const clean = { |
|
|
|
|
layers: all_layers |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
t.deepEqual(compiled.type, 'reverse', 'query type set'); |
|
|
|
|
t.deepEqual(centroid, expected, 'reverse: boundary.circle/lon overrides point.lat/lon'); |
|
|
|
|
const query = proxyquire('../../../query/reverse', { |
|
|
|
|
'pelias-query': { |
|
|
|
|
layout: { |
|
|
|
|
FilteredBooleanQuery: MockQuery |
|
|
|
|
}, |
|
|
|
|
view: views, |
|
|
|
|
Vars: require('pelias-query').Vars |
|
|
|
|
}, |
|
|
|
|
'./reverse_defaults': {} |
|
|
|
|
})(clean); |
|
|
|
|
|
|
|
|
|
t.deepEquals(query.body.vs.var('layers').toString(), ['address', 'venue', 'street']); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('size fuzz test', function(t) { |
|
|
|
|
// test different sizes
|
|
|
|
|
var sizes = [1,4,20,undefined,null]; |
|
|
|
|
var expected = [1,4,20,1,1]; |
|
|
|
|
sizes.forEach( function( size, index ){ |
|
|
|
|
var query = generate({ |
|
|
|
|
'point.lat': 29.49136, 'point.lon': -82.50622, querySize: size |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
module.exports.tests.focus_point = (test, common) => { |
|
|
|
|
test('numeric point.lat and non-numeric point.lon should not add focus:point:* fields', t => { |
|
|
|
|
const clean = { |
|
|
|
|
'point.lat': 12.121212, |
|
|
|
|
'point.lon': 'this is non-numeric' |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var compiled = JSON.parse( JSON.stringify( query ) ); |
|
|
|
|
t.equal( compiled.body.size, expected[index], 'valid reverse query for size: '+ size); |
|
|
|
|
}); |
|
|
|
|
const query = proxyquire('../../../query/reverse', { |
|
|
|
|
'pelias-query': { |
|
|
|
|
layout: { |
|
|
|
|
FilteredBooleanQuery: MockQuery |
|
|
|
|
}, |
|
|
|
|
view: views, |
|
|
|
|
Vars: require('pelias-query').Vars |
|
|
|
|
}, |
|
|
|
|
'./reverse_defaults': {} |
|
|
|
|
})(clean); |
|
|
|
|
|
|
|
|
|
t.notOk(query.body.vs.isset('focus:point:lat')); |
|
|
|
|
t.notOk(query.body.vs.isset('focus:point:lon')); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('valid boundary.country reverse search', function(t) { |
|
|
|
|
var query = generate({ |
|
|
|
|
'point.lat': 29.49136, |
|
|
|
|
'point.lon': -82.50622, |
|
|
|
|
'boundary.circle.lat': 29.49136, |
|
|
|
|
'boundary.circle.lon': -82.50622, |
|
|
|
|
'boundary.circle.radius': 3, |
|
|
|
|
'boundary.country': 'ABC' |
|
|
|
|
}); |
|
|
|
|
test('non-numeric point.lat and numeric point.lon should not add focus:point:* fields', t => { |
|
|
|
|
const clean = { |
|
|
|
|
'point.lat': 'this is non-numeric', |
|
|
|
|
'point.lon': 21.212121 |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var compiled = JSON.parse( JSON.stringify( query ) ); |
|
|
|
|
var expected = require('../fixture/reverse_with_boundary_country'); |
|
|
|
|
const query = proxyquire('../../../query/reverse', { |
|
|
|
|
'pelias-query': { |
|
|
|
|
layout: { |
|
|
|
|
FilteredBooleanQuery: MockQuery |
|
|
|
|
}, |
|
|
|
|
view: views, |
|
|
|
|
Vars: require('pelias-query').Vars |
|
|
|
|
}, |
|
|
|
|
'./reverse_defaults': {} |
|
|
|
|
})(clean); |
|
|
|
|
|
|
|
|
|
t.notOk(query.body.vs.isset('focus:point:lat')); |
|
|
|
|
t.notOk(query.body.vs.isset('focus:point:lon')); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
t.deepEqual(compiled.type, 'reverse', 'query type set'); |
|
|
|
|
t.deepEqual(compiled.body, expected, 'valid reverse query with boundary.country'); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('numeric point.lat and point.lon should add focus:point:* fields', t => { |
|
|
|
|
const clean = { |
|
|
|
|
'point.lat': 12.121212, |
|
|
|
|
'point.lon': 21.212121 |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const query = proxyquire('../../../query/reverse', { |
|
|
|
|
'pelias-query': { |
|
|
|
|
layout: { |
|
|
|
|
FilteredBooleanQuery: MockQuery |
|
|
|
|
}, |
|
|
|
|
view: views, |
|
|
|
|
Vars: require('pelias-query').Vars |
|
|
|
|
}, |
|
|
|
|
'./reverse_defaults': {} |
|
|
|
|
})(clean); |
|
|
|
|
|
|
|
|
|
t.deepEquals(query.body.vs.var('focus:point:lat').toString(), 12.121212); |
|
|
|
|
t.deepEquals(query.body.vs.var('focus:point:lon').toString(), 21.212121); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('valid sources filter', function(t) { |
|
|
|
|
var query = generate({ |
|
|
|
|
'point.lat': 29.49136, |
|
|
|
|
'point.lon': -82.50622, |
|
|
|
|
'boundary.circle.lat': 29.49136, |
|
|
|
|
'boundary.circle.lon': -82.50622, |
|
|
|
|
'boundary.circle.radius': 3, |
|
|
|
|
'sources': ['test'] |
|
|
|
|
}); |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
var compiled = JSON.parse( JSON.stringify( query ) ); |
|
|
|
|
var expected = require('../fixture/reverse_with_source_filtering'); |
|
|
|
|
module.exports.tests.boundary_circle = (test, common) => { |
|
|
|
|
test('numeric lat and non-numeric lon should not add boundary:circle:* fields', t => { |
|
|
|
|
const clean = { |
|
|
|
|
'boundary.circle.lat': 12.121212, |
|
|
|
|
'boundary.circle.lon': 'this is non-numeric' |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
t.deepEqual(compiled.type, 'reverse', 'query type set'); |
|
|
|
|
t.deepEqual(compiled.body, expected, 'valid reverse query with source filtering'); |
|
|
|
|
const query = proxyquire('../../../query/reverse', { |
|
|
|
|
'pelias-query': { |
|
|
|
|
layout: { |
|
|
|
|
FilteredBooleanQuery: MockQuery |
|
|
|
|
}, |
|
|
|
|
view: views, |
|
|
|
|
Vars: require('pelias-query').Vars |
|
|
|
|
}, |
|
|
|
|
'./reverse_defaults': {} |
|
|
|
|
})(clean); |
|
|
|
|
|
|
|
|
|
t.notOk(query.body.vs.isset('boundary:circle:lat')); |
|
|
|
|
t.notOk(query.body.vs.isset('boundary:circle:lon')); |
|
|
|
|
t.notOk(query.body.vs.isset('boundary:circle:radius')); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('valid layers filter', (t) => { |
|
|
|
|
const query = generate({ |
|
|
|
|
'point.lat': 29.49136, |
|
|
|
|
'point.lon': -82.50622, |
|
|
|
|
'boundary.circle.lat': 29.49136, |
|
|
|
|
'boundary.circle.lon': -82.50622, |
|
|
|
|
'boundary.circle.radius': 3, |
|
|
|
|
// only venue, address, and street layers should be retained
|
|
|
|
|
'layers': ['neighbourhood', 'venue', 'locality', 'address', 'region', 'street', 'country'] |
|
|
|
|
}); |
|
|
|
|
test('non-numeric lat and numeric lon should not add boundary:circle:* fields', t => { |
|
|
|
|
const clean = { |
|
|
|
|
'boundary.circle.lat': 'this is non-numeric', |
|
|
|
|
'boundary.circle.lon': 21.212121 |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const query = proxyquire('../../../query/reverse', { |
|
|
|
|
'pelias-query': { |
|
|
|
|
layout: { |
|
|
|
|
FilteredBooleanQuery: MockQuery |
|
|
|
|
}, |
|
|
|
|
view: views, |
|
|
|
|
Vars: require('pelias-query').Vars |
|
|
|
|
}, |
|
|
|
|
'./reverse_defaults': {} |
|
|
|
|
})(clean); |
|
|
|
|
|
|
|
|
|
t.notOk(query.body.vs.isset('boundary:circle:lat')); |
|
|
|
|
t.notOk(query.body.vs.isset('boundary:circle:lon')); |
|
|
|
|
t.notOk(query.body.vs.isset('boundary:circle:radius')); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('radius not supplied should default to value from reverse_defaults', t => { |
|
|
|
|
const clean = { |
|
|
|
|
'boundary.circle.lat': 12.121212, |
|
|
|
|
'boundary.circle.lon': 21.212121 |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const query = proxyquire('../../../query/reverse', { |
|
|
|
|
'pelias-query': { |
|
|
|
|
layout: { |
|
|
|
|
FilteredBooleanQuery: MockQuery |
|
|
|
|
}, |
|
|
|
|
view: views, |
|
|
|
|
Vars: require('pelias-query').Vars |
|
|
|
|
}, |
|
|
|
|
'./reverse_defaults': { |
|
|
|
|
'boundary:circle:radius': 17 |
|
|
|
|
} |
|
|
|
|
})(clean); |
|
|
|
|
|
|
|
|
|
t.deepEquals(query.body.vs.var('boundary:circle:lat').toString(), 12.121212); |
|
|
|
|
t.deepEquals(query.body.vs.var('boundary:circle:lon').toString(), 21.212121); |
|
|
|
|
t.deepEquals(query.body.vs.var('boundary:circle:radius').toString(), 17); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('numeric radius supplied should be used instead of value from reverse_defaults', t => { |
|
|
|
|
const clean = { |
|
|
|
|
'boundary.circle.lat': 12.121212, |
|
|
|
|
'boundary.circle.lon': 21.212121, |
|
|
|
|
'boundary.circle.radius': 17 |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const compiled = JSON.parse( JSON.stringify( query ) ); |
|
|
|
|
const expected = require('../fixture/reverse_with_layer_filtering'); |
|
|
|
|
const query = proxyquire('../../../query/reverse', { |
|
|
|
|
'pelias-query': { |
|
|
|
|
layout: { |
|
|
|
|
FilteredBooleanQuery: MockQuery |
|
|
|
|
}, |
|
|
|
|
view: views, |
|
|
|
|
Vars: require('pelias-query').Vars |
|
|
|
|
}, |
|
|
|
|
'./reverse_defaults': { |
|
|
|
|
'boundary:circle:radius': 18 |
|
|
|
|
} |
|
|
|
|
})(clean); |
|
|
|
|
|
|
|
|
|
t.deepEquals(query.body.vs.var('boundary:circle:lat').toString(), 12.121212); |
|
|
|
|
t.deepEquals(query.body.vs.var('boundary:circle:lon').toString(), 21.212121); |
|
|
|
|
t.deepEquals(query.body.vs.var('boundary:circle:radius').toString(), '17km'); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('non-numeric radius supplied should not set any boundary:circle:radius', t => { |
|
|
|
|
const clean = { |
|
|
|
|
'boundary.circle.lat': 12.121212, |
|
|
|
|
'boundary.circle.lon': 21.212121, |
|
|
|
|
'boundary.circle.radius': 'this is non-numeric' |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
t.deepEqual(compiled.type, 'reverse', 'query type set'); |
|
|
|
|
t.deepEqual(compiled.body, expected, 'valid reverse query with source filtering'); |
|
|
|
|
const query = proxyquire('../../../query/reverse', { |
|
|
|
|
'pelias-query': { |
|
|
|
|
layout: { |
|
|
|
|
FilteredBooleanQuery: MockQuery |
|
|
|
|
}, |
|
|
|
|
view: views, |
|
|
|
|
Vars: require('pelias-query').Vars |
|
|
|
|
}, |
|
|
|
|
'./reverse_defaults': { |
|
|
|
|
'boundary:circle:radius': 18 |
|
|
|
|
} |
|
|
|
|
})(clean); |
|
|
|
|
|
|
|
|
|
t.deepEquals(query.body.vs.var('boundary:circle:lat').toString(), 12.121212); |
|
|
|
|
t.deepEquals(query.body.vs.var('boundary:circle:lon').toString(), 21.212121); |
|
|
|
|
t.deepEquals(query.body.vs.var('boundary:circle:radius').toString(), 18); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('valid layers filter - subset of non-coarse layers', (t) => { |
|
|
|
|
const query = generate({ |
|
|
|
|
'point.lat': 29.49136, |
|
|
|
|
'point.lon': -82.50622, |
|
|
|
|
'boundary.circle.lat': 29.49136, |
|
|
|
|
'boundary.circle.lon': -82.50622, |
|
|
|
|
'boundary.circle.radius': 3, |
|
|
|
|
// only venue, address, and street layers should be retained
|
|
|
|
|
'layers': ['neighbourhood', 'venue', 'street', 'locality'] |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
module.exports.tests.boundary_country = (test, common) => { |
|
|
|
|
test('non-string boundary.country should not set boundary:country', t => { |
|
|
|
|
[17, undefined, {}, [], true, null].forEach(value => { |
|
|
|
|
const clean = { |
|
|
|
|
'boundary.country': value |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const query = proxyquire('../../../query/reverse', { |
|
|
|
|
'pelias-query': { |
|
|
|
|
layout: { |
|
|
|
|
FilteredBooleanQuery: MockQuery |
|
|
|
|
}, |
|
|
|
|
view: views, |
|
|
|
|
Vars: require('pelias-query').Vars |
|
|
|
|
}, |
|
|
|
|
'./reverse_defaults': {} |
|
|
|
|
})(clean); |
|
|
|
|
|
|
|
|
|
t.notOk(query.body.vs.isset('boundary:country')); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
const compiled = JSON.parse( JSON.stringify( query ) ); |
|
|
|
|
const expected = require('../fixture/reverse_with_layer_filtering_non_coarse_subset'); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
test('string boundary.country should set boundary:country', t => { |
|
|
|
|
const clean = { |
|
|
|
|
'boundary.country': 'boundary country value' |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const query = proxyquire('../../../query/reverse', { |
|
|
|
|
'pelias-query': { |
|
|
|
|
layout: { |
|
|
|
|
FilteredBooleanQuery: MockQuery |
|
|
|
|
}, |
|
|
|
|
view: views, |
|
|
|
|
Vars: require('pelias-query').Vars |
|
|
|
|
}, |
|
|
|
|
'./reverse_defaults': {} |
|
|
|
|
})(clean); |
|
|
|
|
|
|
|
|
|
t.deepEquals(query.body.vs.var('boundary:country').toString(), 'boundary country value'); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
module.exports.tests.categories = (test, common) => { |
|
|
|
|
test('categories supplied should set input:categories', t => { |
|
|
|
|
const clean = { |
|
|
|
|
categories: 'categories value' |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
t.deepEqual(compiled.type, 'reverse', 'query type set'); |
|
|
|
|
t.deepEqual(compiled.body, expected, 'valid reverse query with source filtering'); |
|
|
|
|
const query = proxyquire('../../../query/reverse', { |
|
|
|
|
'pelias-query': { |
|
|
|
|
layout: { |
|
|
|
|
FilteredBooleanQuery: MockQuery |
|
|
|
|
}, |
|
|
|
|
view: views, |
|
|
|
|
Vars: require('pelias-query').Vars |
|
|
|
|
}, |
|
|
|
|
'./reverse_defaults': {} |
|
|
|
|
})(clean); |
|
|
|
|
|
|
|
|
|
t.deepEquals(query.body.vs.var('input:categories').toString(), 'categories value'); |
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
|
|
}); |
|
|
|
|