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() {
571
571
done ( ) ;
572
572
} ) ;
573
573
} ) ;
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
+ } ) ;
574
603
575
604
it ( 'test cloud function parameter validation success' , ( done ) => {
576
605
// 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