File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -571,6 +571,35 @@ describe('miscellaneous', function() {
571571 done ( ) ;
572572 } ) ;
573573 } ) ;
574+
575+ it ( 'test cloud function query parameters' , ( done ) => {
576+ Parse . Cloud . define ( 'echoParams' , ( req , res ) => {
577+ res . success ( req . params ) ;
578+ } ) ;
579+ var headers = {
580+ 'Content-Type' : 'application/json' ,
581+ 'X-Parse-Application-Id' : 'test' ,
582+ 'X-Parse-Javascript-Key' : 'test'
583+ } ;
584+ request . post ( {
585+ headers : headers ,
586+ url : 'http://localhost:8378/1/functions/echoParams' , //?option=1&other=2
587+ qs : {
588+ option : 1 ,
589+ other : 2
590+ } ,
591+ body : '{"foo":"bar", "other": 1}'
592+ } , ( error , response , body ) => {
593+ expect ( error ) . toBe ( null ) ;
594+ var res = JSON . parse ( body ) . result ;
595+ expect ( res . option ) . toEqual ( '1' ) ;
596+ // Make sure query string params override body params
597+ expect ( res . other ) . toEqual ( '2' ) ;
598+ expect ( res . foo ) . toEqual ( "bar" ) ;
599+ delete Parse . Cloud . Functions [ 'echoParams' ] ;
600+ done ( ) ;
601+ } ) ;
602+ } ) ;
574603
575604 it ( 'test cloud function parameter validation success' , ( done ) => {
576605 // Register a function with validation
Original file line number Diff line number Diff line change @@ -9,8 +9,11 @@ var router = new PromiseRouter();
99
1010function handleCloudFunction ( req ) {
1111 if ( Parse . Cloud . Functions [ req . params . functionName ] ) {
12+
13+ const params = Object . assign ( { } , req . body , req . query ) ;
14+
1215 if ( Parse . Cloud . Validators [ req . params . functionName ] ) {
13- var result = Parse . Cloud . Validators [ req . params . functionName ] ( req . body || { } ) ;
16+ var result = Parse . Cloud . Validators [ req . params . functionName ] ( params ) ;
1417 if ( ! result ) {
1518 throw new Parse . Error ( Parse . Error . SCRIPT_FAILED , 'Validation failed.' ) ;
1619 }
@@ -19,7 +22,7 @@ function handleCloudFunction(req) {
1922 return new Promise ( function ( resolve , reject ) {
2023 var response = createResponseObject ( resolve , reject ) ;
2124 var request = {
22- params : req . body || { } ,
25+ params : params ,
2326 master : req . auth && req . auth . isMaster ,
2427 user : req . auth && req . auth . user ,
2528 installationId : req . info . installationId
You can’t perform that action at this time.
0 commit comments