Skip to content

Commit

Permalink
Merge branch 'matmar10-issues/29'
Browse files Browse the repository at this point in the history
  • Loading branch information
wankdanker committed Aug 10, 2017
2 parents b3204e4 + dd25177 commit 5c63266
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1661,3 +1661,60 @@ test('original various tests', function (t) {

t.end();
});

test('map array inside array to property', function (t) {

var obj = {
"orders": [{
"foodie": {
"first_name": "Foodie2",
"last_name": "Foodie2"
},
"sort_code": "A02"
}],
"transfers": [{
"type": "GIVE",
"target_route": {
"_id": "58e4a15607689eafed8e2841",
"driver": "58e4a15607689eafed8e2831"
},
"orders": ["58e4a15807689eafed8e2d0b"]
}]
};

var expect = {
"orders": [{
"foodie": {
"first_name": "Foodie2",
"last_name": "Foodie2"
},
"sort_code": "A02"
}],
"transfers": [{
"type": "GIVE",
"target_route": {
"_id": "58e4a15607689eafed8e2841",
"driver": "58e4a15607689eafed8e2831"
},
"orders": ["58e4a15807689eafed8e2d0b"]
}]
};

// would expect this to just assign the array as a property
var map = {
'orders[]._id': 'orders[]._id',
'orders[].sort_code': 'orders[].sort_code',
'orders[].foodie._id': 'orders[].foodie._id',
'orders[].foodie.first_name': 'orders[].foodie.first_name',
'orders[].foodie.last_name': 'orders[].foodie.last_name',
'transfers[].type': 'transfers[].type',
'transfers[].orders[]': 'transfers[].orders',
'transfers[].target_route._id': 'transfers[].target_route._id',
'transfers[].target_route.driver': 'transfers[].target_route.driver'
};

var result = om(obj, map);

t.deepEqual(result, expect);
t.end();
});

0 comments on commit 5c63266

Please sign in to comment.