Browse Source

added support for city+country inputs

pull/730/head
Stephen Hess 8 years ago
parent
commit
7670eef3fb
  1. 20
      query/search.js
  2. 158
      test/unit/query/search.js

20
query/search.js

@ -120,7 +120,7 @@ function generateQuery( clean ){
}
function getQuery(vs) {
if (hasStreet(vs) || isCityStateOnlyWithOptionalCountry(vs)) {
if (hasStreet(vs) || isCityStateOnlyWithOptionalCountry(vs) || isCityCountryOnly(vs)) {
return {
type: 'fallback',
body: fallbackQuery.render(vs)
@ -138,8 +138,8 @@ function hasStreet(vs) {
}
function isCityStateOnlyWithOptionalCountry(vs) {
var isSet = function(layer) {
return vs.isset('input:' + layer);
var isSet = (layer) => {
return vs.isset(`input:${layer}`);
};
var allowedFields = ['locality', 'region'];
@ -150,4 +150,18 @@ function isCityStateOnlyWithOptionalCountry(vs) {
}
function isCityCountryOnly(vs) {
var isSet = (layer) => {
return vs.isset(`input:${layer}`);
};
var allowedFields = ['locality', 'country'];
var disallowedFields = ['query', 'category', 'housenumber', 'street',
'neighbourhood', 'borough', 'postcode', 'county', 'region'];
return allowedFields.every(isSet) &&
!disallowedFields.some(isSet);
}
module.exports = generateQuery;

158
test/unit/query/search.js

@ -447,6 +447,164 @@ module.exports.tests.city_state = function(test, common) {
};
module.exports.tests.city_country = function(test, common) {
test('only city and country set should return query', function(t) {
var clean = {
parsed_text: {
'city': 'city value',
'country': 'country value'
}
};
var query = generate(clean);
t.notEqual(query, undefined, 'should not have returned undefined');
t.end();
});
test('city-only should return undefined', function(t) {
var clean = {
parsed_text: {
city: 'city value'
}
};
var query = generate(clean);
t.equals(query, undefined, 'should have returned undefined');
t.end();
});
test('country-only should return undefined', function(t) {
var clean = {
parsed_text: {
country: 'country value'
}
};
var query = generate(clean);
t.equals(query, undefined, 'should have returned undefined');
t.end();
});
test('city/country with query should return undefined', function(t) {
var clean = {
parsed_text: {
city: 'city value',
country: 'country value',
query: 'query value'
}
};
var query = generate(clean);
t.equals(query, undefined, 'should have returned undefined');
t.end();
});
test('city/country with category should return undefined', function(t) {
var clean = {
parsed_text: {
city: 'city value',
country: 'country value',
category: 'category value'
}
};
var query = generate(clean);
t.equals(query, undefined, 'should have returned undefined');
t.end();
});
test('city/country with number should return undefined', function(t) {
var clean = {
parsed_text: {
city: 'city value',
country: 'country value',
number: 'number value'
}
};
var query = generate(clean);
t.equals(query, undefined, 'should have returned undefined');
t.end();
});
test('city/country with neighbourhood should return undefined', function(t) {
var clean = {
parsed_text: {
city: 'city value',
country: 'country value',
neighbourhood: 'neighbourhood value'
}
};
var query = generate(clean);
t.equals(query, undefined, 'should have returned undefined');
t.end();
});
test('city/country with borough should return undefined', function(t) {
var clean = {
parsed_text: {
city: 'city value',
country: 'country value',
borough: 'borough value'
}
};
var query = generate(clean);
t.equals(query, undefined, 'should have returned undefined');
t.end();
});
test('city/country with postalcode should return undefined', function(t) {
var clean = {
parsed_text: {
city: 'city value',
country: 'country value',
postalcode: 'postalcode value'
}
};
var query = generate(clean);
t.equals(query, undefined, 'should have returned undefined');
t.end();
});
test('city/country with county should return undefined', function(t) {
var clean = {
parsed_text: {
city: 'city value',
country: 'country value',
county: 'county value'
}
};
var query = generate(clean);
t.equals(query, undefined, 'should have returned undefined');
t.end();
});
};
module.exports.all = function (tape, common) {
function test(name, testFunction) {
return tape('search query ' + name, testFunction);

Loading…
Cancel
Save