@@ -355,6 +355,117 @@ describe('cloud validator', () => {
355
355
} ) ;
356
356
} ) ;
357
357
358
+ it ( 'set params not-required options data' , done => {
359
+ Parse . Cloud . define (
360
+ 'hello' ,
361
+ req => {
362
+ expect ( req . params . data ) . toBe ( 'abc' ) ;
363
+ return 'Hello world!' ;
364
+ } ,
365
+ {
366
+ fields : {
367
+ data : {
368
+ type : String ,
369
+ required : false ,
370
+ options : s => {
371
+ return s . length >= 4 && s . length <= 50 ;
372
+ } ,
373
+ error : 'Validation failed. Expected length of data to be between 4 and 50.' ,
374
+ } ,
375
+ } ,
376
+ }
377
+ ) ;
378
+ Parse . Cloud . run ( 'hello' , { data : 'abc' } )
379
+ . then ( ( ) => {
380
+ fail ( 'function should have failed.' ) ;
381
+ } )
382
+ . catch ( error => {
383
+ expect ( error . code ) . toEqual ( Parse . Error . VALIDATION_ERROR ) ;
384
+ expect ( error . message ) . toEqual (
385
+ 'Validation failed. Expected length of data to be between 4 and 50.'
386
+ ) ;
387
+ done ( ) ;
388
+ } ) ;
389
+ } ) ;
390
+
391
+ it ( 'set params not-required type' , done => {
392
+ Parse . Cloud . define (
393
+ 'hello' ,
394
+ req => {
395
+ expect ( req . params . data ) . toBe ( null ) ;
396
+ return 'Hello world!' ;
397
+ } ,
398
+ {
399
+ fields : {
400
+ data : {
401
+ type : String ,
402
+ required : false ,
403
+ } ,
404
+ } ,
405
+ }
406
+ ) ;
407
+ Parse . Cloud . run ( 'hello' , { data : null } )
408
+ . then ( ( ) => {
409
+ fail ( 'function should have failed.' ) ;
410
+ } )
411
+ . catch ( error => {
412
+ expect ( error . code ) . toEqual ( Parse . Error . VALIDATION_ERROR ) ;
413
+ expect ( error . message ) . toEqual ( 'Validation failed. Invalid type for data. Expected: string' ) ;
414
+ done ( ) ;
415
+ } ) ;
416
+ } ) ;
417
+
418
+ it ( 'set params not-required options' , done => {
419
+ Parse . Cloud . define (
420
+ 'hello' ,
421
+ ( ) => {
422
+ return 'Hello world!' ;
423
+ } ,
424
+ {
425
+ fields : {
426
+ data : {
427
+ type : String ,
428
+ required : false ,
429
+ options : s => {
430
+ return s . length >= 4 && s . length <= 50 ;
431
+ } ,
432
+ } ,
433
+ } ,
434
+ }
435
+ ) ;
436
+ Parse . Cloud . run ( 'hello' , { } )
437
+ . then ( ( ) => {
438
+ done ( ) ;
439
+ } )
440
+ . catch ( ( ) => {
441
+ fail ( 'function should not have failed.' ) ;
442
+ } ) ;
443
+ } ) ;
444
+
445
+ it ( 'set params not-required no-options' , done => {
446
+ Parse . Cloud . define (
447
+ 'hello' ,
448
+ ( ) => {
449
+ return 'Hello world!' ;
450
+ } ,
451
+ {
452
+ fields : {
453
+ data : {
454
+ type : String ,
455
+ required : false ,
456
+ } ,
457
+ } ,
458
+ }
459
+ ) ;
460
+ Parse . Cloud . run ( 'hello' , { } )
461
+ . then ( ( ) => {
462
+ done ( ) ;
463
+ } )
464
+ . catch ( ( ) => {
465
+ fail ( 'function should not have failed.' ) ;
466
+ } ) ;
467
+ } ) ;
468
+
358
469
it ( 'set params option' , done => {
359
470
Parse . Cloud . define (
360
471
'hello' ,
0 commit comments