From 6aa997dc69904b35a98a162db011df8054cadbdf Mon Sep 17 00:00:00 2001 From: Peter Johnson Date: Fri, 11 Feb 2022 20:22:45 +0100 Subject: [PATCH] feat(geojson): display unit number in geojson properties (#1603) --- helper/geojsonify_place_details.js | 1 + middleware/renamePlacenames.js | 1 + test/unit/helper/geojsonify_place_details.js | 7 +++++++ 3 files changed, 9 insertions(+) diff --git a/helper/geojsonify_place_details.js b/helper/geojsonify_place_details.js index 776fde7ca..e5f9b9c75 100644 --- a/helper/geojsonify_place_details.js +++ b/helper/geojsonify_place_details.js @@ -5,6 +5,7 @@ const field = require('./fieldValue'); // If a property is identified as a single string, assume it should be presented as a string in response // If something other than string is desired, use the following structure: { name: 'category', type: 'array' } const DETAILS_PROPS = [ + { name: 'unit', type: 'string' }, { name: 'housenumber', type: 'string' }, { name: 'street', type: 'string' }, { name: 'postalcode', type: 'string' }, diff --git a/middleware/renamePlacenames.js b/middleware/renamePlacenames.js index aaa4cb0af..281988e0d 100644 --- a/middleware/renamePlacenames.js +++ b/middleware/renamePlacenames.js @@ -3,6 +3,7 @@ const _ = require('lodash'); const PARENT_PROPS = require('../helper/placeTypes'); const ADDRESS_PROPS = [ + { name: 'unit', newName: 'unit' }, { name: 'number', newName: 'housenumber' }, { name: 'zip', newName: 'postalcode', transform: (value) => { return [value]; } }, { name: 'street', newName: 'street' } diff --git a/test/unit/helper/geojsonify_place_details.js b/test/unit/helper/geojsonify_place_details.js index c06b2a17f..0ea8f596e 100644 --- a/test/unit/helper/geojsonify_place_details.js +++ b/test/unit/helper/geojsonify_place_details.js @@ -5,6 +5,7 @@ module.exports.tests = {}; module.exports.tests.geojsonify_place_details = (test, common) => { test('plain old string values should be copied verbatim, replacing old values', t => { const source = { + unit: 'unit value', housenumber: 'housenumber value', street: 'street value', postalcode: 'postalcode value', @@ -53,6 +54,7 @@ module.exports.tests.geojsonify_place_details = (test, common) => { }; const expected = { + unit: 'unit value', housenumber: 'housenumber value', street: 'street value', postalcode: 'postalcode value', @@ -110,6 +112,7 @@ module.exports.tests.geojsonify_place_details = (test, common) => { test('\'empty\' string-type values should be output as \'\'', t => { [ [], {}, '', true, null, undefined ].forEach(empty_value => { const source = { + unit: empty_value, housenumber: empty_value, street: empty_value, postalcode: empty_value, @@ -170,6 +173,7 @@ module.exports.tests.geojsonify_place_details = (test, common) => { test('source arrays should be copy first value', t => { const source = { + unit: ['unit value 1', 'unit value 2'], housenumber: ['housenumber value 1', 'housenumber value 2'], street: ['street value 1', 'street value 2'], postalcode: ['postalcode value 1', 'postalcode value 2'], @@ -218,6 +222,7 @@ module.exports.tests.geojsonify_place_details = (test, common) => { }; const expected = { + unit: 'unit value 1', housenumber: 'housenumber value 1', street: 'street value 1', postalcode: 'postalcode value 1', @@ -275,6 +280,7 @@ module.exports.tests.geojsonify_place_details = (test, common) => { test('non-empty objects should be converted to strings', t => { // THIS TEST SHOWS THAT THE CODE DOES NOT DO WHAT IT EXPECTED const source = { + unit: { unit: 'unit value'}, housenumber: { housenumber: 'housenumber value'}, street: { street: 'street value'}, postalcode: { postalcode: 'postalcode value'}, @@ -323,6 +329,7 @@ module.exports.tests.geojsonify_place_details = (test, common) => { }; const expected = { + unit: '[object Object]', housenumber: '[object Object]', street: '[object Object]', postalcode: '[object Object]',