@@ -73,4 +73,64 @@ describe('groupByFilter', function() {
7373
7474 } ) ;
7575
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+ ] ;
88+
89+ expect ( filter ( players , 'team' , 'a' ) ) . toEqual ( {
90+ a : [ players [ 5 ] , players [ 6 ] ] ,
91+ alpha : [ players [ 0 ] ] ,
92+ beta : [ players [ 1 ] , players [ 3 ] ] ,
93+ gamma : [ players [ 2 ] , players [ 4 ] ]
94+ } ) ;
95+
96+ } ) ;
97+
98+ it ( 'should replace null when asked, support nested properties to' , function ( ) {
99+ var orders = [
100+ { id :10 , customer : { name : 'foo' , id : 1 } } ,
101+ { id :11 , customer : { name : 'bar' , id : 2 } } ,
102+ { id :12 , customer : { name : 'foo' , id : 1 } } ,
103+ { id :13 , customer : { name : 'bar' , id : 2 } } ,
104+ { id :14 , customer : { name : 'bar' , id : 3 } } ,
105+ { id :15 , customer : { name : null } } ,
106+ { id :16 , customer : { } } ,
107+ 2 , null , true
108+ ] ;
109+
110+ expect ( filter ( orders , 'customer.name' , 0 ) ) . toEqual ( {
111+ foo : [ orders [ 0 ] , orders [ 2 ] ] ,
112+ bar : [ orders [ 1 ] , orders [ 3 ] , orders [ 4 ] ] ,
113+ 0 : [ orders [ 5 ] , orders [ 6 ] , 2 , null , true ]
114+ } ) ;
115+
116+ } ) ;
117+
118+
119+ it ( 'should replace null when asked, get object as collection, property(nested to) as identifier and ' +
120+ 'returns the composed aggregate object.' , function ( ) {
121+ var dataObject = {
122+ 0 : { id : 1 , data : { } } ,
123+ 1 : { id : 1 , data : { } } ,
124+ 2 : { id : 2 , data : { } } ,
125+ 3 : { id : 2 , data : { } } ,
126+ 4 : { id : null , data : { } }
127+ } ;
128+
129+ expect ( filter ( dataObject , 'id' , 0 ) ) . toEqual ( {
130+ 0 : [ dataObject [ 4 ] ] ,
131+ 1 : [ dataObject [ 0 ] , dataObject [ 1 ] ] ,
132+ 2 : [ dataObject [ 2 ] , dataObject [ 3 ] ]
133+ } ) ;
134+
135+ } ) ;
76136} ) ;
0 commit comments