@@ -591,24 +591,58 @@ describe('Polymorphism Test', () => {
591591 } ) ;
592592
593593 it ( 'update nested updateMany' , async ( ) => {
594- const { db, videoWithOwner : video , user } = await setup ( ) ;
594+ const { db } = await setup ( ) ;
595595
596- // updateMany
597- await db . user . update ( {
598- where : { id : user . id } ,
596+ const user = await db . user . create ( {
599597 data : {
598+ email : 'a@b.com' ,
600599 ratedVideos : {
601- create : { url : 'xyz' , duration : 111 , rating : 222 , owner : { connect : { id : user . id } } } ,
600+ create : { id : 10 , url : 'xyz' , duration : 1 , rating : 111 } ,
602601 } ,
603602 } ,
604603 } ) ;
604+
605+ // create another user and video
606+ await db . user . create ( {
607+ data : {
608+ email : 'b@c.com' ,
609+ ratedVideos : {
610+ create : { id : 20 , url : 'abc' , duration : 2 , rating : 222 } ,
611+ } ,
612+ } ,
613+ } ) ;
614+
615+ // updateMany with filter
605616 await expect (
606617 db . user . update ( {
607618 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+ } ,
609622 include : { ratedVideos : true } ,
610623 } )
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 : 'a@b.com' } ,
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+ } ) ;
612646 } ) ;
613647
614648 it ( 'update nested deleteOne' , async ( ) => {
0 commit comments