Browse Source

Fix all unit tests

pull/426/head
Diana Shkolnikov 9 years ago committed by Julian Simioni
parent
commit
af8044ef29
  1. 2
      helper/labelGenerator.js
  2. 16
      test/unit/controller/search.js
  3. 14
      test/unit/fixture/autocomplete_linguistic_with_admin.js
  4. 16
      test/unit/fixture/dedupe_elasticsearch_nonascii_results.js
  5. 184
      test/unit/fixture/dedupe_elasticsearch_results.js
  6. 2
      test/unit/fixture/reverse_with_boundary_country.js
  7. 2
      test/unit/fixture/search_boundary_country.js
  8. 48
      test/unit/fixture/search_full_address.js
  9. 38
      test/unit/fixture/search_partial_address.js
  10. 38
      test/unit/fixture/search_regions_address.js
  11. 4
      test/unit/helper/labelGenerator_SGP.js
  12. 4
      test/unit/helper/labelGenerator_SWE.js
  13. 8
      test/unit/mock/backend.js
  14. 17
      test/unit/query/search.js
  15. 12
      test/unit/sanitiser/_layers.js
  16. 2
      test/unit/sanitiser/search.js
  17. 4
      test/unit/service/mget.js
  18. 4
      test/unit/service/search.js

2
helper/labelGenerator.js

@ -52,6 +52,6 @@ function getInitialLabel(record) {
return []; return [];
} }
return [record.name.default]; return [record.name];
} }

16
test/unit/controller/search.js

@ -50,9 +50,11 @@ module.exports.tests.functional_success = function(test, common) {
_id: 'myid1', _id: 'myid1',
_score: 10, _score: 10,
_type: 'mytype1', _type: 'mytype1',
admin0: 'country1', parent: {
admin1: 'state1', country: 'country1',
admin2: 'city1', region: 'state1',
county: 'city1'
},
center_point: { lat: 100.1, lon: -50.5 }, center_point: { lat: 100.1, lon: -50.5 },
name: { default: 'test name1' }, name: { default: 'test name1' },
value: 1 value: 1
@ -61,9 +63,11 @@ module.exports.tests.functional_success = function(test, common) {
_id: 'myid2', _id: 'myid2',
_score: 20, _score: 20,
_type: 'mytype2', _type: 'mytype2',
admin0: 'country2', parent: {
admin1: 'state2', country: 'country2',
admin2: 'city2', region: 'state2',
county: 'city2'
},
center_point: { lat: 100.2, lon: -51.5 }, center_point: { lat: 100.2, lon: -51.5 },
name: { default: 'test name2' }, name: { default: 'test name2' },
value: 2 value: 2

14
test/unit/fixture/autocomplete_linguistic_with_admin.js

@ -20,7 +20,7 @@ module.exports = {
'should': [ 'should': [
{ {
'match': { 'match': {
'admin0': { 'parent.country': {
'analyzer': 'peliasAdmin', 'analyzer': 'peliasAdmin',
'boost': 800, 'boost': 800,
'query': 'three' 'query': 'three'
@ -29,7 +29,7 @@ module.exports = {
}, },
{ {
'match': { 'match': {
'admin1': { 'parent.region': {
'analyzer': 'peliasAdmin', 'analyzer': 'peliasAdmin',
'boost': 600, 'boost': 600,
'query': 'three' 'query': 'three'
@ -38,7 +38,7 @@ module.exports = {
}, },
{ {
'match': { 'match': {
'admin1_abbr': { 'parent.region_a': {
'analyzer': 'peliasAdmin', 'analyzer': 'peliasAdmin',
'boost': 600, 'boost': 600,
'query': 'three' 'query': 'three'
@ -47,7 +47,7 @@ module.exports = {
}, },
{ {
'match': { 'match': {
'admin2': { 'parent.county': {
'analyzer': 'peliasAdmin', 'analyzer': 'peliasAdmin',
'boost': 400, 'boost': 400,
'query': 'three' 'query': 'three'
@ -56,7 +56,7 @@ module.exports = {
}, },
{ {
'match': { 'match': {
'local_admin': { 'parent.localadmin': {
'analyzer': 'peliasAdmin', 'analyzer': 'peliasAdmin',
'boost': 200, 'boost': 200,
'query': 'three' 'query': 'three'
@ -65,7 +65,7 @@ module.exports = {
}, },
{ {
'match': { 'match': {
'locality': { 'parent.locality': {
'analyzer': 'peliasAdmin', 'analyzer': 'peliasAdmin',
'boost': 200, 'boost': 200,
'query': 'three' 'query': 'three'
@ -74,7 +74,7 @@ module.exports = {
}, },
{ {
'match': { 'match': {
'neighborhood': { 'parent.neighbourhood': {
'analyzer': 'peliasAdmin', 'analyzer': 'peliasAdmin',
'boost': 200, 'boost': 200,
'query': 'three' 'query': 'three'

16
test/unit/fixture/dedupe_elasticsearch_nonascii_results.js

@ -7,9 +7,11 @@ module.exports = [
'name': { 'name': {
'default': '万里长城万里长城' 'default': '万里长城万里长城'
}, },
'parent': {
'country_a': 'CHN', 'country_a': 'CHN',
'country': 'China', 'country': 'China',
'region': 'Beijing', 'region': 'Beijing'
},
'confidence': 0.733 'confidence': 0.733
}, },
{ {
@ -20,9 +22,11 @@ module.exports = [
'name': { 'name': {
'default': '万里长城' 'default': '万里长城'
}, },
'parent': {
'country_a': 'CHN', 'country_a': 'CHN',
'country': 'China', 'country': 'China',
'region': 'Beijing', 'region': 'Beijing'
},
'confidence': 0.733 'confidence': 0.733
}, },
{ {
@ -33,12 +37,14 @@ module.exports = [
'name': { 'name': {
'default': '万里花' 'default': '万里花'
}, },
'parent': {
'country_a': 'JPN', 'country_a': 'JPN',
'country': 'Japan', 'country': 'Japan',
'region': 'Tokyo', 'region': 'Tokyo',
'county': '豊島区', 'county': '豊島区',
'locality': 'Tokyo', 'locality': 'Tokyo',
'neighbourhood': '2丁目', 'neighbourhood': '2丁目'
},
'confidence': 0.646 'confidence': 0.646
}, },
{ {
@ -53,9 +59,11 @@ module.exports = [
'street': 'S308', 'street': 'S308',
'postalcode': '312044' 'postalcode': '312044'
}, },
'parent': {
'country_a': 'CHN', 'country_a': 'CHN',
'country': 'China', 'country': 'China',
'region': 'Zhejiang', 'region': 'Zhejiang'
},
'confidence': 0.646 'confidence': 0.646
} }
]; ];

184
test/unit/fixture/dedupe_elasticsearch_results.js

@ -5,17 +5,19 @@ module.exports = [
'lat': 40.039265 'lat': 40.039265
}, },
'address': {}, 'address': {},
'local_admin': 'East Lampeter', 'parent': {
'admin1_abbr': 'PA', 'localadmin': 'East Lampeter',
'region_a': 'PA',
'region': 'Pennsylvania',
'locality': 'Smoketown',
'country_a': 'USA',
'county': 'Lancaster County',
'country': 'United States',
'neighbourhood': 'Greenland'
},
'name': { 'name': {
'default': 'East Lampeter High School' 'default': 'East Lampeter High School'
}, },
'admin1': 'Pennsylvania',
'locality': 'Smoketown',
'alpha3': 'USA',
'admin2': 'Lancaster County',
'admin0': 'United States',
'neighborhood': 'Greenland',
'category': [ 'category': [
'education' 'education'
], ],
@ -30,17 +32,19 @@ module.exports = [
'lat': 40.039265 'lat': 40.039265
}, },
'address': {}, 'address': {},
'local_admin': 'East Lampeter', 'parent': {
'admin1_abbr': 'PA', 'localadmin': 'East Lampeter',
'region_a': 'PA',
'region': 'Pennsylvania',
'locality': 'Smoketown',
'country_a': 'USA',
'county': 'Lancaster County',
'country': 'United States',
'neighbourhood': 'Greenland'
},
'name': { 'name': {
'default': 'East Lampeter, High-School' 'default': 'East Lampeter, High-School'
}, },
'admin1': 'Pennsylvania',
'locality': 'Smoketown',
'alpha3': 'USA',
'admin2': 'Lancaster County',
'admin0': 'United States',
'neighborhood': 'Greenland',
'category': [ 'category': [
'education' 'education'
], ],
@ -55,17 +59,19 @@ module.exports = [
'lat': 39.99288 'lat': 39.99288
}, },
'address': {}, 'address': {},
'local_admin': 'West Lampeter', 'parent': {
'admin1_abbr': 'PA', 'localadmin': 'West Lampeter',
'region_a': 'PA',
'region': 'Pennsylvania',
'locality': 'Lampeter',
'country_a': 'USA',
'county': 'Lancaster County',
'country': 'United States',
'neighbourhood': 'Wheatland Mills'
},
'name': { 'name': {
'default': 'Lampeter-Strasburg High School' 'default': 'Lampeter-Strasburg High School'
}, },
'admin1': 'Pennsylvania',
'locality': 'Lampeter',
'alpha3': 'USA',
'admin2': 'Lancaster County',
'admin0': 'United States',
'neighborhood': 'Wheatland Mills',
'category': [ 'category': [
'education' 'education'
], ],
@ -80,17 +86,19 @@ module.exports = [
'lat': 40.03927 'lat': 40.03927
}, },
'address': {}, 'address': {},
'local_admin': 'East Lampeter', 'parent': {
'admin1_abbr': 'PA', 'localadmin': 'East Lampeter',
'region_a': 'PA',
'region': 'Pennsylvania',
'locality': 'Smoketown',
'country_a': 'USA',
'county': 'Lancaster County',
'country': 'United States',
'neighbourhood': 'Greenland'
},
'name': { 'name': {
'default': 'East Lampeter High School' 'default': 'East Lampeter High School'
}, },
'admin1': 'Pennsylvania',
'locality': 'Smoketown',
'alpha3': 'USA',
'admin2': 'Lancaster County',
'admin0': 'United States',
'neighborhood': 'Greenland',
'category': [ 'category': [
'education' 'education'
], ],
@ -105,17 +113,19 @@ module.exports = [
'lat': 39.992877 'lat': 39.992877
}, },
'address': {}, 'address': {},
'local_admin': 'West Lampeter', 'parent': {
'admin1_abbr': 'PA', 'region': 'Pennsylvania',
'locality': 'Lampeter',
'country_a': 'USA',
'county': 'Lancaster County',
'country': 'United States',
'neighbourhood': 'Wheatland Mills',
'localadmin': 'West Lampeter',
'region_a': 'PA'
},
'name': { 'name': {
'default': 'Lampeter-Strasburg High School' 'default': 'Lampeter-Strasburg High School'
}, },
'admin1': 'Pennsylvania',
'locality': 'Lampeter',
'alpha3': 'USA',
'admin2': 'Lancaster County',
'admin0': 'United States',
'neighborhood': 'Wheatland Mills',
'category': [ 'category': [
'education' 'education'
], ],
@ -130,17 +140,19 @@ module.exports = [
'lat': 40.038987 'lat': 40.038987
}, },
'address': {}, 'address': {},
'local_admin': 'East Lampeter', 'parent': {
'admin1_abbr': 'PA', 'region': 'Pennsylvania',
'locality': 'Smoketown',
'country_a': 'USA',
'county': 'Lancaster County',
'country': 'United States',
'neighbourhood': 'Greenland',
'localadmin': 'East Lampeter',
'region_a': 'PA'
},
'name': { 'name': {
'default': 'East Lampeter School' 'default': 'East Lampeter School'
}, },
'admin1': 'Pennsylvania',
'locality': 'Smoketown',
'alpha3': 'USA',
'admin2': 'Lancaster County',
'admin0': 'United States',
'neighborhood': 'Greenland',
'category': [ 'category': [
'education' 'education'
], ],
@ -155,17 +167,19 @@ module.exports = [
'lat': 40.03899 'lat': 40.03899
}, },
'address': {}, 'address': {},
'local_admin': 'East Lampeter', 'parent': {
'admin1_abbr': 'PA', 'region': 'Pennsylvania',
'locality': 'Smoketown',
'country_a': 'USA',
'county': 'Lancaster County',
'country': 'United States',
'neighbourhood': 'Greenland',
'localadmin': 'East Lampeter',
'region_a': 'PA'
},
'name': { 'name': {
'default': 'East Lampeter School' 'default': 'East Lampeter School'
}, },
'admin1': 'Pennsylvania',
'locality': 'Smoketown',
'alpha3': 'USA',
'admin2': 'Lancaster County',
'admin0': 'United States',
'neighborhood': 'Greenland',
'category': [ 'category': [
'education' 'education'
], ],
@ -180,16 +194,18 @@ module.exports = [
'lat': 38.762788 'lat': 38.762788
}, },
'address': {}, 'address': {},
'local_admin': 'Polk', 'parent': {
'admin1_abbr': 'MO', 'region': 'Missouri',
'locality': 'Strasburg',
'country_a': 'USA',
'county': 'Cass County',
'country': 'United States',
'localadmin': 'Polk',
'region_a': 'MO'
},
'name': { 'name': {
'default': 'Strasburg School' 'default': 'Strasburg School'
}, },
'admin1': 'Missouri',
'locality': 'Strasburg',
'alpha3': 'USA',
'admin2': 'Cass County',
'admin0': 'United States',
'category': [ 'category': [
'education' 'education'
], ],
@ -204,16 +220,18 @@ module.exports = [
'lat': 38.98445 'lat': 38.98445
}, },
'address': {}, 'address': {},
'admin1_abbr': 'VA',
'name': { 'name': {
'default': 'Strasburg High School' 'default': 'Strasburg High School'
}, },
'admin1': 'Virginia', 'parent': {
'region_a': 'VA',
'region': 'Virginia',
'locality': 'Strasburg', 'locality': 'Strasburg',
'alpha3': 'USA', 'country_a': 'USA',
'admin2': 'Shenandoah County', 'county': 'Shenandoah County',
'admin0': 'United States', 'country': 'United States',
'neighborhood': 'Strasburg Junction', 'neighbourhood': 'Strasburg Junction'
},
'category': [ 'category': [
'education' 'education'
], ],
@ -228,16 +246,18 @@ module.exports = [
'lat': 46.13427 'lat': 46.13427
}, },
'address': {}, 'address': {},
'local_admin': 'Strasburg',
'admin1_abbr': 'ND',
'name': { 'name': {
'default': 'Strasburg High School' 'default': 'Strasburg High School'
}, },
'admin1': 'North Dakota', 'parent': {
'localadmin': 'Strasburg',
'region_a': 'ND',
'region': 'North Dakota',
'locality': 'Strasburg', 'locality': 'Strasburg',
'alpha3': 'USA', 'country_a': 'USA',
'admin2': 'Emmons County', 'county': 'Emmons County',
'admin0': 'United States', 'country': 'United States'
},
'category': [ 'category': [
'education' 'education'
], ],
@ -252,16 +272,18 @@ module.exports = [
'lat': 40.597578 'lat': 40.597578
}, },
'address': {}, 'address': {},
'local_admin': 'Franklin',
'admin1_abbr': 'OH',
'name': { 'name': {
'default': 'Strasburg High School' 'default': 'Strasburg High School'
}, },
'admin1': 'Ohio', 'parent': {
'localadmin': 'Franklin',
'region_a': 'OH',
'region': 'Ohio',
'locality': 'Strasburg', 'locality': 'Strasburg',
'alpha3': 'USA', 'country_a': 'USA',
'admin2': 'Tuscarawas County', 'county': 'Tuscarawas County',
'admin0': 'United States', 'country': 'United States'
},
'category': [ 'category': [
'education' 'education'
], ],

2
test/unit/fixture/reverse_with_boundary_country.js

@ -8,7 +8,7 @@ module.exports = {
'must': [ 'must': [
{ {
'match': { 'match': {
'alpha3': { 'parent.country_a': {
'analyzer': 'standard', 'analyzer': 'standard',
'query': 'ABC' 'query': 'ABC'
} }

2
test/unit/fixture/search_boundary_country.js

@ -7,7 +7,7 @@ module.exports = {
'must': [ 'must': [
{ {
'match': { 'match': {
'alpha3': { 'parent.country_a': {
'analyzer': 'standard', 'analyzer': 'standard',
'query': 'ABC' 'query': 'ABC'
} }

48
test/unit/fixture/search_full_address.js

@ -109,55 +109,55 @@ module.exports = {
} }
}, { }, {
'match': { 'match': {
'alpha3': { 'parent.country': {
'query': 'USA', 'query': 'new york',
'boost': vs['admin:alpha3:boost'], 'boost': vs['admin:country:boost'],
'analyzer': vs['admin:alpha3:analyzer'] 'analyzer': vs['admin:country:analyzer']
} }
} }
}, { }, {
'match': { 'match': {
'admin0': { 'parent.country_a': {
'query': 'new york', 'query': 'USA',
'boost': vs['admin:admin0:boost'], 'boost': vs['admin:country_a:boost'],
'analyzer': vs['admin:admin0:analyzer'] 'analyzer': vs['admin:country_a:analyzer']
} }
} }
}, { }, {
'match': { 'match': {
'admin1': { 'parent.region': {
'query': 'new york', 'query': 'new york',
'boost': vs['admin:admin1:boost'], 'boost': vs['admin:region:boost'],
'analyzer': vs['admin:admin1:analyzer'] 'analyzer': vs['admin:region:analyzer']
} }
} }
}, { }, {
'match': { 'match': {
'admin1_abbr': { 'parent.region_a': {
'query': 'NY', 'query': 'NY',
'boost': vs['admin:admin1_abbr:boost'], 'boost': vs['admin:region_a:boost'],
'analyzer': vs['admin:admin1_abbr:analyzer'] 'analyzer': vs['admin:region_a:analyzer']
} }
} }
}, { }, {
'match': { 'match': {
'admin2': { 'parent.county': {
'query': 'new york', 'query': 'new york',
'boost': vs['admin:admin2:boost'], 'boost': vs['admin:county:boost'],
'analyzer': vs['admin:admin2:analyzer'] 'analyzer': vs['admin:county:analyzer']
} }
} }
}, { }, {
'match': { 'match': {
'local_admin': { 'parent.localadmin': {
'query': 'new york', 'query': 'new york',
'boost': vs['admin:local_admin:boost'], 'boost': vs['admin:localadmin:boost'],
'analyzer': vs['admin:local_admin:analyzer'] 'analyzer': vs['admin:localadmin:analyzer']
} }
} }
}, { }, {
'match': { 'match': {
'locality': { 'parent.locality': {
'query': 'new york', 'query': 'new york',
'boost': vs['admin:locality:boost'], 'boost': vs['admin:locality:boost'],
'analyzer': vs['admin:locality:analyzer'] 'analyzer': vs['admin:locality:analyzer']
@ -165,10 +165,10 @@ module.exports = {
} }
}, { }, {
'match': { 'match': {
'neighborhood': { 'parent.neighbourhood': {
'query': 'new york', 'query': 'new york',
'boost': vs['admin:neighborhood:boost'], 'boost': vs['admin:neighbourhood:boost'],
'analyzer': vs['admin:neighborhood:analyzer'] 'analyzer': vs['admin:neighbourhood:analyzer']
} }
} }
}] }]

38
test/unit/fixture/search_partial_address.js

@ -85,47 +85,47 @@ module.exports = {
} }
},{ },{
'match': { 'match': {
'admin0': { 'parent.country': {
'query': 'new york', 'query': 'new york',
'boost': vs['admin:admin0:boost'], 'boost': vs['admin:country:boost'],
'analyzer': vs['admin:admin0:analyzer'] 'analyzer': vs['admin:country:analyzer']
} }
} }
}, { }, {
'match': { 'match': {
'admin1': { 'parent.region': {
'query': 'new york', 'query': 'new york',
'boost': vs['admin:admin1:boost'], 'boost': vs['admin:region:boost'],
'analyzer': vs['admin:admin1:analyzer'] 'analyzer': vs['admin:region:analyzer']
} }
} }
}, { }, {
'match': { 'match': {
'admin1_abbr': { 'parent.region_a': {
'query': 'new york', 'query': 'new york',
'boost': vs['admin:admin1_abbr:boost'], 'boost': vs['admin:region_a:boost'],
'analyzer': vs['admin:admin1_abbr:analyzer'] 'analyzer': vs['admin:region_a:analyzer']
} }
} }
}, { }, {
'match': { 'match': {
'admin2': { 'parent.county': {
'query': 'new york', 'query': 'new york',
'boost': vs['admin:admin2:boost'], 'boost': vs['admin:county:boost'],
'analyzer': vs['admin:admin2:analyzer'] 'analyzer': vs['admin:county:analyzer']
} }
} }
}, { }, {
'match': { 'match': {
'local_admin': { 'parent.localadmin': {
'query': 'new york', 'query': 'new york',
'boost': vs['admin:local_admin:boost'], 'boost': vs['admin:localadmin:boost'],
'analyzer': vs['admin:local_admin:analyzer'] 'analyzer': vs['admin:localadmin:analyzer']
} }
} }
}, { }, {
'match': { 'match': {
'locality': { 'parent.locality': {
'query': 'new york', 'query': 'new york',
'boost': vs['admin:locality:boost'], 'boost': vs['admin:locality:boost'],
'analyzer': vs['admin:locality:analyzer'] 'analyzer': vs['admin:locality:analyzer']
@ -133,10 +133,10 @@ module.exports = {
} }
}, { }, {
'match': { 'match': {
'neighborhood': { 'parent.neighbourhood': {
'query': 'new york', 'query': 'new york',
'boost': vs['admin:neighborhood:boost'], 'boost': vs['admin:neighbourhood:boost'],
'analyzer': vs['admin:neighborhood:analyzer'] 'analyzer': vs['admin:neighbourhood:analyzer']
} }
} }
}] }]

38
test/unit/fixture/search_regions_address.js

@ -101,47 +101,47 @@ module.exports = {
} }
}, { }, {
'match': { 'match': {
'admin0': { 'parent.country': {
'query': 'manhattan', 'query': 'manhattan',
'boost': vs['admin:admin0:boost'], 'boost': vs['admin:country:boost'],
'analyzer': vs['admin:admin0:analyzer'] 'analyzer': vs['admin:country:analyzer']
} }
} }
}, { }, {
'match': { 'match': {
'admin1': { 'parent.region': {
'query': 'manhattan', 'query': 'manhattan',
'boost': vs['admin:admin1:boost'], 'boost': vs['admin:region:boost'],
'analyzer': vs['admin:admin1:analyzer'] 'analyzer': vs['admin:region:analyzer']
} }
} }
}, { }, {
'match': { 'match': {
'admin1_abbr': { 'parent.region_a': {
'query': 'NY', 'query': 'NY',
'boost': vs['admin:admin1_abbr:boost'], 'boost': vs['admin:region_a:boost'],
'analyzer': vs['admin:admin1_abbr:analyzer'] 'analyzer': vs['admin:region_a:analyzer']
} }
} }
}, { }, {
'match': { 'match': {
'admin2': { 'parent.county': {
'query': 'manhattan', 'query': 'manhattan',
'boost': vs['admin:admin2:boost'], 'boost': vs['admin:county:boost'],
'analyzer': vs['admin:admin2:analyzer'] 'analyzer': vs['admin:county:analyzer']
} }
} }
}, { }, {
'match': { 'match': {
'local_admin': { 'parent.localadmin': {
'query': 'manhattan', 'query': 'manhattan',
'boost': vs['admin:local_admin:boost'], 'boost': vs['admin:localadmin:boost'],
'analyzer': vs['admin:local_admin:analyzer'] 'analyzer': vs['admin:localadmin:analyzer']
} }
} }
}, { }, {
'match': { 'match': {
'locality': { 'parent.locality': {
'query': 'manhattan', 'query': 'manhattan',
'boost': vs['admin:locality:boost'], 'boost': vs['admin:locality:boost'],
'analyzer': vs['admin:locality:analyzer'] 'analyzer': vs['admin:locality:analyzer']
@ -149,10 +149,10 @@ module.exports = {
} }
}, { }, {
'match': { 'match': {
'neighborhood': { 'parent.neighbourhood': {
'query': 'manhattan', 'query': 'manhattan',
'boost': vs['admin:neighborhood:boost'], 'boost': vs['admin:neighbourhood:boost'],
'analyzer': vs['admin:neighborhood:analyzer'] 'analyzer': vs['admin:neighbourhood:analyzer']
} }
} }
}] }]

4
test/unit/helper/labelGenerator_SGP.js

@ -14,7 +14,7 @@ module.exports.tests.interface = function(test, common) {
module.exports.tests.north_west_singapore = function(test, common) { module.exports.tests.north_west_singapore = function(test, common) {
test('north west singapore', function(t) { test('north west singapore', function(t) {
var doc = { var doc = {
'name': { 'default': 'North West' }, 'name': 'North West',
'country_a': 'SGP', 'country_a': 'SGP',
'country': 'Singapore', 'country': 'Singapore',
'region': 'North West' 'region': 'North West'
@ -28,7 +28,7 @@ module.exports.tests.north_west_singapore = function(test, common) {
module.exports.tests.singapore_mcdonalds = function(test, common) { module.exports.tests.singapore_mcdonalds = function(test, common) {
test('singapore_mcdonalds', function(t) { test('singapore_mcdonalds', function(t) {
var doc = { var doc = {
'name': { 'default': 'McDonald\'s' }, 'name': 'McDonald\'s',
'country_a': 'SGP', 'country_a': 'SGP',
'country': 'Singapore', 'country': 'Singapore',
'region': 'Central Singapore', 'region': 'Central Singapore',

4
test/unit/helper/labelGenerator_SWE.js

@ -14,7 +14,7 @@ module.exports.tests.interface = function(test, common) {
module.exports.tests.skane1 = function(test, common) { module.exports.tests.skane1 = function(test, common) {
test('skåne 1', function(t) { test('skåne 1', function(t) {
var doc = { var doc = {
'name': { 'default': 'Malmö' }, 'name': 'Malmö',
'country_a': 'SWE', 'country_a': 'SWE',
'country': 'Sweden', 'country': 'Sweden',
'region': 'Skåne', 'region': 'Skåne',
@ -29,7 +29,7 @@ module.exports.tests.skane1 = function(test, common) {
module.exports.tests.skane2 = function(test, common) { module.exports.tests.skane2 = function(test, common) {
test('skåne 2', function(t) { test('skåne 2', function(t) {
var doc = { var doc = {
'name': { 'default': 'Malmö' }, 'name': 'Malmö',
'country_a': 'SWE', 'country_a': 'SWE',
'country': 'Sweden', 'country': 'Sweden',
'region': 'Skåne', 'region': 'Skåne',

8
test/unit/mock/backend.js

@ -15,7 +15,7 @@ responses['client/search/ok/1'] = function( cmd, cb ){
value: 1, value: 1,
center_point: { lat: 100.1, lon: -50.5 }, center_point: { lat: 100.1, lon: -50.5 },
name: { default: 'test name1' }, name: { default: 'test name1' },
admin0: 'country1', admin1: 'state1', admin2: 'city1' parent: { country: 'country1', region: 'state1', county: 'city1' }
} }
}, { }, {
_id: 'myid2', _id: 'myid2',
@ -25,7 +25,7 @@ responses['client/search/ok/1'] = function( cmd, cb ){
value: 2, value: 2,
center_point: { lat: 100.2, lon: -51.5 }, center_point: { lat: 100.2, lon: -51.5 },
name: { default: 'test name2' }, name: { default: 'test name2' },
admin0: 'country2', admin1: 'state2', admin2: 'city2' parent: { country: 'country2', region: 'state2', county: 'city2' }
} }
}])); }]));
}; };
@ -43,7 +43,7 @@ responses['client/mget/ok/1'] = function( cmd, cb ){
value: 1, value: 1,
center_point: { lat: 100.1, lon: -50.5 }, center_point: { lat: 100.1, lon: -50.5 },
name: { default: 'test name1' }, name: { default: 'test name1' },
admin0: 'country1', admin1: 'state1', admin2: 'city1' parent: { country: 'country1', region: 'state1', county: 'city1' }
} }
}, { }, {
_id: 'myid2', _id: 'myid2',
@ -54,7 +54,7 @@ responses['client/mget/ok/1'] = function( cmd, cb ){
value: 2, value: 2,
center_point: { lat: 100.2, lon: -51.5 }, center_point: { lat: 100.2, lon: -51.5 },
name: { default: 'test name2' }, name: { default: 'test name2' },
admin0: 'country2', admin1: 'state2', admin2: 'city2' parent: { country: 'country2', region: 'state2', county: 'city2' }
} }
}])); }]));
}; };

17
test/unit/query/search.js

@ -126,8 +126,7 @@ 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: [ 'address', 'venue', 'country', 'region', 'county', 'neighbourhood', 'locality', 'localadmin' ],
'locality', 'local_admin', 'osmaddress', 'openaddresses' ],
querySize: 10, querySize: 10,
parsed_text: parser.get_parsed_address(address), parsed_text: parser.get_parsed_address(address),
}); });
@ -135,15 +134,20 @@ 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_full_address'); var expected = require('../fixture/search_full_address');
t.deepEqual(compiled, expected, 'valid search query'); t.deepEqual(compiled.query.filtered.query.bool.should, expected.query.filtered.query.bool.should, 'valid boundary.country query');
[ { match: { 'phrase.default': { analyzer: 'peliasPhrase', boost: 1, query: '123 main st', slop: 2, type: 'phrase' } } }, { function_score: { boost_mode: 'replace', filter: { exists: { field: 'popularity' } }, functions: [ { field_value_factor: [Object], weight: 1 } ], max_boost: 20, query: { match: { 'phrase.default': [Object] } }, score_mode: 'first' } }, { function_score: { boost_mode: 'replace', filter: { exists: { field: 'population' } }, functions: [ { field_value_factor: [Object], weight: 2 } ], max_boost: 20, query: { match: { 'phrase.default': [Object] } }, score_mode: 'first' } }, { match: { 'address.number': { analyzer: 'peliasHousenumber', boost: 2, query: '123' } } }, { match: { 'address.street': { analyzer: 'peliasStreet', boost: 5, query: 'main st' } } }, { match: { 'address.zip': { analyzer: 'peliasZip', boost: 20, query: '10010' } } }, { match: { 'parent.country_a': { analyzer: 'standard', boost: 5, query: 'USA' } } }, { match: { 'parent.country': { analyzer: 'peliasAdmin', boost: 4, query: 'new york' } } }, { match: { 'parent.region': { analyzer: 'peliasAdmin', boost: 3, query: 'new york' } } }, { match: { 'parent.region_a': { analyzer: 'peliasAdmin', boost: 3, query: 'NY' } } }, { match: { 'parent.county': { analyzer: 'peliasAdmin', boost: 2, query: 'new york' } } }, { match: { 'parent.localadmin': { analyzer: 'peliasAdmin', boost: 1, query: 'new york' } } }, { match: { 'parent.locality': { analyzer: 'peliasAdmin', boost: 1, query: 'new york' } } }, { match: { 'parent.neighbourhood': { analyzer: 'peliasAdmin', boost: 1, query: 'new york' } } } ]
[ { match: { 'phrase.default': { analyzer: 'peliasPhrase', boost: 1, query: '123 main st', slop: 2, type: 'phrase' } } }, { function_score: { boost_mode: 'replace', filter: { exists: { field: 'popularity' } }, functions: [ { field_value_factor: [Object], weight: 1 } ], max_boost: 20, query: { match: { 'phrase.default': [Object] } }, score_mode: 'first' } }, { function_score: { boost_mode: 'replace', filter: { exists: { field: 'population' } }, functions: [ { field_value_factor: [Object], weight: 2 } ], max_boost: 20, query: { match: { 'phrase.default': [Object] } }, score_mode: 'first' } }, { match: { 'address.number': { analyzer: 'peliasHousenumber', boost: 2, query: '123' } } }, { match: { 'address.street': { analyzer: 'peliasStreet', boost: 5, query: 'main st' } } }, { match: { 'address.zip': { analyzer: 'peliasZip', boost: 20, query: '10010' } } }, { match: { 'parent.country': { analyzer: 'peliasAdmin', boost: 4, query: 'new york' } } }, { match: { 'parent.country_a': { analyzer: 'standard', boost: 5, query: 'USA' } } }, { match: { 'parent.region': { analyzer: 'peliasAdmin', boost: 3, query: 'new york' } } }, { match: { 'parent.region_a': { analyzer: 'peliasAdmin', boost: 3, query: 'NY' } } }, { match: { 'parent.county': { analyzer: 'peliasAdmin', boost: 2, query: 'new york' } } }, { match: { 'parent.localadmin': { analyzer: 'peliasAdmin', boost: 1, query: 'new york' } } }, { match: { 'parent.locality': { analyzer: 'peliasAdmin', boost: 1, query: 'new york' } } }, { match: { 'parent.neighbourhood': { analyzer: 'peliasAdmin', boost: 1, query: 'new york' } } } ]
//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: [ 'address', 'venue', 'country', 'region', 'county', 'neighbourhood', 'locality', 'localadmin' ],
'locality', 'local_admin', 'osmaddress', 'openaddresses' ],
querySize: 10, querySize: 10,
parsed_text: parser.get_parsed_address(partial_address), parsed_text: parser.get_parsed_address(partial_address),
}); });
@ -158,8 +162,7 @@ module.exports.tests.query = function(test, common) {
test('valid query with regions in address', function(t) { test('valid query with regions in address', function(t) {
var partial_address = '1 water st manhattan ny'; var partial_address = '1 water st manhattan ny';
var query = generate({ text: partial_address, var query = generate({ text: partial_address,
layers: [ 'geoname', 'osmnode', 'osmway', 'admin0', 'admin1', 'admin2', 'neighborhood', layers: [ 'address', 'venue', 'country', 'region', 'county', 'neighbourhood', 'locality', 'localadmin' ],
'locality', 'local_admin', 'osmaddress', 'openaddresses' ],
querySize: 10, querySize: 10,
parsed_text: parser.get_parsed_address(partial_address), parsed_text: parser.get_parsed_address(partial_address),
}); });

12
test/unit/sanitiser/_layers.js

@ -43,7 +43,7 @@ module.exports.tests.sanitize_layers = function(test, common) {
var admin_layers = [ 'continent', 'macrocountry', 'country', 'dependency', var admin_layers = [ 'continent', 'macrocountry', 'country', 'dependency',
'region', 'locality', 'localadmin', 'county', 'macrohood', 'neighbourhood', 'region', 'locality', 'localadmin', 'county', 'macrohood', 'neighbourhood',
'microhood', 'disputed', 'admin0', 'admin1', 'admin2', 'neighborhood', 'local_admin' ]; 'microhood', 'disputed' ];
t.deepEqual(clean.layers, admin_layers, 'coarse layers set'); t.deepEqual(clean.layers, admin_layers, 'coarse layers set');
t.end(); t.end();
@ -65,7 +65,7 @@ module.exports.tests.sanitize_layers = function(test, common) {
sanitize(raw, clean); sanitize(raw, clean);
var expected_layers = ['venue', 'country', 'admin0', 'region', 'admin1']; var expected_layers = ['venue', 'country', 'region'];
t.deepEqual(clean.layers, expected_layers, 'venue + regular layers'); t.deepEqual(clean.layers, expected_layers, 'venue + regular layers');
t.end(); t.end();
}); });
@ -78,7 +78,7 @@ module.exports.tests.sanitize_layers = function(test, common) {
var expected_layers = [ 'continent', 'macrocountry', 'country', 'dependency', var expected_layers = [ 'continent', 'macrocountry', 'country', 'dependency',
'region', 'locality', 'localadmin', 'county', 'macrohood', 'neighbourhood', 'region', 'locality', 'localadmin', 'county', 'macrohood', 'neighbourhood',
'microhood', 'disputed', 'admin0', 'admin1', 'admin2', 'neighborhood', 'local_admin' ]; 'microhood', 'disputed' ];
t.deepEqual(clean.layers, expected_layers, 'coarse + regular layers set'); t.deepEqual(clean.layers, expected_layers, 'coarse + regular layers set');
t.end(); t.end();
@ -90,7 +90,7 @@ module.exports.tests.sanitize_layers = function(test, common) {
sanitize(raw, clean); sanitize(raw, clean);
var expected_layers = ['address', 'country', 'admin0', 'locality' ]; var expected_layers = ['address', 'country', 'locality' ];
t.deepEqual(clean.layers, expected_layers, 'address + regular layers set'); t.deepEqual(clean.layers, expected_layers, 'address + regular layers set');
t.end(); t.end();
}); });
@ -101,7 +101,7 @@ module.exports.tests.sanitize_layers = function(test, common) {
sanitize(raw, clean); sanitize(raw, clean);
var expected_layers = ['venue', 'country', 'admin0']; var expected_layers = ['venue', 'country'];
t.deepEqual(clean.layers, expected_layers, 'venue layers found (no duplicates)'); t.deepEqual(clean.layers, expected_layers, 'venue layers found (no duplicates)');
t.end(); t.end();
}); });
@ -115,7 +115,7 @@ module.exports.tests.sanitize_layers = function(test, common) {
var coarse_layers = [ 'continent', 'macrocountry', var coarse_layers = [ 'continent', 'macrocountry',
'country', 'dependency', 'region', 'locality', 'localadmin', 'country', 'dependency', 'region', 'locality', 'localadmin',
'county', 'macrohood', 'neighbourhood', 'microhood', 'county', 'macrohood', 'neighbourhood', 'microhood',
'disputed', 'admin0', 'admin1', 'admin2', 'neighborhood', 'local_admin']; 'disputed' ];
var venue_layers = [ 'venue' ]; var venue_layers = [ 'venue' ];
var expected_layers = venue_layers.concat(coarse_layers); var expected_layers = venue_layers.concat(coarse_layers);

2
test/unit/sanitiser/search.js

@ -72,7 +72,7 @@ module.exports.tests.sanitise_valid_text = function(test, common) {
}; };
module.exports.tests.sanitize_text_with_delim = function(test, common) { module.exports.tests.sanitize_text_with_delim = function(test, common) {
var texts = [ 'a,bcd', '123 main st, admin1', ',,,', ' ' ]; var texts = [ 'a,bcd', '123 main st, region', ',,,', ' ' ];
test('valid texts with a comma', function(t) { test('valid texts with a comma', function(t) {
texts.forEach( function( text ){ texts.forEach( function( text ){

4
test/unit/service/mget.js

@ -20,14 +20,14 @@ module.exports.tests.functional_success = function(test, common) {
value: 1, value: 1,
center_point: { lat: 100.1, lon: -50.5 }, center_point: { lat: 100.1, lon: -50.5 },
name: { default: 'test name1' }, name: { default: 'test name1' },
admin0: 'country1', admin1: 'state1', admin2: 'city1' parent: { country: 'country1', region: 'state1', county: 'city1' }
}, },
{ {
_id: 'myid2', _type: 'mytype2', _id: 'myid2', _type: 'mytype2',
value: 2, value: 2,
center_point: { lat: 100.2, lon: -51.5 }, center_point: { lat: 100.2, lon: -51.5 },
name: { default: 'test name2' }, name: { default: 'test name2' },
admin0: 'country2', admin1: 'state2', admin2: 'city2' parent: { country: 'country2', region: 'state2', county: 'city2' }
} }
]; ];

4
test/unit/service/search.js

@ -23,7 +23,7 @@ module.exports.tests.functional_success = function(test, common) {
value: 1, value: 1,
center_point: { lat: 100.1, lon: -50.5 }, center_point: { lat: 100.1, lon: -50.5 },
name: { default: 'test name1' }, name: { default: 'test name1' },
admin0: 'country1', admin1: 'state1', admin2: 'city1' parent: { country: 'country1', region: 'state1', county: 'city1' }
}, },
{ {
_id: 'myid2', _type: 'mytype2', _id: 'myid2', _type: 'mytype2',
@ -31,7 +31,7 @@ module.exports.tests.functional_success = function(test, common) {
value: 2, value: 2,
center_point: { lat: 100.2, lon: -51.5 }, center_point: { lat: 100.2, lon: -51.5 },
name: { default: 'test name2' }, name: { default: 'test name2' },
admin0: 'country2', admin1: 'state2', admin2: 'city2' parent: { country: 'country2', region: 'state2', county: 'city2' }
} }
]; ];

Loading…
Cancel
Save