From 10cd693e0213f96d1b7998aa10e82961351315ed Mon Sep 17 00:00:00 2001 From: Diana Shkolnikov Date: Thu, 7 Apr 2016 14:49:22 -0400 Subject: [PATCH] parent block properties should not be changed, only top level ones --- middleware/normalizeParentIds.js | 6 +- test/unit/middleware/normalizeParentIds.js | 98 ++++++++++++---------- 2 files changed, 55 insertions(+), 49 deletions(-) diff --git a/middleware/normalizeParentIds.js b/middleware/normalizeParentIds.js index 2c9d3629..fe512b61 100644 --- a/middleware/normalizeParentIds.js +++ b/middleware/normalizeParentIds.js @@ -39,10 +39,10 @@ function setup() { */ function normalizeParentIds(place) { - if (place && place.parent) { + if (place) { placeTypes.forEach(function (placeType) { - if (place.parent[placeType] && place.parent[placeType].length > 0 && place.parent[placeType][0]) { - place.parent[placeType + '_id'] = [ makeNewId(placeType, place.parent[placeType + '_id']) ]; + if (place[placeType] && place[placeType].length > 0 && place[placeType][0]) { + place[placeType + '_id'] = [ makeNewId(placeType, place[placeType + '_id']) ]; } }); } diff --git a/test/unit/middleware/normalizeParentIds.js b/test/unit/middleware/normalizeParentIds.js index 9ad603f8..95dc1387 100644 --- a/test/unit/middleware/normalizeParentIds.js +++ b/test/unit/middleware/normalizeParentIds.js @@ -8,30 +8,33 @@ module.exports.tests.interface = function(test, common) { var input = { data: [{ 'parent': { - 'country': ['United States'], + 'country': ['United States'], // these shouldn't change 'country_id': ['85633793'], - 'country_a': ['USA'], - 'macroregion': ['MacroRegion Name'], - 'macroregion_id': ['foobar'], - 'macroregion_a': ['MacroRegion Abbreviation'], - 'region': ['New York'], - 'region_id': ['85688543'], - 'region_a': ['NY'], - 'macrocounty': ['MacroCounty Name'], - 'macrocounty_id': ['~~~~~'], - 'macrocounty_a': ['MacroCounty Abbreviation'], - 'county': ['Kings County'], - 'county_id': ['102082361'], - 'county_a': [null], - 'localadmin': ['Brooklyn'], - 'localadmin_id': ['404521211'], - 'localadmin_a': [null], - 'locality': ['Some Locality'], - 'locality_id': ['85977539'], - 'locality_a': [null], - 'neighbourhood': [], - 'neighbourhood_id': [] - } + 'country_a': ['USA'] + }, + 'country': ['United States'], + 'country_id': ['85633793'], + 'country_a': ['USA'], + 'macroregion': ['MacroRegion Name'], + 'macroregion_id': ['foobar'], + 'macroregion_a': ['MacroRegion Abbreviation'], + 'region': ['New York'], + 'region_id': ['85688543'], + 'region_a': ['NY'], + 'macrocounty': ['MacroCounty Name'], + 'macrocounty_id': ['~~~~~'], + 'macrocounty_a': ['MacroCounty Abbreviation'], + 'county': ['Kings County'], + 'county_id': ['102082361'], + 'county_a': [null], + 'localadmin': ['Brooklyn'], + 'localadmin_id': ['404521211'], + 'localadmin_a': [null], + 'locality': ['Some Locality'], + 'locality_id': ['85977539'], + 'locality_a': [null], + 'neighbourhood': [], + 'neighbourhood_id': [] }] }; @@ -39,29 +42,32 @@ module.exports.tests.interface = function(test, common) { data: [{ 'parent': { 'country': ['United States'], - 'country_id': ['whosonfirst:country:85633793'], - 'country_a': ['USA'], - 'macroregion': ['MacroRegion Name'], - 'macroregion_id': ['whosonfirst:macroregion:foobar'], - 'macroregion_a': ['MacroRegion Abbreviation'], - 'region': ['New York'], - 'region_id': ['whosonfirst:region:85688543'], - 'region_a': ['NY'], - 'macrocounty': ['MacroCounty Name'], - 'macrocounty_id': ['whosonfirst:macrocounty:~~~~~'], - 'macrocounty_a': ['MacroCounty Abbreviation'], - 'county': ['Kings County'], - 'county_id': ['whosonfirst:county:102082361'], - 'county_a': [null], - 'localadmin': ['Brooklyn'], - 'localadmin_id': ['whosonfirst:localadmin:404521211'], - 'localadmin_a': [null], - 'locality': ['Some Locality'], - 'locality_id': ['whosonfirst:locality:85977539'], - 'locality_a': [null], - 'neighbourhood': [], - 'neighbourhood_id': [] - } + 'country_id': ['85633793'], + 'country_a': ['USA'] + }, + 'country': ['United States'], + 'country_id': ['whosonfirst:country:85633793'], + 'country_a': ['USA'], + 'macroregion': ['MacroRegion Name'], + 'macroregion_id': ['whosonfirst:macroregion:foobar'], + 'macroregion_a': ['MacroRegion Abbreviation'], + 'region': ['New York'], + 'region_id': ['whosonfirst:region:85688543'], + 'region_a': ['NY'], + 'macrocounty': ['MacroCounty Name'], + 'macrocounty_id': ['whosonfirst:macrocounty:~~~~~'], + 'macrocounty_a': ['MacroCounty Abbreviation'], + 'county': ['Kings County'], + 'county_id': ['whosonfirst:county:102082361'], + 'county_a': [null], + 'localadmin': ['Brooklyn'], + 'localadmin_id': ['whosonfirst:localadmin:404521211'], + 'localadmin_a': [null], + 'locality': ['Some Locality'], + 'locality_id': ['whosonfirst:locality:85977539'], + 'locality_a': [null], + 'neighbourhood': [], + 'neighbourhood_id': [] }] };