Skip to content

Commit

Permalink
removed wankdanker#49 fix - breaks backwards compatibility. Needs dis…
Browse files Browse the repository at this point in the history
…cussion
  • Loading branch information
Scott Switzer committed Oct 12, 2019
1 parent d57b328 commit 0766113
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 40 deletions.
4 changes: 2 additions & 2 deletions src/object-mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ function update_arr(dest, key, data, keys, context)
if (key.add) {
if (data !== null && typeof data !== 'undefined') {
dest = dest || []
//dest.push(data)
dest = dest.concat(data)
dest.push(data)
// dest = dest.concat(data)
}
return dest
}
Expand Down
132 changes: 94 additions & 38 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1624,16 +1624,11 @@ test('mapping - map and append full array to existing mapped array', function (t
'thingOther' : 'thing2[]+',
};

var expect = {
'thing2' : [
{a: 'a1', b: 'b1'}
, {a: 'a2', b: 'b2'}
, {a: 'a3', b: 'b3'}
, {a: 'a4', b: 'b4'}
, {a: 'a5', b: 'b5'}
, {a: 'a6', b: 'b6'}
]
};
var expect = {thing2:
[
[ { a: 'a1', b: 'b1' }, { a: 'a2', b: 'b2' }, { a: 'a3', b: 'b3' } ],
[ { a: 'a4', b: 'b4' }, { a: 'a5', b: 'b5' }, { a: 'a6', b: 'b6' } ]
]}

var result = om(obj, map);

Expand Down Expand Up @@ -2173,34 +2168,34 @@ test('Make sure no objects are created without data #48', function (t) {
t.end();
});

test('1 array mapping wraps destination in an unwanted array #49', function (t) {
const src = {
foo: [{ bar: 4 }, { bar: 33 }],
bifoo: [{ bar: 77 }, { bar: 97 }]
};
const mapper = {
"foo[].bar": "[]+",
"bifoo[].bar": "[]+"
}
var expect = [4, 33, 77, 97];
var result = om(src, mapper);
t.deepEqual(result, expect);
t.end();
});
test('2 array mapping wraps destination in an unwanted array #49', function (t) {
const src = {
foo: [{ bar: 4 }, { bar: 33 }],
bifoo: [{ bar: 77 }, { bar: 97 }]
};
const mapper2 = {
"foo[].bar": "num[]+",
"bifoo[].bar": "num[]+"
}
var expect = {num: [4, 33, 77, 97] };
var result = om(src, mapper2);
t.deepEqual(result, expect);
t.end();
});
// test('1 array mapping wraps destination in an unwanted array #49', function (t) {
// const src = {
// foo: [{ bar: 4 }, { bar: 33 }],
// bifoo: [{ bar: 77 }, { bar: 97 }]
// };
// const mapper = {
// "foo[].bar": "[]+",
// "bifoo[].bar": "[]+"
// }
// var expect = [4, 33, 77, 97];
// var result = om(src, mapper);
// t.deepEqual(result, expect);
// t.end();
// });
// test('2 array mapping wraps destination in an unwanted array #49', function (t) {
// const src = {
// foo: [{ bar: 4 }, { bar: 33 }],
// bifoo: [{ bar: 77 }, { bar: 97 }]
// };
// const mapper2 = {
// "foo[].bar": "num[]+",
// "bifoo[].bar": "num[]+"
// }
// var expect = {num: [4, 33, 77, 97] };
// var result = om(src, mapper2);
// t.deepEqual(result, expect);
// t.end();
// });

// test('Including parent items in arrays #50', function (t) {
// const src = {
Expand Down Expand Up @@ -2234,3 +2229,64 @@ test('2 array mapping wraps destination in an unwanted array #49', function (t)
// t.deepEqual(result, expect);
// t.end();
// });

// test('2 array mapping wraps destination in an unwanted array #49', function (t) {
// const src = {
// "firstName": "S",
// "lastName": "J",
// "Alias": [{
// "firstName": "S111",
// "lastName": "J111"
// }, {
// "firstName": "S111222",
// "lastName": "J1222211"
// }],
// "address": [
// {
// "streetName": "",
// "city": "S2"
// },
// {
// "streetName": "karve",
// "city": "pune"
// }
// ]
// };
// const map = {
// "firstName": "Name[].FirstName",
// "lastName": "Name[].LastName",
// "Alias[].firstName": "Name[].FirstName",
// "Alias[].lastName": "Name[].LastName",
// "address[].streetName": "Address[].StreetName",
// "address[].city": "Address[].City"
// }
// var expect = {
// "Name": [
// {
// "FirstName": "S",
// "LastName": "J"
// },
// {
// "FirstName": "S111",
// "LastName": "J111"
// },
// {
// "FirstName": "S111222",
// "LastName": "J1222211"
// }
// ],
// "Address": [
// {
// "StreetName": "",
// "City": "S2"
// },
// {
// "StreetName": "karve",
// "City": "pune"
// }
// ]
// };
// var result = om(src, map);
// t.deepEqual(result, expect);
// t.end();
// });

0 comments on commit 0766113

Please sign in to comment.