File tree Expand file tree Collapse file tree 3 files changed +29
-22
lines changed Expand file tree Collapse file tree 3 files changed +29
-22
lines changed Original file line number Diff line number Diff line change @@ -514,8 +514,8 @@ class ParseObject<T extends Attributes = Attributes> {
514
514
515
515
static _getRequestOptions ( options : RequestOptions & FullOptions & { json ?: boolean } = { } ) {
516
516
const requestOptions : RequestOptions & FullOptions & { json ?: boolean } = { } ;
517
- if ( ! options ) {
518
- return requestOptions ;
517
+ if ( Object . prototype . toString . call ( options ) !== '[object Object]' ) {
518
+ throw new Error ( 'request options must be of type Object' ) ;
519
519
}
520
520
const { hasOwn } = Object ;
521
521
if ( hasOwn ( options , 'useMasterKey' ) ) {
Original file line number Diff line number Diff line change @@ -356,4 +356,31 @@ describe('CloudController', () => {
356
356
} ) ;
357
357
expect ( options . useMasterKey ) . toBe ( false ) ;
358
358
} ) ;
359
+
360
+ it ( 'run passes with empty options' , ( ) => {
361
+ const values = [ undefined , { } ] ;
362
+
363
+ const mockRun = jest . fn ( ) ;
364
+ mockRun . mockReturnValue ( Promise . resolve ( { result : { } } ) ) ;
365
+
366
+ CoreManager . setCloudController ( {
367
+ run : mockRun ,
368
+ getJobsData : jest . fn ( ) ,
369
+ startJob : jest . fn ( ) ,
370
+ } ) ;
371
+
372
+ for ( const value of values ) {
373
+ mockRun . mockClear ( ) ;
374
+ expect ( ( ) => Cloud . run ( 'myfunction' , { } , value ) ) . not . toThrow ( ) ;
375
+ expect ( mockRun ) . toHaveBeenLastCalledWith ( 'myfunction' , { } , { } ) ;
376
+ }
377
+ } ) ;
378
+
379
+ it ( 'run throws with invalid options' , ( ) => {
380
+ const values = [ null , [ ] ] ;
381
+ for ( const value of values ) {
382
+ expect ( ( ) => Cloud . run ( 'myfunction' , { } , value ) ) . toThrow ( ) ;
383
+ }
384
+ } ) ;
385
+
359
386
} ) ;
Original file line number Diff line number Diff line change @@ -3543,23 +3543,3 @@ describe('ParseObject pin', () => {
3543
3543
CoreManager . set ( 'NODE_LOGGING' , false ) ;
3544
3544
} ) ;
3545
3545
} ) ;
3546
-
3547
- describe ( 'ParseObject._getRequestOptions' , ( ) => {
3548
- it ( 'returns empty object when options is null' , ( ) => {
3549
- const requestOptions = ParseObject . _getRequestOptions ( null ) ;
3550
-
3551
- expect ( requestOptions ) . toEqual ( { } ) ;
3552
- } ) ;
3553
-
3554
- it ( 'returns empty object when options is an empty string' , ( ) => {
3555
- const requestOptions = ParseObject . _getRequestOptions ( "" ) ;
3556
-
3557
- expect ( requestOptions ) . toEqual ( { } ) ;
3558
- } ) ;
3559
-
3560
- it ( 'returns empty object when options is undefined' , ( ) => {
3561
- const requestOptions = ParseObject . _getRequestOptions ( undefined ) ;
3562
-
3563
- expect ( requestOptions ) . toEqual ( { } ) ;
3564
- } ) ;
3565
- } ) ;
You can’t perform that action at this time.
0 commit comments