You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

150 lines
4.3 KiB

var generate = require('../../../query/search');
var parser = require('../../../helper/query_parser');
module.exports.tests = {};
module.exports.tests.interface = function(test, common) {
test('valid interface', function(t) {
t.equal(typeof generate, 'function', 'valid function');
t.end();
});
};
var sort = require('../fixture/sort_default');
10 years ago
module.exports.tests.query = function(test, common) {
test('valid search + focus + bbox', function(t) {
var query = generate({
text: 'test', size: 10,
lat: 29.49136, lon: -82.50622,
bbox: {
9 years ago
top: 47.47,
right: -61.84,
bottom: 11.51,
left: -103.16
},
layers: ['test']
});
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_focus_bbox');
expected.sort = sort;
t.deepEqual(compiled, expected, 'valid search query');
t.end();
});
test('valid search + bbox', function(t) {
var query = generate({
text: 'test', size: 10,
bbox: {
9 years ago
top: 47.47,
right: -61.84,
bottom: 11.51,
left: -103.16
},
layers: ['test']
});
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_bbox');
expected.sort = sort;
9 years ago
t.deepEqual(compiled, expected, 'valid search query');
t.end();
});
test('valid lingustic-only search', function(t) {
var query = generate({
text: 'test', size: 10,
layers: ['test']
});
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_only');
expected.sort = sort;
t.deepEqual(compiled, expected, 'valid search query');
t.end();
});
test('search search + focus', function(t) {
var query = generate({
text: 'test', size: 10,
lat: 29.49136, lon: -82.50622,
layers: ['test']
});
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_linguistic_focus');
expected.sort = sort;
t.deepEqual(compiled, expected, 'valid search query');
t.end();
});
test('valid query with a full valid address', function(t) {
var address = '123 main st new york ny 10010 US';
9 years ago
var query = generate({ text: address,
layers: [ 'geoname', 'osmnode', 'osmway', 'admin0', 'admin1', 'admin2', 'neighborhood',
'locality', 'local_admin', 'osmaddress', 'openaddresses' ],
size: 10,
details: true,
parsed_text: parser.get_parsed_address(address),
});
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_full_address');
expected.sort = sort;
t.deepEqual(compiled, expected, 'valid search query');
t.end();
});
9 years ago
test('valid query with partial address', function(t) {
var partial_address = 'soho grand, new york';
9 years ago
var query = generate({ text: partial_address,
layers: [ 'geoname', 'osmnode', 'osmway', 'admin0', 'admin1', 'admin2', 'neighborhood',
'locality', 'local_admin', 'osmaddress', 'openaddresses' ],
size: 10,
details: true,
parsed_text: parser.get_parsed_address(partial_address),
});
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_partial_address');
expected.sort = sort;
t.deepEqual(compiled, expected, 'valid search query');
t.end();
});
test('valid query with regions in address', function(t) {
var partial_address = '1 water st manhattan ny';
var query = generate({ text: partial_address,
layers: [ 'geoname', 'osmnode', 'osmway', 'admin0', 'admin1', 'admin2', 'neighborhood',
'locality', 'local_admin', 'osmaddress', 'openaddresses' ],
size: 10,
details: true,
parsed_text: parser.get_parsed_address(partial_address),
});
var compiled = JSON.parse( JSON.stringify( query ) );
var expected = require('../fixture/search_regions_address');
expected.sort = sort;
t.deepEqual(compiled, expected, 'valid search query');
t.end();
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {
return tape('search query ' + name, testFunction);
}
for( var testCase in module.exports.tests ){
module.exports.tests[testCase](test, common);
}
};