@@ -15,7 +15,7 @@ describe('Resolver helper `projection` ->', () => {
1515 } ) ;
1616
1717 it ( 'should not call query.select if projection is empty' , ( ) => {
18- projectionHelper ( resolveParams , false ) ;
18+ projectionHelper ( resolveParams ) ;
1919 expect ( spyFn ) . not . toBeCalled ( ) ;
2020 } ) ;
2121
@@ -31,29 +31,35 @@ describe('Resolver helper `projection` ->', () => {
3131 expect ( spyFn ) . toBeCalledWith ( { 'n.first' : true , 'n.last' : true } ) ;
3232 } ) ;
3333
34+ it ( 'should make projection fields flat with nested aliases' , ( ) => {
35+ resolveParams . projection = { name : { first : 1 , last : 1 } } ;
36+ projectionHelper ( resolveParams , { name : { __selfAlias : 'n' , first : 'f' , last : 'l' } } ) ;
37+ expect ( spyFn ) . toBeCalledWith ( { 'n.f' : true , 'n.l' : true } ) ;
38+ } ) ;
39+
3440 it ( 'should not call query.select if projection has * key' , ( ) => {
3541 resolveParams . projection = { '*' : true } ;
36- projectionHelper ( resolveParams , false ) ;
42+ projectionHelper ( resolveParams ) ;
3743 expect ( spyFn ) . not . toBeCalled ( ) ;
3844 } ) ;
3945
4046 describe ( 'projection operators' , ( ) => {
4147 // see more details here https://docs.mongodb.com/v3.2/reference/operator/projection/meta/
42- it ( 'should pass $meta unflatted ' , ( ) => {
48+ it ( 'should pass $meta non-flatten ' , ( ) => {
4349 resolveParams . projection = { score : { $meta : 'textScore' } } ;
44- projectionHelper ( resolveParams , false ) ;
50+ projectionHelper ( resolveParams ) ;
4551 expect ( spyFn ) . toBeCalledWith ( { score : { $meta : 'textScore' } } ) ;
4652 } ) ;
4753
48- it ( 'should pass $slice unflatted ' , ( ) => {
54+ it ( 'should pass $slice non-flatten ' , ( ) => {
4955 resolveParams . projection = { comments : { $slice : 5 } } ;
50- projectionHelper ( resolveParams , false ) ;
56+ projectionHelper ( resolveParams ) ;
5157 expect ( spyFn ) . toBeCalledWith ( { comments : { $slice : 5 } } ) ;
5258 } ) ;
5359
54- it ( 'should pass $elemMatch unflatted ' , ( ) => {
60+ it ( 'should pass $elemMatch non-flatten ' , ( ) => {
5561 resolveParams . projection = { students : { $elemMatch : { school : 102 } } } ;
56- projectionHelper ( resolveParams , false ) ;
62+ projectionHelper ( resolveParams ) ;
5763 expect ( spyFn ) . toBeCalledWith ( { students : { $elemMatch : { school : 102 } } } ) ;
5864 } ) ;
5965 } ) ;
0 commit comments