From 1a156488d2142ac007a309ffee15e1bf7df6d2fa Mon Sep 17 00:00:00 2001 From: Vesa Meskanen Date: Thu, 17 Mar 2016 10:59:20 +0200 Subject: [PATCH] Unit test for configured flip street/number countries --- .../unit/middleware/localNamingConventions.js | 43 ++++++++++++++++++- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/test/unit/middleware/localNamingConventions.js b/test/unit/middleware/localNamingConventions.js index d22642db..c544abe7 100644 --- a/test/unit/middleware/localNamingConventions.js +++ b/test/unit/middleware/localNamingConventions.js @@ -1,4 +1,19 @@ -var localNamingConventions = require('../../../middleware/localNamingConventions'); + +var proxyquire = require('proxyquire'); + +var customConfig = { + generate: function generate() { + return { + api : { + localization : { // expand the set of flipped countries + flipNumberAndStreetCountries : ['NLD'] // Netherlands + } + } + }; + } +}; + +var localNamingConventions = proxyquire('../../../middleware/localNamingConventions', { 'pelias-config': customConfig }); module.exports.tests = {}; @@ -42,8 +57,28 @@ module.exports.tests.flipNumberAndStreet = function(test, common) { } }; + var nlAddress = { + '_id': 'test3', + '_type': 'test', + 'name': { 'default': '117 Keizersgracht' }, + 'center_point': { 'lon': 4.887545, 'lat': 52.376795 }, + 'address_parts': { + 'zip': '1015', + 'number': '117', + 'street': 'Keizersgracht' + }, + 'parent': { + 'region': ['Amsterdam'], + 'locality': ['Amsterdam'], + 'country_a': ['NLD'], + 'county': ['Noord-Holland'], + 'country': ['Netherlands'], + 'neighbourhood': ['Grachtengordel-West'] + } + }; + var req = {}, - res = { data: [ ukAddress, deAddress ] }, + res = { data: [ ukAddress, deAddress, nlAddress ] }, middleware = localNamingConventions(); test('flipNumberAndStreet', function(t) { @@ -57,6 +92,10 @@ module.exports.tests.flipNumberAndStreet = function(test, common) { // eg. '101 Grolmanstraße' -> 'Grolmanstraße 101' t.equal( res.data[1].name.default, 'Grolmanstraße 23', 'flipped name' ); + // NLD address should have the housenumber and street name flipped, too + // this definition comes from pelias configuration + t.equal( res.data[2].name.default, 'Keizersgracht 117', 'flipped name' ); + t.end(); }); });