-
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix:
createManyAndReturn
doesn't work for polymorphic models
- Loading branch information
Showing
5 changed files
with
137 additions
and
7 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
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
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,63 @@ | ||
import { loadSchema } from '@zenstackhq/testtools'; | ||
describe('issue 1576', () => { | ||
it('regression', async () => { | ||
const { enhance } = await loadSchema( | ||
` | ||
model Profile { | ||
id Int @id @default(autoincrement()) | ||
name String | ||
items Item[] | ||
type String | ||
@@delegate(type) | ||
@@allow('all', true) | ||
} | ||
model GoldProfile extends Profile { | ||
ticket Int | ||
} | ||
model Item { | ||
id Int @id @default(autoincrement()) | ||
profileId Int | ||
profile Profile @relation(fields: [profileId], references: [id]) | ||
type String | ||
@@delegate(type) | ||
@@allow('all', true) | ||
} | ||
model GoldItem extends Item { | ||
inventory Boolean | ||
} | ||
` | ||
); | ||
|
||
const db = enhance(); | ||
|
||
const profile = await db.goldProfile.create({ | ||
data: { | ||
name: 'hello', | ||
ticket: 5, | ||
}, | ||
}); | ||
|
||
await expect( | ||
db.goldItem.createManyAndReturn({ | ||
data: [ | ||
{ | ||
profileId: profile.id, | ||
inventory: true, | ||
}, | ||
{ | ||
profileId: profile.id, | ||
inventory: true, | ||
}, | ||
], | ||
}) | ||
).resolves.toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ profileId: profile.id, type: 'GoldItem', inventory: true }), | ||
expect.objectContaining({ profileId: profile.id, type: 'GoldItem', inventory: true }), | ||
]) | ||
); | ||
}); | ||
}); |