@@ -73,4 +73,66 @@ describe('groupByFilter', function() {
73
73
74
74
} ) ;
75
75
76
+ it ( 'should replace null when asked, get array as collection, property(nested to) as identifier and ' +
77
+ 'returns the composed aggregate object.' , function ( ) {
78
+
79
+ var players = [
80
+ { name : 'Gene' , team : 'alpha' } ,
81
+ { name : 'George' , team : 'beta' } ,
82
+ { name : 'Steve' , team : 'gamma' } ,
83
+ { name : 'Paula' , team : 'beta' } ,
84
+ { name : 'Scruath' , team : 'gamma' } ,
85
+ { name : 'Alex' , team : null } ,
86
+ { name : 'Rob' } ,
87
+ { name : 'Sven' , team : false }
88
+ ] ;
89
+
90
+ expect ( filter ( players , 'team' , 'a' ) ) . toEqual ( {
91
+ a : [ players [ 5 ] , players [ 6 ] ] ,
92
+ alpha : [ players [ 0 ] ] ,
93
+ beta : [ players [ 1 ] , players [ 3 ] ] ,
94
+ gamma : [ players [ 2 ] , players [ 4 ] ] ,
95
+ 'false' : [ players [ 7 ] ]
96
+ } ) ;
97
+
98
+ } ) ;
99
+
100
+ it ( 'should replace null when asked, support nested properties to' , function ( ) {
101
+ var orders = [
102
+ { id :10 , customer : { name : 'foo' , id : 1 } } ,
103
+ { id :11 , customer : { name : 'bar' , id : 2 } } ,
104
+ { id :12 , customer : { name : 'foo' , id : 1 } } ,
105
+ { id :13 , customer : { name : 'bar' , id : 2 } } ,
106
+ { id :14 , customer : { name : 'bar' , id : 3 } } ,
107
+ { id :15 , customer : { name : null } } ,
108
+ { id :16 , customer : { } } ,
109
+ 2 , null , true
110
+ ] ;
111
+
112
+ expect ( filter ( orders , 'customer.name' , 0 ) ) . toEqual ( {
113
+ foo : [ orders [ 0 ] , orders [ 2 ] ] ,
114
+ bar : [ orders [ 1 ] , orders [ 3 ] , orders [ 4 ] ] ,
115
+ 0 : [ orders [ 5 ] , orders [ 6 ] , 2 , null , true ]
116
+ } ) ;
117
+
118
+ } ) ;
119
+
120
+
121
+ it ( 'should replace null when asked, get object as collection, property(nested to) as identifier and ' +
122
+ 'returns the composed aggregate object.' , function ( ) {
123
+ var dataObject = {
124
+ 0 : { id : 1 , data : { } } ,
125
+ 1 : { id : 1 , data : { } } ,
126
+ 2 : { id : 2 , data : { } } ,
127
+ 3 : { id : 2 , data : { } } ,
128
+ 4 : { id : null , data : { } }
129
+ } ;
130
+
131
+ expect ( filter ( dataObject , 'id' , 0 ) ) . toEqual ( {
132
+ 0 : [ dataObject [ 4 ] ] ,
133
+ 1 : [ dataObject [ 0 ] , dataObject [ 1 ] ] ,
134
+ 2 : [ dataObject [ 2 ] , dataObject [ 3 ] ]
135
+ } ) ;
136
+
137
+ } ) ;
76
138
} ) ;
0 commit comments