@@ -2364,9 +2364,7 @@ describe('ParseQuery', () => {
23642364 find ( ) { } ,
23652365 aggregate ( className , params , options ) {
23662366 expect ( className ) . toBe ( 'Item' ) ;
2367- expect ( params ) . toEqual ( {
2368- pipeline : [ { group : { objectId : '$name' } } ]
2369- } ) ;
2367+ expect ( params . pipeline ) . toEqual ( [ { group : { objectId : '$name' } } ] ) ;
23702368 expect ( options . useMasterKey ) . toEqual ( true ) ;
23712369 expect ( options . requestTask ) . toBeDefined ( ) ;
23722370 return Promise . resolve ( {
@@ -2390,9 +2388,7 @@ describe('ParseQuery', () => {
23902388 find ( ) { } ,
23912389 aggregate ( className , params , options ) {
23922390 expect ( className ) . toBe ( 'Item' ) ;
2393- expect ( params ) . toEqual ( {
2394- pipeline : { group : { objectId : '$name' } }
2395- } ) ;
2391+ expect ( params . pipeline ) . toEqual ( { group : { objectId : '$name' } } ) ;
23962392 expect ( options . useMasterKey ) . toEqual ( true ) ;
23972393 expect ( options . requestTask ) . toBeDefined ( ) ;
23982394 return Promise . resolve ( {
@@ -2441,9 +2437,7 @@ describe('ParseQuery', () => {
24412437 find ( ) { } ,
24422438 aggregate ( className , params , options ) {
24432439 expect ( className ) . toBe ( 'Item' ) ;
2444- expect ( params ) . toEqual ( {
2445- pipeline : [ { group : { objectId : '$name' } } ]
2446- } ) ;
2440+ expect ( params . pipeline ) . toEqual ( [ { group : { objectId : '$name' } } ] ) ;
24472441 expect ( options . useMasterKey ) . toEqual ( true ) ;
24482442 expect ( options . sessionToken ) . toEqual ( '1234' ) ;
24492443 return Promise . resolve ( {
@@ -2461,6 +2455,27 @@ describe('ParseQuery', () => {
24612455 } ) ;
24622456 } ) ;
24632457
2458+ it ( 'can issue an aggregate query with read preference' , async ( ) => {
2459+ // Override controller
2460+ CoreManager . setQueryController ( {
2461+ find ( ) { } ,
2462+ aggregate ( className , params , options ) {
2463+ expect ( className ) . toBe ( 'Item' ) ;
2464+ expect ( params . readPreference ) . toEqual ( 'SECONDARY' ) ;
2465+ expect ( options . useMasterKey ) . toEqual ( true ) ;
2466+ return Promise . resolve ( {
2467+ results : [ ]
2468+ } ) ;
2469+ }
2470+ } ) ;
2471+ // Query
2472+ const q = new ParseQuery ( 'Item' ) ;
2473+ q . readPreference ( 'SECONDARY' ) ;
2474+ const results = await q . aggregate ( [ ] , { sessionToken : '1234' } ) ;
2475+ // Validate
2476+ expect ( results ) . toEqual ( [ ] ) ;
2477+ } ) ;
2478+
24642479 it ( 'can pass options to an aggregate query with hint' , ( done ) => {
24652480 const pipeline = [
24662481 { group : { objectId : '$name' } }
@@ -2469,10 +2484,8 @@ describe('ParseQuery', () => {
24692484 find ( ) { } ,
24702485 aggregate ( className , params , options ) {
24712486 expect ( className ) . toBe ( 'Item' ) ;
2472- expect ( params ) . toEqual ( {
2473- pipeline : [ { group : { objectId : '$name' } } ] ,
2474- hint : '_id_' ,
2475- } ) ;
2487+ expect ( params . pipeline ) . toEqual ( [ { group : { objectId : '$name' } } ] ) ;
2488+ expect ( params . hint ) . toEqual ( '_id_' ) ;
24762489 expect ( options . useMasterKey ) . toEqual ( true ) ;
24772490 expect ( options . sessionToken ) . toEqual ( '1234' ) ;
24782491 return Promise . resolve ( {
0 commit comments