@@ -21,10 +21,38 @@ describe('Resolver helper `projection` ->', () => {
21
21
projectionHelper ( resolveParams ) ;
22
22
expect ( spyFn ) . to . have . not . been . called ( ) ;
23
23
} ) ;
24
+
24
25
it ( 'should call query.select if projection is provided' , ( ) => {
25
26
resolveParams . projection = { name : 1 , age : 1 } ;
26
27
projectionHelper ( resolveParams ) ;
27
28
expect ( spyFn ) . to . have . been . called . with ( { name : true , age : true } ) ;
28
29
} ) ;
30
+
31
+ it ( 'should make projection fields flat' , ( ) => {
32
+ resolveParams . projection = { name : { first : 1 , last : 1 } } ;
33
+ projectionHelper ( resolveParams ) ;
34
+ expect ( spyFn ) . to . have . been . called . with ( { name : true } ) ;
35
+ } ) ;
36
+
37
+ describe ( 'projection operators' , ( ) => {
38
+ // see more details here https://docs.mongodb.com/v3.2/reference/operator/projection/meta/
39
+ it ( 'should pass $meta unflatted' , ( ) => {
40
+ resolveParams . projection = { score : { $meta : 'textScore' } } ;
41
+ projectionHelper ( resolveParams ) ;
42
+ expect ( spyFn ) . to . have . been . called . with ( { score : { $meta : 'textScore' } } ) ;
43
+ } ) ;
44
+
45
+ it ( 'should pass $slice unflatted' , ( ) => {
46
+ resolveParams . projection = { comments : { $slice : 5 } } ;
47
+ projectionHelper ( resolveParams ) ;
48
+ expect ( spyFn ) . to . have . been . called . with ( { comments : { $slice : 5 } } ) ;
49
+ } ) ;
50
+
51
+ it ( 'should pass $elemMatch unflatted' , ( ) => {
52
+ resolveParams . projection = { students : { $elemMatch : { school : 102 } } } ;
53
+ projectionHelper ( resolveParams ) ;
54
+ expect ( spyFn ) . to . have . been . called . with ( { students : { $elemMatch : { school : 102 } } } ) ;
55
+ } ) ;
56
+ } ) ;
29
57
} ) ;
30
58
} ) ;
0 commit comments