-
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(delegate): make sure nested
createMany
is converted into regula…
…r `create` Fixes #1520
- Loading branch information
Showing
2 changed files
with
101 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { loadSchema } from '@zenstackhq/testtools'; | ||
|
||
describe('issue 1520', () => { | ||
it('regression', async () => { | ||
const { enhance } = await loadSchema( | ||
` | ||
model Course { | ||
id Int @id @default(autoincrement()) | ||
title String | ||
addedToNotifications AddedToCourseNotification[] | ||
} | ||
model Group { | ||
id Int @id @default(autoincrement()) | ||
addedToNotifications AddedToGroupNotification[] | ||
} | ||
model Notification { | ||
id Int @id @default(autoincrement()) | ||
createdAt DateTime @default(now()) | ||
type String | ||
senderId Int | ||
receiverId Int | ||
@@delegate (type) | ||
} | ||
model AddedToGroupNotification extends Notification { | ||
groupId Int | ||
group Group @relation(fields: [groupId], references: [id], onDelete: Cascade) | ||
} | ||
model AddedToCourseNotification extends Notification { | ||
courseId Int | ||
course Course @relation(fields: [courseId], references: [id], onDelete: Cascade) | ||
} | ||
`, | ||
{ enhancements: ['delegate'] } | ||
); | ||
|
||
const db = enhance(); | ||
const r = await db.course.create({ | ||
data: { | ||
title: 'English classes', | ||
addedToNotifications: { | ||
createMany: { | ||
data: [ | ||
{ | ||
id: 1, | ||
receiverId: 1, | ||
senderId: 2, | ||
}, | ||
], | ||
}, | ||
}, | ||
}, | ||
include: { addedToNotifications: true }, | ||
}); | ||
|
||
expect(r.addedToNotifications).toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ | ||
id: 1, | ||
courseId: 1, | ||
receiverId: 1, | ||
senderId: 2, | ||
}), | ||
]) | ||
); | ||
}); | ||
}); |