diff --git a/test/unit/fixture/reverse_null_island.js b/test/unit/fixture/reverse_null_island.js deleted file mode 100644 index 874518d4..00000000 --- a/test/unit/fixture/reverse_null_island.js +++ /dev/null @@ -1,39 +0,0 @@ -var vs = require('../../../query/reverse_defaults'); - -module.exports = { - 'query': { - 'bool': { - 'filter': [{ - 'geo_distance': { - 'distance': '3km', - 'distance_type': 'plane', - 'optimize_bbox': 'indexed', - 'center_point': { - 'lat': 0, - 'lon': 0 - } - } - }, - { - 'terms': { - 'layer': ['venue', 'address', 'street'] - } - }] - } - }, - 'sort': [ - '_score', - { - '_geo_distance': { - 'center_point': { - 'lat': 0, - 'lon': 0 - }, - 'order': 'asc', - 'distance_type': 'plane' - } - } - ], - 'size': vs.size, - 'track_scores': true -}; diff --git a/test/unit/fixture/reverse_standard.js b/test/unit/fixture/reverse_standard.js deleted file mode 100644 index 4a477ce1..00000000 --- a/test/unit/fixture/reverse_standard.js +++ /dev/null @@ -1,39 +0,0 @@ -var vs = require('../../../query/reverse_defaults'); - -module.exports = { - 'query': { - 'bool': { - 'filter': [{ - 'geo_distance': { - 'distance': '3km', - 'distance_type': 'plane', - 'optimize_bbox': 'indexed', - 'center_point': { - 'lat': 29.49136, - 'lon': -82.50622 - } - } - }, - { - 'terms': { - 'layer': ['venue', 'address', 'street'] - } - }] - } - }, - 'sort': [ - '_score', - { - '_geo_distance': { - 'center_point': { - 'lat': 29.49136, - 'lon': -82.50622 - }, - 'order': 'asc', - 'distance_type': 'plane' - } - } - ], - 'size': vs.size, - 'track_scores': true -}; diff --git a/test/unit/fixture/reverse_with_boundary_country.js b/test/unit/fixture/reverse_with_boundary_country.js deleted file mode 100644 index 6677247a..00000000 --- a/test/unit/fixture/reverse_with_boundary_country.js +++ /dev/null @@ -1,49 +0,0 @@ -var vs = require('../../../query/reverse_defaults'); - -module.exports = { - 'query': { - 'bool': { - 'must': [ - { - 'match': { - 'parent.country_a': { - 'analyzer': 'standard', - 'query': 'ABC' - } - } - } - ], - 'filter': [{ - 'geo_distance': { - 'distance': '3km', - 'distance_type': 'plane', - 'optimize_bbox': 'indexed', - 'center_point': { - 'lat': 29.49136, - 'lon': -82.50622 - } - } - }, - { - 'terms': { - 'layer': ['venue', 'address', 'street'] - } - }] - } - }, - 'sort': [ - '_score', - { - '_geo_distance': { - 'center_point': { - 'lat': 29.49136, - 'lon': -82.50622 - }, - 'order': 'asc', - 'distance_type': 'plane' - } - } - ], - 'size': vs.size, - 'track_scores': true -}; diff --git a/test/unit/fixture/reverse_with_layer_filtering.js b/test/unit/fixture/reverse_with_layer_filtering.js deleted file mode 100644 index 5d6c53b5..00000000 --- a/test/unit/fixture/reverse_with_layer_filtering.js +++ /dev/null @@ -1,41 +0,0 @@ -var vs = require('../../../query/reverse_defaults'); - -module.exports = { - 'query': { - 'bool': { - 'filter': [ - { - 'geo_distance': { - 'distance': '3km', - 'distance_type': 'plane', - 'optimize_bbox': 'indexed', - 'center_point': { - 'lat': 29.49136, - 'lon': -82.50622 - } - } - }, - { - 'terms': { - 'layer': ['venue', 'address', 'street'] - } - } - ] - } - }, - 'sort': [ - '_score', - { - '_geo_distance': { - 'center_point': { - 'lat': 29.49136, - 'lon': -82.50622 - }, - 'order': 'asc', - 'distance_type': 'plane' - } - } - ], - 'size': vs.size, - 'track_scores': true -}; diff --git a/test/unit/fixture/reverse_with_layer_filtering_non_coarse_subset.js b/test/unit/fixture/reverse_with_layer_filtering_non_coarse_subset.js deleted file mode 100644 index aba18b08..00000000 --- a/test/unit/fixture/reverse_with_layer_filtering_non_coarse_subset.js +++ /dev/null @@ -1,41 +0,0 @@ -var vs = require('../../../query/reverse_defaults'); - -module.exports = { - 'query': { - 'bool': { - 'filter': [ - { - 'geo_distance': { - 'distance': '3km', - 'distance_type': 'plane', - 'optimize_bbox': 'indexed', - 'center_point': { - 'lat': 29.49136, - 'lon': -82.50622 - } - } - }, - { - 'terms': { - 'layer': ['venue', 'street'] - } - } - ] - } - }, - 'sort': [ - '_score', - { - '_geo_distance': { - 'center_point': { - 'lat': 29.49136, - 'lon': -82.50622 - }, - 'order': 'asc', - 'distance_type': 'plane' - } - } - ], - 'size': vs.size, - 'track_scores': true -}; diff --git a/test/unit/fixture/reverse_with_source_filtering.js b/test/unit/fixture/reverse_with_source_filtering.js deleted file mode 100644 index b2bcb0d9..00000000 --- a/test/unit/fixture/reverse_with_source_filtering.js +++ /dev/null @@ -1,46 +0,0 @@ -var vs = require('../../../query/reverse_defaults'); - -module.exports = { - 'query': { - 'bool': { - 'filter': [ - { - 'geo_distance': { - 'distance': '3km', - 'distance_type': 'plane', - 'optimize_bbox': 'indexed', - 'center_point': { - 'lat': 29.49136, - 'lon': -82.50622 - } - } - }, - { - 'terms': { - 'source': ['test'] - } - }, - { - 'terms': { - 'layer': ['venue', 'address', 'street'] - } - } - ] - } - }, - 'sort': [ - '_score', - { - '_geo_distance': { - 'center_point': { - 'lat': 29.49136, - 'lon': -82.50622 - }, - 'order': 'asc', - 'distance_type': 'plane' - } - } - ], - 'size': vs.size, - 'track_scores': true -}; diff --git a/test/unit/query/reverse.js b/test/unit/query/reverse.js index 0e47eaed..78c98e0c 100644 --- a/test/unit/query/reverse.js +++ b/test/unit/query/reverse.js @@ -2,6 +2,7 @@ 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 = { @@ -207,7 +208,7 @@ module.exports.tests.layers = (test, common) => { test('non-empty array clean.layers should only set non-coarse layers in vs', t => { const clean = { - sources: ['source 1', 'source 2'] + layers: all_layers }; const query = proxyquire('../../../query/reverse', { @@ -221,7 +222,282 @@ module.exports.tests.layers = (test, common) => { './reverse_defaults': {} })(clean); - t.deepEquals(query.body.vs.var('sources').toString(), ['source 1', 'source 2']); + t.deepEquals(query.body.vs.var('layers').toString(), ['address', 'venue', 'street']); + t.end(); + + }); + +}; + +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' + }; + + 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('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 + }; + + 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('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(); + + }); + +}; + +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' + }; + + 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('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 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' + }; + + 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(); + + }); + +}; + +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')); + }); + + 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' + }; + + 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(); }); diff --git a/test/unit/run.js b/test/unit/run.js index cfe60255..5631b9f3 100644 --- a/test/unit/run.js +++ b/test/unit/run.js @@ -9,101 +9,101 @@ var common = { }; var tests = [ - // require('./app'), - // require('./schema'), - // require('./controller/coarse_reverse'), - // require('./controller/index'), - // require('./controller/libpostal'), - // require('./controller/place'), - // require('./controller/placeholder'), - // require('./controller/search'), - // require('./controller/search_with_ids'), - // require('./controller/predicates/has_parsed_text_properties'), - // require('./controller/predicates/has_request_parameter'), - // require('./controller/predicates/has_response_data'), - // require('./controller/predicates/has_results_at_layers'), - // require('./controller/predicates/has_request_parameter'), - // require('./controller/predicates/has_request_errors'), - // require('./controller/predicates/is_addressit_parse'), - // require('./controller/predicates/is_admin_only_analysis'), - // require('./controller/predicates/is_coarse_reverse'), - // require('./controller/predicates/is_only_non_admin_layers'), - // require('./controller/predicates/is_request_sources_only_whosonfirst'), - // require('./helper/debug'), - // require('./helper/diffPlaces'), - // require('./helper/geojsonify_place_details'), - // require('./helper/geojsonify'), - // require('./helper/logging'), - // require('./helper/type_mapping'), - // require('./helper/sizeCalculator'), - // require('./helper/stackTraceLine'), - // require('./middleware/access_log'), - // require('./middleware/accuracy'), - // require('./middleware/assignLabels'), - // require('./middleware/confidenceScore'), - // require('./middleware/confidenceScoreFallback'), - // require('./middleware/confidenceScoreReverse'), - // require('./middleware/changeLanguage'), - // require('./middleware/distance'), - // require('./middleware/interpolate'), - // require('./middleware/localNamingConventions'), - // require('./middleware/dedupe'), - // require('./middleware/parseBBox'), - // require('./middleware/sendJSON'), - // require('./middleware/normalizeParentIds'), - // require('./middleware/sortResponseData'), - // require('./middleware/trimByGranularity'), - // require('./middleware/trimByGranularityStructured'), - // require('./middleware/requestLanguage'), - // require('./query/address_search_using_ids'), - // require('./query/autocomplete'), - // require('./query/autocomplete_defaults'), - // require('./query/search_defaults'), - // require('./query/reverse_defaults'), + require('./app'), + require('./schema'), + require('./controller/coarse_reverse'), + require('./controller/index'), + require('./controller/libpostal'), + require('./controller/place'), + require('./controller/placeholder'), + require('./controller/search'), + require('./controller/search_with_ids'), + require('./controller/predicates/has_parsed_text_properties'), + require('./controller/predicates/has_request_parameter'), + require('./controller/predicates/has_response_data'), + require('./controller/predicates/has_results_at_layers'), + require('./controller/predicates/has_request_parameter'), + require('./controller/predicates/has_request_errors'), + require('./controller/predicates/is_addressit_parse'), + require('./controller/predicates/is_admin_only_analysis'), + require('./controller/predicates/is_coarse_reverse'), + require('./controller/predicates/is_only_non_admin_layers'), + require('./controller/predicates/is_request_sources_only_whosonfirst'), + require('./helper/debug'), + require('./helper/diffPlaces'), + require('./helper/geojsonify_place_details'), + require('./helper/geojsonify'), + require('./helper/logging'), + require('./helper/type_mapping'), + require('./helper/sizeCalculator'), + require('./helper/stackTraceLine'), + require('./middleware/access_log'), + require('./middleware/accuracy'), + require('./middleware/assignLabels'), + require('./middleware/confidenceScore'), + require('./middleware/confidenceScoreFallback'), + require('./middleware/confidenceScoreReverse'), + require('./middleware/changeLanguage'), + require('./middleware/distance'), + require('./middleware/interpolate'), + require('./middleware/localNamingConventions'), + require('./middleware/dedupe'), + require('./middleware/parseBBox'), + require('./middleware/sendJSON'), + require('./middleware/normalizeParentIds'), + require('./middleware/sortResponseData'), + require('./middleware/trimByGranularity'), + require('./middleware/trimByGranularityStructured'), + require('./middleware/requestLanguage'), + require('./query/address_search_using_ids'), + require('./query/autocomplete'), + require('./query/autocomplete_defaults'), + require('./query/search_defaults'), + require('./query/reverse_defaults'), require('./query/reverse'), - // require('./query/search'), - // require('./query/search_original'), - // require('./query/structured_geocoding'), - // require('./query/text_parser'), - // require('./sanitizer/_boundary_country'), - // require('./sanitizer/_debug'), - // require('./sanitizer/_flag_bool'), - // require('./sanitizer/_geonames_deprecation'), - // require('./sanitizer/_geonames_warnings'), - // require('./sanitizer/_geo_common'), - // require('./sanitizer/_geo_reverse'), - // require('./sanitizer/_groups'), - // require('./sanitizer/_ids'), - // require('./sanitizer/_iso2_to_iso3'), - // require('./sanitizer/_layers'), - // require('./sanitizer/_location_bias'), - // require('./sanitizer/_city_name_standardizer'), - // require('./sanitizer/_request_language'), - // require('./sanitizer/_single_scalar_parameters'), - // require('./sanitizer/_size'), - // require('./sanitizer/_sources'), - // require('./sanitizer/_sources_and_layers'), - // require('./sanitizer/_synthesize_analysis'), - // require('./sanitizer/_text'), - // require('./sanitizer/_text_addressit'), - // require('./sanitizer/_tokenizer'), - // require('./sanitizer/_deprecate_quattroshapes'), - // require('./sanitizer/_categories'), - // require('./sanitizer/nearby'), - // require('./sanitizer/autocomplete'), - // require('./sanitizer/structured_geocoding'), - // require('./sanitizer/place'), - // require('./sanitizer/reverse'), - // require('./sanitizer/sanitizeAll'), - // require('./sanitizer/search'), - // require('./sanitizer/defer_to_addressit'), - // require('./sanitizer/wrap'), - // require('./service/configurations/Interpolation'), - // require('./service/configurations/Language'), - // require('./service/configurations/PlaceHolder'), - // require('./service/configurations/PointInPolygon'), - // require('./service/mget'), - // require('./service/search') + require('./query/search'), + require('./query/search_original'), + require('./query/structured_geocoding'), + require('./query/text_parser'), + require('./sanitizer/_boundary_country'), + require('./sanitizer/_debug'), + require('./sanitizer/_flag_bool'), + require('./sanitizer/_geonames_deprecation'), + require('./sanitizer/_geonames_warnings'), + require('./sanitizer/_geo_common'), + require('./sanitizer/_geo_reverse'), + require('./sanitizer/_groups'), + require('./sanitizer/_ids'), + require('./sanitizer/_iso2_to_iso3'), + require('./sanitizer/_layers'), + require('./sanitizer/_location_bias'), + require('./sanitizer/_city_name_standardizer'), + require('./sanitizer/_request_language'), + require('./sanitizer/_single_scalar_parameters'), + require('./sanitizer/_size'), + require('./sanitizer/_sources'), + require('./sanitizer/_sources_and_layers'), + require('./sanitizer/_synthesize_analysis'), + require('./sanitizer/_text'), + require('./sanitizer/_text_addressit'), + require('./sanitizer/_tokenizer'), + require('./sanitizer/_deprecate_quattroshapes'), + require('./sanitizer/_categories'), + require('./sanitizer/nearby'), + require('./sanitizer/autocomplete'), + require('./sanitizer/structured_geocoding'), + require('./sanitizer/place'), + require('./sanitizer/reverse'), + require('./sanitizer/sanitizeAll'), + require('./sanitizer/search'), + require('./sanitizer/defer_to_addressit'), + require('./sanitizer/wrap'), + require('./service/configurations/Interpolation'), + require('./service/configurations/Language'), + require('./service/configurations/PlaceHolder'), + require('./service/configurations/PointInPolygon'), + require('./service/mget'), + require('./service/search') ]; tests.map(function(t) {