File tree 2 files changed +34
-2
lines changed
2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -587,6 +587,35 @@ describe('miscellaneous', function() {
587
587
done ( ) ;
588
588
} ) ;
589
589
} ) ;
590
+
591
+ it ( 'test cloud function query parameters' , ( done ) => {
592
+ Parse . Cloud . define ( 'echoParams' , ( req , res ) => {
593
+ res . success ( req . params ) ;
594
+ } ) ;
595
+ var headers = {
596
+ 'Content-Type' : 'application/json' ,
597
+ 'X-Parse-Application-Id' : 'test' ,
598
+ 'X-Parse-Javascript-Key' : 'test'
599
+ } ;
600
+ request . post ( {
601
+ headers : headers ,
602
+ url : 'http://localhost:8378/1/functions/echoParams' , //?option=1&other=2
603
+ qs : {
604
+ option : 1 ,
605
+ other : 2
606
+ } ,
607
+ body : '{"foo":"bar", "other": 1}'
608
+ } , ( error , response , body ) => {
609
+ expect ( error ) . toBe ( null ) ;
610
+ var res = JSON . parse ( body ) . result ;
611
+ expect ( res . option ) . toEqual ( '1' ) ;
612
+ // Make sure query string params override body params
613
+ expect ( res . other ) . toEqual ( '2' ) ;
614
+ expect ( res . foo ) . toEqual ( "bar" ) ;
615
+ delete Parse . Cloud . Functions [ 'echoParams' ] ;
616
+ done ( ) ;
617
+ } ) ;
618
+ } ) ;
590
619
591
620
it ( 'test cloud function parameter validation success' , ( done ) => {
592
621
// Register a function with validation
Original file line number Diff line number Diff line change @@ -9,8 +9,11 @@ var router = new PromiseRouter();
9
9
10
10
function handleCloudFunction ( req ) {
11
11
if ( Parse . Cloud . Functions [ req . params . functionName ] ) {
12
+
13
+ const params = Object . assign ( { } , req . body , req . query ) ;
14
+
12
15
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 ) ;
14
17
if ( ! result ) {
15
18
throw new Parse . Error ( Parse . Error . SCRIPT_FAILED , 'Validation failed.' ) ;
16
19
}
@@ -19,7 +22,7 @@ function handleCloudFunction(req) {
19
22
return new Promise ( function ( resolve , reject ) {
20
23
var response = createResponseObject ( resolve , reject ) ;
21
24
var request = {
22
- params : req . body || { } ,
25
+ params : params ,
23
26
master : req . auth && req . auth . isMaster ,
24
27
user : req . auth && req . auth . user ,
25
28
installationId : req . info . installationId
You can’t perform that action at this time.
0 commit comments