@ -22,6 +22,7 @@ module.exports.tests.trimByGranularity = function(test, common) {
{ name : 'street 1' , _matched _queries : [ 'fallback.street' ] } ,
{ name : 'address 1' , _matched _queries : [ 'fallback.address' ] } ,
{ name : 'neighbourhood 1' , _matched _queries : [ 'fallback.neighbourhood' ] } ,
{ name : 'borough 1' , _matched _queries : [ 'fallback.borough' ] } ,
{ name : 'locality 1' , _matched _queries : [ 'fallback.locality' ] } ,
{ name : 'localadmin 1' , _matched _queries : [ 'fallback.localadmin' ] } ,
{ name : 'county 1' , _matched _queries : [ 'fallback.county' ] } ,
@ -58,6 +59,7 @@ module.exports.tests.trimByGranularity = function(test, common) {
{ name : 'street 2' , _matched _queries : [ 'fallback.street' ] } ,
{ name : 'address 1' , _matched _queries : [ 'fallback.address' ] } ,
{ name : 'neighbourhood 1' , _matched _queries : [ 'fallback.neighbourhood' ] } ,
{ name : 'borough 1' , _matched _queries : [ 'fallback.borough' ] } ,
{ name : 'locality 1' , _matched _queries : [ 'fallback.locality' ] } ,
{ name : 'localadmin 1' , _matched _queries : [ 'fallback.localadmin' ] } ,
{ name : 'county 1' , _matched _queries : [ 'fallback.county' ] } ,
@ -93,6 +95,7 @@ module.exports.tests.trimByGranularity = function(test, common) {
{ name : 'address 1' , _matched _queries : [ 'fallback.address' ] } ,
{ name : 'address 2' , _matched _queries : [ 'fallback.address' ] } ,
{ name : 'neighbourhood 1' , _matched _queries : [ 'fallback.neighbourhood' ] } ,
{ name : 'borough 1' , _matched _queries : [ 'fallback.borough' ] } ,
{ name : 'locality 1' , _matched _queries : [ 'fallback.locality' ] } ,
{ name : 'localadmin 1' , _matched _queries : [ 'fallback.localadmin' ] } ,
{ name : 'county 1' , _matched _queries : [ 'fallback.county' ] } ,
@ -127,6 +130,7 @@ module.exports.tests.trimByGranularity = function(test, common) {
data : [
{ name : 'neighbourhood 1' , _matched _queries : [ 'fallback.neighbourhood' ] } ,
{ name : 'neighbourhood 2' , _matched _queries : [ 'fallback.neighbourhood' ] } ,
{ name : 'borough 1' , _matched _queries : [ 'fallback.borough' ] } ,
{ name : 'locality 1' , _matched _queries : [ 'fallback.locality' ] } ,
{ name : 'localadmin 1' , _matched _queries : [ 'fallback.localadmin' ] } ,
{ name : 'county 1' , _matched _queries : [ 'fallback.county' ] } ,
@ -154,6 +158,89 @@ module.exports.tests.trimByGranularity = function(test, common) {
testIt ( ) ;
} ) ;
test ( 'all records with fallback.* matched_queries name should retain only boroughs when they are most granular' , function ( t ) {
var req = {
clean : {
parsed _text : {
borough : 'borough value'
}
}
} ;
var res = {
data : [
{ name : 'borough 1' , _matched _queries : [ 'fallback.borough' ] } ,
{ name : 'borough 2' , _matched _queries : [ 'fallback.borough' ] } ,
{ name : 'locality 1' , _matched _queries : [ 'fallback.locality' ] } ,
{ name : 'localadmin 1' , _matched _queries : [ 'fallback.localadmin' ] } ,
{ name : 'county 1' , _matched _queries : [ 'fallback.county' ] } ,
{ name : 'macrocounty 1' , _matched _queries : [ 'fallback.macrocounty' ] } ,
{ name : 'region 1' , _matched _queries : [ 'fallback.region' ] } ,
{ name : 'macroregion 1' , _matched _queries : [ 'fallback.macroregion' ] } ,
{ name : 'dependency 1' , _matched _queries : [ 'fallback.dependency' ] } ,
{ name : 'country 1' , _matched _queries : [ 'fallback.country' ] } ,
{ name : 'unknown' , _matched _queries : [ 'fallback.unknown' ] }
]
} ;
var expected _data = [
{ name : 'borough 1' , _matched _queries : [ 'fallback.borough' ] } ,
{ name : 'borough 2' , _matched _queries : [ 'fallback.borough' ] } ,
] ;
function testIt ( ) {
trimByGranularity ( req , res , function ( ) {
t . deepEquals ( res . data , expected _data , 'only borough records should be here' ) ;
t . end ( ) ;
} ) ;
}
testIt ( ) ;
} ) ;
test ( 'if req.parsed_text has city but not borough then borough and city results should be returned' , function ( t ) {
var req = {
clean : {
parsed _text : {
city : 'city value'
}
}
} ;
var res = {
data : [
{ name : 'borough 1' , _matched _queries : [ 'fallback.borough' ] } ,
{ name : 'borough 2' , _matched _queries : [ 'fallback.borough' ] } ,
{ name : 'locality 1' , _matched _queries : [ 'fallback.locality' ] } ,
{ name : 'locality 2' , _matched _queries : [ 'fallback.locality' ] } ,
{ name : 'localadmin 1' , _matched _queries : [ 'fallback.localadmin' ] } ,
{ name : 'county 1' , _matched _queries : [ 'fallback.county' ] } ,
{ name : 'macrocounty 1' , _matched _queries : [ 'fallback.macrocounty' ] } ,
{ name : 'region 1' , _matched _queries : [ 'fallback.region' ] } ,
{ name : 'macroregion 1' , _matched _queries : [ 'fallback.macroregion' ] } ,
{ name : 'dependency 1' , _matched _queries : [ 'fallback.dependency' ] } ,
{ name : 'country 1' , _matched _queries : [ 'fallback.country' ] } ,
{ name : 'unknown' , _matched _queries : [ 'fallback.unknown' ] }
]
} ;
var expected _data = [
{ name : 'borough 1' , _matched _queries : [ 'fallback.borough' ] } ,
{ name : 'borough 2' , _matched _queries : [ 'fallback.borough' ] } ,
{ name : 'locality 1' , _matched _queries : [ 'fallback.locality' ] } ,
{ name : 'locality 2' , _matched _queries : [ 'fallback.locality' ] }
] ;
function testIt ( ) {
trimByGranularity ( req , res , function ( ) {
t . deepEquals ( res . data , expected _data , 'only borough/locality records should be here' ) ;
t . end ( ) ;
} ) ;
}
testIt ( ) ;
} ) ;
test ( 'all records with fallback.* matched_queries name should retain only localities when they are most granular' , function ( t ) {
var req = { clean : { } } ;