@@ -21,10 +21,38 @@ describe('Resolver helper `projection` ->', () => {
2121 projectionHelper ( resolveParams ) ;
2222 expect ( spyFn ) . to . have . not . been . called ( ) ;
2323 } ) ;
24+
2425 it ( 'should call query.select if projection is provided' , ( ) => {
2526 resolveParams . projection = { name : 1 , age : 1 } ;
2627 projectionHelper ( resolveParams ) ;
2728 expect ( spyFn ) . to . have . been . called . with ( { name : true , age : true } ) ;
2829 } ) ;
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+ } ) ;
2957 } ) ;
3058} ) ;
0 commit comments