diff --git a/labelSchema.js b/labelSchema.js index f01a357..fe04b7d 100644 --- a/labelSchema.js +++ b/labelSchema.js @@ -1,11 +1,9 @@ -var _ = require('lodash'); +const _ = require('lodash'); const removeAccents = require('remove-accents'); // lowercase characters and remove some punctuation function normalizeString(str){ - if (!str) { - return ''; - } + if (!str) { return ''; } return removeAccents(str.toLowerCase().split(/[ ,-]+/).join(' ')); } @@ -21,11 +19,8 @@ function getFirstProperty(fields) { if (!_.isEmpty(fieldValue)) { return fieldValue[0]; } - } - }; - } // this function is exclusively used for figuring out which field to use for states/provinces @@ -235,7 +230,7 @@ module.exports = { }, 'FRA': { 'valueFunctions': { - 'local': getFirstProperty(['locality', 'localadmin']), + 'local': getFirstProperty(['locality', 'localadmin', 'county', 'macrocounty']), 'country': getFRACountryValue() } }, diff --git a/test/labelGenerator_FRA.js b/test/labelGenerator_FRA.js index b825356..678684f 100644 --- a/test/labelGenerator_FRA.js +++ b/test/labelGenerator_FRA.js @@ -9,7 +9,7 @@ module.exports.tests.interface = function(test, common) { }); }; -module.exports.tests.united_kingdom = function(test, common) { +module.exports.tests.france = function(test, common) { test('venue', function(t) { var doc = { 'name': { 'default': 'venue name' }, @@ -378,6 +378,37 @@ module.exports.tests.united_kingdom = function(test, common) { t.end(); }); + test('postalcode with locality', function(t) { + var doc = { + 'name': { 'default': '69001' }, + 'layer': 'postalcode', + 'locality': ['Lyon'], + 'county': ['Metropolitan Lyon'], + 'macrocounty': ['Lyon'], + 'region': ['Rhône'], + 'macroregion': ['Auvergne-Rhone-Alpes'], + 'country_a': ['FRA'], + 'country': ['France'] + }; + t.equal(generator(doc),'69001, Lyon, France'); + t.end(); + }); + + test('postalcode without locality or localadmin', function(t) { + var doc = { + 'name': { 'default': '13080' }, + 'layer': 'postalcode', + 'county': ['Aix-en-Provence Canton'], + 'macrocounty': ['Aix-En-Provence'], + 'region': ['Bouches-du-Rhône'], + 'macroregion': ['Provence-Alpes-Cote d\'Azur'], + 'country_a': ['FRA'], + 'country': ['France'] + }; + t.equal(generator(doc),'13080, Aix-en-Provence Canton, France'); + t.end(); + }); + }; module.exports.all = function (tape, common) {