@@ -431,6 +431,7 @@ describe('schemas', () => {
431
431
defaultValue : false ,
432
432
} ,
433
433
defaultZero : { type : 'Number' , defaultValue : 0 } ,
434
+ relation : { type : 'Relation' , targetClass : 'SomeClass' }
434
435
} ,
435
436
} ,
436
437
} ) . then ( async response => {
@@ -457,6 +458,7 @@ describe('schemas', () => {
457
458
defaultValue : false ,
458
459
} ,
459
460
defaultZero : { type : 'Number' , defaultValue : 0 } ,
461
+ relation : { type : 'Relation' , targetClass : 'SomeClass' }
460
462
} ,
461
463
classLevelPermissions : defaultClassLevelPermissions ,
462
464
} ) ;
@@ -479,10 +481,108 @@ describe('schemas', () => {
479
481
expect ( obj . get ( 'defaultFalse' ) ) . toEqual ( false ) ;
480
482
expect ( obj . get ( 'defaultZero' ) ) . toEqual ( 0 ) ;
481
483
expect ( obj . get ( 'ptr' ) ) . toBeUndefined ( ) ;
484
+ expect ( obj . get ( 'relation' ) ) . toBeUndefined ( ) ;
482
485
done ( ) ;
483
486
} ) ;
484
487
} ) ;
485
488
489
+ it ( 'try to set a relation field as a required field' , async ( done ) => {
490
+ try {
491
+ await request ( {
492
+ url : 'http://localhost:8378/1/schemas' ,
493
+ method : 'POST' ,
494
+ headers : masterKeyHeaders ,
495
+ json : true ,
496
+ body : {
497
+ className : 'NewClassWithRelationRequired' ,
498
+ fields : {
499
+ foo : { type : 'String' } ,
500
+ relation : { type : 'Relation' , targetClass : 'SomeClass' , required : true }
501
+ } ,
502
+ } ,
503
+ } ) ;
504
+ fail ( 'should fail' ) ;
505
+ } catch ( e ) {
506
+ expect ( e . data . code ) . toEqual ( 111 ) ;
507
+ }
508
+ done ( ) ;
509
+ } ) ;
510
+
511
+ it ( 'try to set a relation field with a default value' , async ( done ) => {
512
+ try {
513
+ await request ( {
514
+ url : 'http://localhost:8378/1/schemas' ,
515
+ method : 'POST' ,
516
+ headers : masterKeyHeaders ,
517
+ json : true ,
518
+ body : {
519
+ className : 'NewClassRelationWithOptions' ,
520
+ fields : {
521
+ foo : { type : 'String' } ,
522
+ relation : { type : 'Relation' , targetClass : 'SomeClass' , defaultValue : { __type : 'Relation' , className : '_User' } }
523
+ } ,
524
+ } ,
525
+ } ) ;
526
+ fail ( 'should fail' ) ;
527
+ } catch ( e ) {
528
+ expect ( e . data . code ) . toEqual ( 111 ) ;
529
+ }
530
+ done ( ) ;
531
+ } ) ;
532
+
533
+ it ( 'try to update schemas with a relation field with options' , async ( done ) => {
534
+ await request ( {
535
+ url : 'http://localhost:8378/1/schemas' ,
536
+ method : 'POST' ,
537
+ headers : masterKeyHeaders ,
538
+ json : true ,
539
+ body : {
540
+ className : 'NewClassRelationWithOptions' ,
541
+ fields : {
542
+ foo : { type : 'String' }
543
+ } ,
544
+ } ,
545
+ } ) ;
546
+ try {
547
+ await request ( {
548
+ url : 'http://localhost:8378/1/schemas/NewClassRelationWithOptions' ,
549
+ method : 'POST' ,
550
+ headers : masterKeyHeaders ,
551
+ json : true ,
552
+ body : {
553
+ className : 'NewClassRelationWithOptions' ,
554
+ fields : {
555
+ relation : { type : 'Relation' , targetClass : 'SomeClass' , required : true }
556
+ } ,
557
+ _method : "PUT"
558
+ }
559
+ } ) ;
560
+ fail ( 'should fail' ) ;
561
+ } catch ( e ) {
562
+ expect ( e . data . code ) . toEqual ( 111 ) ;
563
+ }
564
+
565
+ try {
566
+ await request ( {
567
+ url : 'http://localhost:8378/1/schemas/NewClassRelationWithOptions' ,
568
+ method : 'POST' ,
569
+ headers : masterKeyHeaders ,
570
+ json : true ,
571
+ body : {
572
+ className : 'NewClassRelationWithOptions' ,
573
+ fields : {
574
+ relation : { type : 'Relation' , targetClass : 'SomeClass' , defaultValue : { __type : 'Relation' , className : '_User' } }
575
+ } ,
576
+ _method : "PUT"
577
+ }
578
+ } ) ;
579
+ fail ( 'should fail' ) ;
580
+ } catch ( e ) {
581
+ expect ( e . data . code ) . toEqual ( 111 ) ;
582
+ }
583
+ done ( ) ;
584
+ } ) ;
585
+
486
586
it ( 'validated the data type of default values when creating a new class' , async ( ) => {
487
587
try {
488
588
await request ( {
0 commit comments