|
|
@ -12,28 +12,26 @@ module.exports.tests.trimByGranularity = function(test, common) { |
|
|
|
t.end(); |
|
|
|
t.end(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
test('when venue records are most granular, only they should be retained', function(t) { |
|
|
|
test('all records with fallback.* matched_queries name should retain only venues when they are most granular', function(t) { |
|
|
|
var req = { clean: {} }; |
|
|
|
var req = { clean: {} }; |
|
|
|
|
|
|
|
|
|
|
|
var res = { |
|
|
|
var res = { |
|
|
|
data: [ |
|
|
|
data: [ |
|
|
|
{ name: 'venue 1', layer: 'venue' }, |
|
|
|
{ name: 'venue 1', _matched_queries: ['fallback.venue'] }, |
|
|
|
{ name: 'venue 2', layer: 'venue' }, |
|
|
|
{ name: 'venue 2', _matched_queries: ['fallback.venue'] }, |
|
|
|
{ name: 'address 1', layer: 'address' }, |
|
|
|
{ name: 'address 1', _matched_queries: ['fallback.address'] }, |
|
|
|
{ name: 'neighbourhood 1', layer: 'neighbourhood' }, |
|
|
|
{ name: 'neighbourhood 1', _matched_queries: ['fallback.neighbourhood'] }, |
|
|
|
{ name: 'locality 1', layer: 'locality' }, |
|
|
|
{ name: 'locality 1', _matched_queries: ['fallback.locality'] }, |
|
|
|
{ name: 'localadmin 1', layer: 'localadmin' }, |
|
|
|
{ name: 'county 1', _matched_queries: ['fallback.county'] }, |
|
|
|
{ name: 'county 1', layer: 'county' }, |
|
|
|
{ name: 'region 1', _matched_queries: ['fallback.region'] }, |
|
|
|
{ name: 'macrocounty 1', layer: 'macrocounty' }, |
|
|
|
{ name: 'country 1', _matched_queries: ['fallback.country'] }, |
|
|
|
{ name: 'region 1', layer: 'region' }, |
|
|
|
{ name: 'unknown', _matched_queries: ['fallback.unknown'] } |
|
|
|
{ name: 'macroregion 1', layer: 'macroregion' }, |
|
|
|
|
|
|
|
{ name: 'country 1', layer: 'country' } |
|
|
|
|
|
|
|
] |
|
|
|
] |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var expected_data = [ |
|
|
|
var expected_data = [ |
|
|
|
{ name: 'venue 1', layer: 'venue' }, |
|
|
|
{ name: 'venue 1', _matched_queries: ['fallback.venue'] }, |
|
|
|
{ name: 'venue 2', layer: 'venue' }, |
|
|
|
{ name: 'venue 2', _matched_queries: ['fallback.venue'] }, |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
function testIt() { |
|
|
|
function testIt() { |
|
|
@ -44,30 +42,27 @@ module.exports.tests.trimByGranularity = function(test, common) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
testIt(); |
|
|
|
testIt(); |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
test('when address records are most granular, only they should be retained', function(t) { |
|
|
|
test('all records with fallback.* matched_queries name should retain only addresses when they are most granular', function(t) { |
|
|
|
var req = { clean: {} }; |
|
|
|
var req = { clean: {} }; |
|
|
|
|
|
|
|
|
|
|
|
var res = { |
|
|
|
var res = { |
|
|
|
data: [ |
|
|
|
data: [ |
|
|
|
{ name: 'address 1', layer: 'address' }, |
|
|
|
{ name: 'address 1', _matched_queries: ['fallback.address'] }, |
|
|
|
{ name: 'address 2', layer: 'address' }, |
|
|
|
{ name: 'address 2', _matched_queries: ['fallback.address'] }, |
|
|
|
{ name: 'neighbourhood 1', layer: 'neighbourhood' }, |
|
|
|
{ name: 'neighbourhood 1', _matched_queries: ['fallback.neighbourhood'] }, |
|
|
|
{ name: 'locality 1', layer: 'locality' }, |
|
|
|
{ name: 'locality 1', _matched_queries: ['fallback.locality'] }, |
|
|
|
{ name: 'localadmin 1', layer: 'localadmin' }, |
|
|
|
{ name: 'county 1', _matched_queries: ['fallback.county'] }, |
|
|
|
{ name: 'county 1', layer: 'county' }, |
|
|
|
{ name: 'region 1', _matched_queries: ['fallback.region'] }, |
|
|
|
{ name: 'macrocounty 1', layer: 'macrocounty' }, |
|
|
|
{ name: 'country 1', _matched_queries: ['fallback.country'] }, |
|
|
|
{ name: 'region 1', layer: 'region' }, |
|
|
|
{ name: 'unknown', _matched_queries: ['fallback.unknown'] } |
|
|
|
{ name: 'macroregion 1', layer: 'macroregion' }, |
|
|
|
|
|
|
|
{ name: 'country 1', layer: 'country' }, |
|
|
|
|
|
|
|
] |
|
|
|
] |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var expected_data = [ |
|
|
|
var expected_data = [ |
|
|
|
{ name: 'address 1', layer: 'address' }, |
|
|
|
{ name: 'address 1', _matched_queries: ['fallback.address'] }, |
|
|
|
{ name: 'address 2', layer: 'address' } |
|
|
|
{ name: 'address 2', _matched_queries: ['fallback.address'] }, |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
function testIt() { |
|
|
|
function testIt() { |
|
|
@ -78,31 +73,26 @@ module.exports.tests.trimByGranularity = function(test, common) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
testIt(); |
|
|
|
testIt(); |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
test('when neighbourhood records are most granular, only they should be retained', function(t) { |
|
|
|
test('all records with fallback.* matched_queries name should retain only neighbourhoods when they are most granular', function(t) { |
|
|
|
var req = { clean: {} }; |
|
|
|
var req = { clean: {} }; |
|
|
|
|
|
|
|
|
|
|
|
var res = { |
|
|
|
var res = { |
|
|
|
data: [ |
|
|
|
data: [ |
|
|
|
{ name: 'neighbourhood 1', layer: 'neighbourhood' }, |
|
|
|
{ name: 'neighbourhood 1', _matched_queries: ['fallback.neighbourhood'] }, |
|
|
|
{ name: 'neighbourhood 2', layer: 'neighbourhood' }, |
|
|
|
{ name: 'neighbourhood 2', _matched_queries: ['fallback.neighbourhood'] }, |
|
|
|
{ name: 'locality 1', layer: 'locality' }, |
|
|
|
{ name: 'locality 1', _matched_queries: ['fallback.locality'] }, |
|
|
|
{ name: 'locality 2', layer: 'locality' }, |
|
|
|
{ name: 'county 1', _matched_queries: ['fallback.county'] }, |
|
|
|
{ name: 'localadmin 1', layer: 'localadmin' }, |
|
|
|
{ name: 'region 1', _matched_queries: ['fallback.region'] }, |
|
|
|
{ name: 'localadmin 2', layer: 'localadmin' }, |
|
|
|
{ name: 'country 1', _matched_queries: ['fallback.country'] }, |
|
|
|
{ name: 'county 1', layer: 'county' }, |
|
|
|
{ name: 'unknown', _matched_queries: ['fallback.unknown'] } |
|
|
|
{ name: 'macrocounty 1', layer: 'macrocounty' }, |
|
|
|
|
|
|
|
{ name: 'region 1', layer: 'region' }, |
|
|
|
|
|
|
|
{ name: 'macroregion 1', layer: 'macroregion' }, |
|
|
|
|
|
|
|
{ name: 'country 1', layer: 'country' } |
|
|
|
|
|
|
|
] |
|
|
|
] |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var expected_data = [ |
|
|
|
var expected_data = [ |
|
|
|
{ name: 'neighbourhood 1', layer: 'neighbourhood' }, |
|
|
|
{ name: 'neighbourhood 1', _matched_queries: ['fallback.neighbourhood'] }, |
|
|
|
{ name: 'neighbourhood 2', layer: 'neighbourhood' } |
|
|
|
{ name: 'neighbourhood 2', _matched_queries: ['fallback.neighbourhood'] }, |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
function testIt() { |
|
|
|
function testIt() { |
|
|
@ -113,121 +103,106 @@ module.exports.tests.trimByGranularity = function(test, common) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
testIt(); |
|
|
|
testIt(); |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
test('when locality/localadmin records are most granular, only they should be retained', function(t) { |
|
|
|
test('all records with fallback.* matched_queries name should retain only localities when they are most granular', function(t) { |
|
|
|
var req = { clean: {} }; |
|
|
|
var req = { clean: {} }; |
|
|
|
|
|
|
|
|
|
|
|
var res = { |
|
|
|
var res = { |
|
|
|
data: [ |
|
|
|
data: [ |
|
|
|
{ name: 'locality 1', layer: 'locality' }, |
|
|
|
{ name: 'locality 1', _matched_queries: ['fallback.locality'] }, |
|
|
|
{ name: 'locality 2', layer: 'locality' }, |
|
|
|
{ name: 'locality 2', _matched_queries: ['fallback.locality'] }, |
|
|
|
{ name: 'localadmin 1', layer: 'localadmin' }, |
|
|
|
{ name: 'county 1', _matched_queries: ['fallback.county'] }, |
|
|
|
{ name: 'localadmin 2', layer: 'localadmin' }, |
|
|
|
{ name: 'region 1', _matched_queries: ['fallback.region'] }, |
|
|
|
{ name: 'county 1', layer: 'county' }, |
|
|
|
{ name: 'country 1', _matched_queries: ['fallback.country'] }, |
|
|
|
{ name: 'macrocounty 1', layer: 'macrocounty' }, |
|
|
|
{ name: 'unknown', _matched_queries: ['fallback.unknown'] } |
|
|
|
{ name: 'region 1', layer: 'region' }, |
|
|
|
|
|
|
|
{ name: 'macroregion 1', layer: 'macroregion' }, |
|
|
|
|
|
|
|
{ name: 'country 1', layer: 'country' }, |
|
|
|
|
|
|
|
] |
|
|
|
] |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var expected_data = [ |
|
|
|
var expected_data = [ |
|
|
|
{ name: 'locality 1', layer: 'locality' }, |
|
|
|
{ name: 'locality 1', _matched_queries: ['fallback.locality'] }, |
|
|
|
{ name: 'locality 2', layer: 'locality' }, |
|
|
|
{ name: 'locality 2', _matched_queries: ['fallback.locality'] }, |
|
|
|
{ name: 'localadmin 1', layer: 'localadmin' }, |
|
|
|
|
|
|
|
{ name: 'localadmin 2', layer: 'localadmin' } |
|
|
|
|
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
function testIt() { |
|
|
|
function testIt() { |
|
|
|
trimByGranularity(req, res, function() { |
|
|
|
trimByGranularity(req, res, function() { |
|
|
|
t.deepEquals(res.data, expected_data, 'only locality/localadmin records should be here'); |
|
|
|
t.deepEquals(res.data, expected_data, 'only locality records should be here'); |
|
|
|
t.end(); |
|
|
|
t.end(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
testIt(); |
|
|
|
testIt(); |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
test('when county/macrocounty records are most granular, only they should be retained', function(t) { |
|
|
|
test('all records with fallback.* matched_queries name should retain only venues when they are most granular', function(t) { |
|
|
|
var req = { clean: {} }; |
|
|
|
var req = { clean: {} }; |
|
|
|
|
|
|
|
|
|
|
|
var res = { |
|
|
|
var res = { |
|
|
|
data: [ |
|
|
|
data: [ |
|
|
|
{ name: 'county 1', layer: 'county' }, |
|
|
|
{ name: 'county 1', _matched_queries: ['fallback.county'] }, |
|
|
|
{ name: 'county 2', layer: 'county' }, |
|
|
|
{ name: 'county 2', _matched_queries: ['fallback.county'] }, |
|
|
|
{ name: 'macrocounty 1', layer: 'macrocounty' }, |
|
|
|
{ name: 'region 1', _matched_queries: ['fallback.region'] }, |
|
|
|
{ name: 'macrocounty 2', layer: 'macrocounty' }, |
|
|
|
{ name: 'country 1', _matched_queries: ['fallback.country'] }, |
|
|
|
{ name: 'region 1', layer: 'region' }, |
|
|
|
{ name: 'unknown', _matched_queries: ['fallback.unknown'] } |
|
|
|
{ name: 'macroregion 1', layer: 'macroregion' }, |
|
|
|
|
|
|
|
{ name: 'country 1', layer: 'country' }, |
|
|
|
|
|
|
|
] |
|
|
|
] |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var expected_data = [ |
|
|
|
var expected_data = [ |
|
|
|
{ name: 'county 1', layer: 'county' }, |
|
|
|
{ name: 'county 1', _matched_queries: ['fallback.county'] }, |
|
|
|
{ name: 'county 2', layer: 'county' }, |
|
|
|
{ name: 'county 2', _matched_queries: ['fallback.county'] }, |
|
|
|
{ name: 'macrocounty 1', layer: 'macrocounty' }, |
|
|
|
|
|
|
|
{ name: 'macrocounty 2', layer: 'macrocounty' }, |
|
|
|
|
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
function testIt() { |
|
|
|
function testIt() { |
|
|
|
trimByGranularity(req, res, function() { |
|
|
|
trimByGranularity(req, res, function() { |
|
|
|
t.deepEquals(res.data, expected_data, 'only county/macrocounty records should be here'); |
|
|
|
t.deepEquals(res.data, expected_data, 'only county records should be here'); |
|
|
|
t.end(); |
|
|
|
t.end(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
testIt(); |
|
|
|
testIt(); |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
test('when region/macroregion records are most granular, only they should be retained', function(t) { |
|
|
|
test('all records with fallback.* matched_queries name should retain only venues when they are most granular', function(t) { |
|
|
|
var req = { clean: {} }; |
|
|
|
var req = { clean: {} }; |
|
|
|
|
|
|
|
|
|
|
|
var res = { |
|
|
|
var res = { |
|
|
|
data: [ |
|
|
|
data: [ |
|
|
|
{ name: 'region 1', layer: 'region' }, |
|
|
|
{ name: 'region 1', _matched_queries: ['fallback.region'] }, |
|
|
|
{ name: 'region 2', layer: 'region' }, |
|
|
|
{ name: 'region 2', _matched_queries: ['fallback.region'] }, |
|
|
|
{ name: 'macroregion 1', layer: 'macroregion' }, |
|
|
|
{ name: 'country 1', _matched_queries: ['fallback.country'] }, |
|
|
|
{ name: 'macroregion 2', layer: 'macroregion' }, |
|
|
|
{ name: 'unknown', _matched_queries: ['fallback.unknown'] } |
|
|
|
{ name: 'country 1', layer: 'country' }, |
|
|
|
|
|
|
|
] |
|
|
|
] |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var expected_data = [ |
|
|
|
var expected_data = [ |
|
|
|
{ name: 'region 1', layer: 'region' }, |
|
|
|
{ name: 'region 1', _matched_queries: ['fallback.region'] }, |
|
|
|
{ name: 'region 2', layer: 'region' }, |
|
|
|
{ name: 'region 2', _matched_queries: ['fallback.region'] }, |
|
|
|
{ name: 'macroregion 1', layer: 'macroregion' }, |
|
|
|
|
|
|
|
{ name: 'macroregion 2', layer: 'macroregion' } |
|
|
|
|
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
function testIt() { |
|
|
|
function testIt() { |
|
|
|
trimByGranularity(req, res, function() { |
|
|
|
trimByGranularity(req, res, function() { |
|
|
|
t.deepEquals(res.data, expected_data, 'only region/macroregion records should be here'); |
|
|
|
t.deepEquals(res.data, expected_data, 'only region records should be here'); |
|
|
|
t.end(); |
|
|
|
t.end(); |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
testIt(); |
|
|
|
testIt(); |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
test('when country records are most granular, only they should be retained', function(t) { |
|
|
|
test('all records with fallback.* matched_queries name should retain only countries when they are most granular', function(t) { |
|
|
|
var req = { clean: {} }; |
|
|
|
var req = { clean: {} }; |
|
|
|
|
|
|
|
|
|
|
|
var res = { |
|
|
|
var res = { |
|
|
|
data: [ |
|
|
|
data: [ |
|
|
|
{ name: 'country 1', layer: 'country' }, |
|
|
|
{ name: 'country 1', _matched_queries: ['fallback.country'] }, |
|
|
|
{ name: 'country 2', layer: 'country' } |
|
|
|
{ name: 'country 2', _matched_queries: ['fallback.country'] }, |
|
|
|
|
|
|
|
{ name: 'unknown', _matched_queries: ['fallback.unknown'] } |
|
|
|
] |
|
|
|
] |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var expected_data = [ |
|
|
|
var expected_data = [ |
|
|
|
{ name: 'country 1', layer: 'country' }, |
|
|
|
{ name: 'country 1', _matched_queries: ['fallback.country'] }, |
|
|
|
{ name: 'country 2', layer: 'country' } |
|
|
|
{ name: 'country 2', _matched_queries: ['fallback.country'] }, |
|
|
|
]; |
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
function testIt() { |
|
|
|
function testIt() { |
|
|
@ -237,6 +212,33 @@ module.exports.tests.trimByGranularity = function(test, common) { |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
testIt(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test('presence of any non-fallback.* named queries should not trim', function(t) { |
|
|
|
|
|
|
|
var req = { clean: {} }; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var res = { |
|
|
|
|
|
|
|
data: [ |
|
|
|
|
|
|
|
{ name: 'region', _matched_queries: ['fallback.region'] }, |
|
|
|
|
|
|
|
{ name: 'country', _matched_queries: ['fallback.country'] }, |
|
|
|
|
|
|
|
{ name: 'result with non-named query' } |
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var expected_data = [ |
|
|
|
|
|
|
|
{ name: 'region', _matched_queries: ['fallback.region'] }, |
|
|
|
|
|
|
|
{ name: 'country', _matched_queries: ['fallback.country'] }, |
|
|
|
|
|
|
|
{ name: 'result with non-named query' } |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function testIt() { |
|
|
|
|
|
|
|
trimByGranularity(req, res, function() { |
|
|
|
|
|
|
|
t.deepEquals(res.data, expected_data, 'all should results should have been retained'); |
|
|
|
|
|
|
|
t.end(); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
testIt(); |
|
|
|
testIt(); |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|