Browse Source

Merge pull request #1014 from pelias/remove-empire-when-country-exists

if country_gid exists, remove empire fields
pull/1016/merge
Stephen K Hess 7 years ago committed by GitHub
parent
commit
96825b589e
  1. 10
      helper/geojsonify_place_details.js
  2. 46
      test/unit/helper/geojsonify_place_details.js

10
helper/geojsonify_place_details.js

@ -46,6 +46,9 @@ const DETAILS_PROPS = [
{ name: 'continent', type: 'string' }, { name: 'continent', type: 'string' },
{ name: 'continent_gid', type: 'string' }, { name: 'continent_gid', type: 'string' },
{ name: 'continent_a', type: 'string' }, { name: 'continent_a', type: 'string' },
{ name: 'empire', type: 'string', condition: _.negate(hasCountry) },
{ name: 'empire_gid', type: 'string', condition: _.negate(hasCountry) },
{ name: 'empire_a', type: 'string', condition: _.negate(hasCountry) },
{ name: 'ocean', type: 'string' }, { name: 'ocean', type: 'string' },
{ name: 'ocean_gid', type: 'string' }, { name: 'ocean_gid', type: 'string' },
{ name: 'ocean_a', type: 'string' }, { name: 'ocean_a', type: 'string' },
@ -57,6 +60,11 @@ const DETAILS_PROPS = [
{ name: 'category', type: 'array', condition: checkCategoryParam } { name: 'category', type: 'array', condition: checkCategoryParam }
]; ];
// returns true IFF source a country_gid property
function hasCountry(params, source) {
return source.hasOwnProperty('country_gid');
}
function checkCategoryParam(params) { function checkCategoryParam(params) {
return _.isObject(params) && params.hasOwnProperty('categories'); return _.isObject(params) && params.hasOwnProperty('categories');
} }
@ -72,7 +80,7 @@ function checkCategoryParam(params) {
function collectProperties( params, source ) { function collectProperties( params, source ) {
return DETAILS_PROPS.reduce((result, prop) => { return DETAILS_PROPS.reduce((result, prop) => {
// if condition isn't met, don't set the property // if condition isn't met, don't set the property
if (_.isFunction(prop.condition) && !prop.condition(params)) { if (_.isFunction(prop.condition) && !prop.condition(params, source)) {
return result; return result;
} }

46
test/unit/helper/geojsonify_place_details.js

@ -532,6 +532,52 @@ module.exports.tests.geojsonify_place_details = (test, common) => {
}; };
module.exports.tests.empire_specific = (test, common) => {
test('empire* properties should not be output when country_gid property is available', t => {
const source = {
country_gid: 'country_gid value',
empire: 'empire value',
empire_gid: 'empire_gid value',
empire_a: 'empire_a value',
label: 'label value'
};
const expected = {
country_gid: 'country_gid value',
label: 'label value'
};
const actual = geojsonify({}, source);
t.deepEqual(actual, expected);
t.end();
});
test('empire* properties should be output when country_gid property is not available', t => {
const source = {
empire: 'empire value',
empire_gid: 'empire_gid value',
empire_a: 'empire_a value',
label: 'label value'
};
const expected = {
empire: 'empire value',
empire_gid: 'empire_gid value',
empire_a: 'empire_a value',
label: 'label value'
};
const actual = geojsonify({}, source);
t.deepEqual(actual, expected);
t.end();
});
};
module.exports.all = (tape, common) => { module.exports.all = (tape, common) => {
function test(name, testFunction) { function test(name, testFunction) {

Loading…
Cancel
Save