@@ -2851,6 +2851,141 @@ describe('ParseQuery', () => {
28512851 } ) ;
28522852 } ) ;
28532853
2854+ it ( 'can pass rawValues option to aggregate query' , async ( ) => {
2855+ const pipeline = [ { group : { objectId : '$name' } } ] ;
2856+ let capturedParams ;
2857+ let capturedOptions ;
2858+ CoreManager . setQueryController ( {
2859+ find ( ) { } ,
2860+ aggregate ( className , params , options ) {
2861+ expect ( className ) . toBe ( 'Item' ) ;
2862+ capturedParams = params ;
2863+ capturedOptions = options ;
2864+ return Promise . resolve ( { results : [ ] } ) ;
2865+ } ,
2866+ } ) ;
2867+
2868+ const q = new ParseQuery ( 'Item' ) ;
2869+ await q . aggregate ( pipeline , { rawValues : true } ) ;
2870+
2871+ expect ( capturedParams . rawValues ) . toBe ( true ) ;
2872+ expect ( 'rawValues' in capturedOptions ) . toBe ( false ) ;
2873+ expect ( capturedOptions . useMasterKey ) . toBe ( true ) ;
2874+ } ) ;
2875+
2876+ it ( 'can pass rawFieldNames option to aggregate query' , async ( ) => {
2877+ const pipeline = [ { group : { objectId : '$name' } } ] ;
2878+ let capturedParams ;
2879+ let capturedOptions ;
2880+ CoreManager . setQueryController ( {
2881+ find ( ) { } ,
2882+ aggregate ( className , params , options ) {
2883+ expect ( className ) . toBe ( 'Item' ) ;
2884+ capturedParams = params ;
2885+ capturedOptions = options ;
2886+ return Promise . resolve ( { results : [ ] } ) ;
2887+ } ,
2888+ } ) ;
2889+
2890+ const q = new ParseQuery ( 'Item' ) ;
2891+ await q . aggregate ( pipeline , { rawFieldNames : true } ) ;
2892+
2893+ expect ( capturedParams . rawFieldNames ) . toBe ( true ) ;
2894+ expect ( 'rawFieldNames' in capturedOptions ) . toBe ( false ) ;
2895+ expect ( capturedOptions . useMasterKey ) . toBe ( true ) ;
2896+ } ) ;
2897+
2898+ it ( 'aggregate defaults useMasterKey to true when no options provided' , async ( ) => {
2899+ const pipeline = [ { group : { objectId : '$name' } } ] ;
2900+ let capturedOptions ;
2901+ CoreManager . setQueryController ( {
2902+ find ( ) { } ,
2903+ aggregate ( _className , _params , options ) {
2904+ capturedOptions = options ;
2905+ return Promise . resolve ( { results : [ ] } ) ;
2906+ } ,
2907+ } ) ;
2908+
2909+ const q = new ParseQuery ( 'Item' ) ;
2910+ await q . aggregate ( pipeline ) ;
2911+
2912+ expect ( capturedOptions . useMasterKey ) . toBe ( true ) ;
2913+ } ) ;
2914+
2915+ it ( 'aggregate allows useMasterKey to be overridden via options' , async ( ) => {
2916+ const pipeline = [ { group : { objectId : '$name' } } ] ;
2917+ let capturedOptions ;
2918+ CoreManager . setQueryController ( {
2919+ find ( ) { } ,
2920+ aggregate ( _className , _params , options ) {
2921+ capturedOptions = options ;
2922+ return Promise . resolve ( { results : [ ] } ) ;
2923+ } ,
2924+ } ) ;
2925+
2926+ const q = new ParseQuery ( 'Item' ) ;
2927+ await q . aggregate ( pipeline , { useMasterKey : false } ) ;
2928+
2929+ expect ( capturedOptions . useMasterKey ) . toBe ( false ) ;
2930+ } ) ;
2931+
2932+ it ( 'aggregate does not leak raw* keys into params when unset' , async ( ) => {
2933+ const pipeline = [ { group : { objectId : '$name' } } ] ;
2934+ let capturedParams ;
2935+ CoreManager . setQueryController ( {
2936+ find ( ) { } ,
2937+ aggregate ( _className , params , _options ) {
2938+ capturedParams = params ;
2939+ return Promise . resolve ( { results : [ ] } ) ;
2940+ } ,
2941+ } ) ;
2942+
2943+ const q = new ParseQuery ( 'Item' ) ;
2944+ await q . aggregate ( pipeline , { useMasterKey : false } ) ;
2945+
2946+ expect ( 'rawValues' in capturedParams ) . toBe ( false ) ;
2947+ expect ( 'rawFieldNames' in capturedParams ) . toBe ( false ) ;
2948+ } ) ;
2949+
2950+ it ( 'aggregate forwards sessionToken via request options' , async ( ) => {
2951+ const pipeline = [ { group : { objectId : '$name' } } ] ;
2952+ let capturedOptions ;
2953+ CoreManager . setQueryController ( {
2954+ find ( ) { } ,
2955+ aggregate ( _className , _params , options ) {
2956+ capturedOptions = options ;
2957+ return Promise . resolve ( { results : [ ] } ) ;
2958+ } ,
2959+ } ) ;
2960+
2961+ const q = new ParseQuery ( 'Item' ) ;
2962+ await q . aggregate ( pipeline , { sessionToken : 'r:abc' , useMasterKey : false } ) ;
2963+
2964+ expect ( capturedOptions . sessionToken ) . toBe ( 'r:abc' ) ;
2965+ expect ( capturedOptions . useMasterKey ) . toBe ( false ) ;
2966+ } ) ;
2967+
2968+ it ( 'aggregate forwards raw* options when explicitly false' , async ( ) => {
2969+ const pipeline = [ { group : { objectId : '$name' } } ] ;
2970+ let capturedParams ;
2971+ CoreManager . setQueryController ( {
2972+ find ( ) { } ,
2973+ aggregate ( _className , params , _options ) {
2974+ capturedParams = params ;
2975+ return Promise . resolve ( { results : [ ] } ) ;
2976+ } ,
2977+ } ) ;
2978+
2979+ const q = new ParseQuery ( 'Item' ) ;
2980+ await q . aggregate ( pipeline , {
2981+ rawValues : false ,
2982+ rawFieldNames : false ,
2983+ } ) ;
2984+
2985+ expect ( capturedParams . rawValues ) . toBe ( false ) ;
2986+ expect ( capturedParams . rawFieldNames ) . toBe ( false ) ;
2987+ } ) ;
2988+
28542989 it ( 'can cancel query' , async ( ) => {
28552990 const mockRequestTask = {
28562991 abort : ( ) => { } ,
0 commit comments