Browse Source

parent block properties should not be changed, only top level ones

pull/488/head
Diana Shkolnikov 9 years ago
parent
commit
10cd693e02
  1. 6
      middleware/normalizeParentIds.js
  2. 10
      test/unit/middleware/normalizeParentIds.js

6
middleware/normalizeParentIds.js

@ -39,10 +39,10 @@ function setup() {
*/ */
function normalizeParentIds(place) { function normalizeParentIds(place) {
if (place && place.parent) { if (place) {
placeTypes.forEach(function (placeType) { placeTypes.forEach(function (placeType) {
if (place.parent[placeType] && place.parent[placeType].length > 0 && place.parent[placeType][0]) { if (place[placeType] && place[placeType].length > 0 && place[placeType][0]) {
place.parent[placeType + '_id'] = [ makeNewId(placeType, place.parent[placeType + '_id']) ]; place[placeType + '_id'] = [ makeNewId(placeType, place[placeType + '_id']) ];
} }
}); });
} }

10
test/unit/middleware/normalizeParentIds.js

@ -8,6 +8,10 @@ module.exports.tests.interface = function(test, common) {
var input = { var input = {
data: [{ data: [{
'parent': { 'parent': {
'country': ['United States'], // these shouldn't change
'country_id': ['85633793'],
'country_a': ['USA']
},
'country': ['United States'], 'country': ['United States'],
'country_id': ['85633793'], 'country_id': ['85633793'],
'country_a': ['USA'], 'country_a': ['USA'],
@ -31,13 +35,16 @@ module.exports.tests.interface = function(test, common) {
'locality_a': [null], 'locality_a': [null],
'neighbourhood': [], 'neighbourhood': [],
'neighbourhood_id': [] 'neighbourhood_id': []
}
}] }]
}; };
var expected = { var expected = {
data: [{ data: [{
'parent': { 'parent': {
'country': ['United States'],
'country_id': ['85633793'],
'country_a': ['USA']
},
'country': ['United States'], 'country': ['United States'],
'country_id': ['whosonfirst:country:85633793'], 'country_id': ['whosonfirst:country:85633793'],
'country_a': ['USA'], 'country_a': ['USA'],
@ -61,7 +68,6 @@ module.exports.tests.interface = function(test, common) {
'locality_a': [null], 'locality_a': [null],
'neighbourhood': [], 'neighbourhood': [],
'neighbourhood_id': [] 'neighbourhood_id': []
}
}] }]
}; };

Loading…
Cancel
Save