Skip to content

Commit

Permalink
Merge pull request #1317 from pelias/fix-address-related-queries
Browse files Browse the repository at this point in the history
fix(predicate): Fix address related layers detection
  • Loading branch information
orangejulius authored Jun 18, 2019
2 parents 287f8f0 + 3a05567 commit 106a90a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ const Debug = require('../../helper/debug');
const debugLog = new Debug('controller:predicates:is_request_layers_any_address_related');
const stackTraceLine = require('../../helper/stackTraceLine');

const admin_placetypes = require('../../helper/placeTypes');

// return true if any layers allowed by the query are related to an address query
// this includes address, street, and any admin layers, but NOT venue and custom layers
// this includes address and street but NOT venue, postalcode, admin, and custom layers
module.exports = (req, res) => {
const address_related_layers = admin_placetypes.concat(['address', 'street']);
const address_related_layers = ['address', 'street'];

const request_layers = _.get(req, 'clean.layers', []);
let result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,22 @@ module.exports.tests.true_conditions = (test, common) => {
t.end();
});

test('admin layers only should return true', t => {
const req = { clean: { layers: ['locality', 'county', 'country'] } };
test('street layer only should return true', t => {
const req = { clean: { layers: ['street'] } };

t.ok(is_request_layers_any_address_related(req));
t.end();
});

test('street and admin layers', t => {
const req = { clean: { layers: ['street', 'locality', 'country'] } };
test('address and postalcode layers should return true', t => {
const req = { clean: { layers: ['address', 'postalcode'] } };

t.ok(is_request_layers_any_address_related(req));
t.end();
});

test('street and admin layers should return true', t => {
const req = { clean: { layers: ['street', 'macrocounty'] } };

t.ok(is_request_layers_any_address_related(req));
t.end();
Expand All @@ -40,6 +47,14 @@ module.exports.tests.false_conditions = (test, common) => {
t.notOk(is_request_layers_any_address_related(req));
t.end();
});

test('admin layers only should return false', t => {
const req = { clean: { layers: ['locality', 'county', 'country'] } };

t.notOk(is_request_layers_any_address_related(req));
t.end();
});

};

module.exports.all = (tape, common) => {
Expand Down

0 comments on commit 106a90a

Please sign in to comment.