@@ -2364,9 +2364,7 @@ describe('ParseQuery', () => {
2364
2364
find ( ) { } ,
2365
2365
aggregate ( className , params , options ) {
2366
2366
expect ( className ) . toBe ( 'Item' ) ;
2367
- expect ( params ) . toEqual ( {
2368
- pipeline : [ { group : { objectId : '$name' } } ]
2369
- } ) ;
2367
+ expect ( params . pipeline ) . toEqual ( [ { group : { objectId : '$name' } } ] ) ;
2370
2368
expect ( options . useMasterKey ) . toEqual ( true ) ;
2371
2369
expect ( options . requestTask ) . toBeDefined ( ) ;
2372
2370
return Promise . resolve ( {
@@ -2390,9 +2388,7 @@ describe('ParseQuery', () => {
2390
2388
find ( ) { } ,
2391
2389
aggregate ( className , params , options ) {
2392
2390
expect ( className ) . toBe ( 'Item' ) ;
2393
- expect ( params ) . toEqual ( {
2394
- pipeline : { group : { objectId : '$name' } }
2395
- } ) ;
2391
+ expect ( params . pipeline ) . toEqual ( { group : { objectId : '$name' } } ) ;
2396
2392
expect ( options . useMasterKey ) . toEqual ( true ) ;
2397
2393
expect ( options . requestTask ) . toBeDefined ( ) ;
2398
2394
return Promise . resolve ( {
@@ -2441,9 +2437,7 @@ describe('ParseQuery', () => {
2441
2437
find ( ) { } ,
2442
2438
aggregate ( className , params , options ) {
2443
2439
expect ( className ) . toBe ( 'Item' ) ;
2444
- expect ( params ) . toEqual ( {
2445
- pipeline : [ { group : { objectId : '$name' } } ]
2446
- } ) ;
2440
+ expect ( params . pipeline ) . toEqual ( [ { group : { objectId : '$name' } } ] ) ;
2447
2441
expect ( options . useMasterKey ) . toEqual ( true ) ;
2448
2442
expect ( options . sessionToken ) . toEqual ( '1234' ) ;
2449
2443
return Promise . resolve ( {
@@ -2461,6 +2455,27 @@ describe('ParseQuery', () => {
2461
2455
} ) ;
2462
2456
} ) ;
2463
2457
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
+
2464
2479
it ( 'can pass options to an aggregate query with hint' , ( done ) => {
2465
2480
const pipeline = [
2466
2481
{ group : { objectId : '$name' } }
@@ -2469,10 +2484,8 @@ describe('ParseQuery', () => {
2469
2484
find ( ) { } ,
2470
2485
aggregate ( className , params , options ) {
2471
2486
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_' ) ;
2476
2489
expect ( options . useMasterKey ) . toEqual ( true ) ;
2477
2490
expect ( options . sessionToken ) . toEqual ( '1234' ) ;
2478
2491
return Promise . resolve ( {
0 commit comments