@@ -591,24 +591,58 @@ describe('Polymorphism Test', () => {
591
591
} ) ;
592
592
593
593
it ( 'update nested updateMany' , async ( ) => {
594
- const { db, videoWithOwner : video , user } = await setup ( ) ;
594
+ const { db } = await setup ( ) ;
595
595
596
- // updateMany
597
- await db . user . update ( {
598
- where : { id : user . id } ,
596
+ const user = await db . user . create ( {
599
597
data : {
598
+
600
599
ratedVideos : {
601
- create : { url : 'xyz' , duration : 111 , rating : 222 , owner : { connect : { id : user . id } } } ,
600
+ create : { id : 10 , url : 'xyz' , duration : 1 , rating : 111 } ,
602
601
} ,
603
602
} ,
604
603
} ) ;
604
+
605
+ // create another user and video
606
+ await db . user . create ( {
607
+ data : {
608
+
609
+ ratedVideos : {
610
+ create : { id : 20 , url : 'abc' , duration : 2 , rating : 222 } ,
611
+ } ,
612
+ } ,
613
+ } ) ;
614
+
615
+ // updateMany with filter
605
616
await expect (
606
617
db . user . update ( {
607
618
where : { id : user . id } ,
608
- data : { ratedVideos : { updateMany : { where : { duration : 111 } , data : { rating : 333 } } } } ,
619
+ data : {
620
+ ratedVideos : { updateMany : { where : { duration : 1 } , data : { rating : 333 } } } ,
621
+ } ,
609
622
include : { ratedVideos : true } ,
610
623
} )
611
- ) . resolves . toMatchObject ( { ratedVideos : expect . arrayContaining ( [ expect . objectContaining ( { rating : 333 } ) ] ) } ) ;
624
+ ) . resolves . toMatchObject ( {
625
+ ratedVideos : expect . arrayContaining ( [ expect . objectContaining ( { rating : 333 } ) ] ) ,
626
+ } ) ;
627
+
628
+ // updateMany without filter
629
+ await expect (
630
+ db . user . update ( {
631
+ where :
{ email :
'[email protected] ' } ,
632
+ data : {
633
+ ratedVideos : { updateMany : { data : { duration : 3 } } } ,
634
+ } ,
635
+ include : { ratedVideos : true } ,
636
+ } )
637
+ ) . resolves . toMatchObject ( {
638
+ ratedVideos : expect . arrayContaining ( [ expect . objectContaining ( { duration : 3 } ) ] ) ,
639
+ } ) ;
640
+
641
+ // user2's video should not be updated
642
+ await expect ( db . ratedVideo . findUnique ( { where : { id : 20 } } ) ) . resolves . toMatchObject ( {
643
+ duration : 2 ,
644
+ rating : 222 ,
645
+ } ) ;
612
646
} ) ;
613
647
614
648
it ( 'update nested deleteOne' , async ( ) => {
0 commit comments