Browse Source

combined non-county layers into one

pull/912/head
Stephen Hess 7 years ago
parent
commit
ea3572539f
  1. 6
      query/address_search_using_ids.js
  2. 180
      test/unit/query/address_search_using_ids.js

6
query/address_search_using_ids.js

@ -66,10 +66,8 @@ addressUsingIdsQuery.filter( peliasQuery.view.sources );
// if there are region/macroregion layers, return ['region', 'macroregion'] // if there are region/macroregion layers, return ['region', 'macroregion']
const granularity_bands = [ const granularity_bands = [
['neighbourhood', 'borough', 'locality', 'localadmin'], ['neighbourhood', 'borough', 'locality', 'localadmin', 'region', 'macroregion', 'dependency', 'country'],
['county', 'macrocounty'], ['county', 'macrocounty']
['region', 'macroregion'],
['dependency', 'country']
]; ];
function anyResultsAtGranularityBand(results, band) { function anyResultsAtGranularityBand(results, band) {

180
test/unit/query/address_search_using_ids.js

@ -179,119 +179,64 @@ module.exports.tests.granularity_bands = (test, common) => {
source_id: 5 source_id: 5
}, },
{ {
layer: 'neighbourhood', layer: 'macrocounty',
source_id: 6 source_id: 6
}, },
{ {
layer: 'borough', layer: 'region',
source_id: 7 source_id: 7
}, },
{ {
layer: 'locality', layer: 'macroregion',
source_id: 8 source_id: 8
}, },
{ {
layer: 'localadmin', layer: 'dependency',
source_id: 9 source_id: 9
}
]
};
const generateQuery = proxyquire('../../../query/address_search_using_ids', {
'pelias-logger': logger,
'pelias-query': {
layout: {
AddressesUsingIdsQuery: MockQuery
}, },
view: views, {
Vars: require('pelias-query').Vars layer: 'country',
} source_id: 10
},
});
const generatedQuery = generateQuery(clean, res);
t.deepEquals(JSON.parse(generatedQuery.body.vs.var('input:layers')), {
neighbourhood: [1, 6],
borough: [2, 7],
locality: [3, 8],
localadmin: [4, 9]
});
t.end();
});
test('only band members with ids should be passed', (t) => {
const logger = mock_logger();
const clean = {
parsed_text: {
number: 'housenumber value',
street: 'street value'
}
};
const res = {
data: [
{ {
layer: 'neighbourhood', layer: 'neighbourhood',
source_id: 1 source_id: 11
} },
] {
}; layer: 'borough',
source_id: 12
const generateQuery = proxyquire('../../../query/address_search_using_ids', { },
'pelias-logger': logger, {
'pelias-query': { layer: 'locality',
layout: { source_id: 13
AddressesUsingIdsQuery: MockQuery },
{
layer: 'localadmin',
source_id: 14
}, },
view: views,
Vars: require('pelias-query').Vars
}
});
const generatedQuery = generateQuery(clean, res);
t.deepEquals(JSON.parse(generatedQuery.body.vs.var('input:layers')), {
neighbourhood: [1],
borough: [],
locality: [],
localadmin: []
});
t.end();
});
test('county/macrocounty granularity band', (t) => {
const logger = mock_logger();
const clean = {
parsed_text: {
number: 'housenumber value',
street: 'street value'
}
};
const res = {
data: [
{ {
layer: 'county', layer: 'county',
source_id: 1 source_id: 15
}, },
{ {
layer: 'macrocounty', layer: 'macrocounty',
source_id: 2 source_id: 16
}, },
{ {
layer: 'region', layer: 'region',
source_id: 3 source_id: 17
}, },
{ {
layer: 'county', layer: 'macroregion',
source_id: 4 source_id: 18
}, },
{ {
layer: 'macrocounty', layer: 'dependency',
source_id: 5 source_id: 19
},
{
layer: 'country',
source_id: 20
} }
] ]
}; };
@ -311,14 +256,20 @@ module.exports.tests.granularity_bands = (test, common) => {
const generatedQuery = generateQuery(clean, res); const generatedQuery = generateQuery(clean, res);
t.deepEquals(JSON.parse(generatedQuery.body.vs.var('input:layers')), { t.deepEquals(JSON.parse(generatedQuery.body.vs.var('input:layers')), {
county: [1, 4], neighbourhood: [1, 11],
macrocounty: [2, 5] borough: [2, 12],
locality: [3, 13],
localadmin: [4, 14],
region: [7, 17],
macroregion: [8, 18],
dependency: [9, 19],
country: [10, 20]
}); });
t.end(); t.end();
}); });
test('region/macroregion granularity band', (t) => { test('only band members with ids should be passed', (t) => {
const logger = mock_logger(); const logger = mock_logger();
const clean = { const clean = {
@ -330,24 +281,8 @@ module.exports.tests.granularity_bands = (test, common) => {
const res = { const res = {
data: [ data: [
{ {
layer: 'region', layer: 'neighbourhood',
source_id: 1 source_id: 1
},
{
layer: 'macroregion',
source_id: 2
},
{
layer: 'country',
source_id: 3
},
{
layer: 'region',
source_id: 4
},
{
layer: 'macroregion',
source_id: 5
} }
] ]
}; };
@ -361,21 +296,25 @@ module.exports.tests.granularity_bands = (test, common) => {
view: views, view: views,
Vars: require('pelias-query').Vars Vars: require('pelias-query').Vars
} }
}); });
const generatedQuery = generateQuery(clean, res); const generatedQuery = generateQuery(clean, res);
t.deepEquals(JSON.parse(generatedQuery.body.vs.var('input:layers')), { t.deepEquals(JSON.parse(generatedQuery.body.vs.var('input:layers')), {
region: [1, 4], neighbourhood: [1],
macroregion: [2, 5] borough: [],
locality: [],
localadmin: [],
region: [],
macroregion: [],
dependency: [],
country: []
}); });
t.end(); t.end();
}); });
test('dependency/country granularity band', (t) => { test('county/macrocounty granularity band', (t) => {
const logger = mock_logger(); const logger = mock_logger();
const clean = { const clean = {
@ -387,20 +326,20 @@ module.exports.tests.granularity_bands = (test, common) => {
const res = { const res = {
data: [ data: [
{ {
layer: 'dependency', layer: 'county',
source_id: 1 source_id: 1
}, },
{ {
layer: 'country', layer: 'macrocounty',
source_id: 2 source_id: 2
}, },
{ {
layer: 'dependency', layer: 'county',
source_id: 3 source_id: 4
}, },
{ {
layer: 'country', layer: 'macrocounty',
source_id: 4 source_id: 5
} }
] ]
}; };
@ -420,12 +359,11 @@ module.exports.tests.granularity_bands = (test, common) => {
const generatedQuery = generateQuery(clean, res); const generatedQuery = generateQuery(clean, res);
t.deepEquals(JSON.parse(generatedQuery.body.vs.var('input:layers')), { t.deepEquals(JSON.parse(generatedQuery.body.vs.var('input:layers')), {
dependency: [1, 3], county: [1, 4],
country: [2, 4] macrocounty: [2, 5]
}); });
t.end(); t.end();
}); });
}; };

Loading…
Cancel
Save