Skip to content

Commit 718fd67

Browse files
authored
chore: more tests about delegate models for updateMany (#2056)
1 parent 5224d56 commit 718fd67

File tree

2 files changed

+42
-7
lines changed

2 files changed

+42
-7
lines changed

tests/integration/tests/enhancements/with-delegate/enhanced-client.test.ts

+41-7
Original file line numberDiff line numberDiff line change
@@ -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+
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+
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: '[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+
});
612646
});
613647

614648
it('update nested deleteOne', async () => {

tests/integration/tests/enhancements/with-delegate/utils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export const POLYMORPHIC_SCHEMA = `
22
model User {
33
id Int @id @default(autoincrement())
4+
email String? @unique
45
level Int @default(0)
56
assets Asset[]
67
ratedVideos RatedVideo[] @relation('direct')

0 commit comments

Comments
 (0)