-
-
Notifications
You must be signed in to change notification settings - Fork 12
fix: delegate count relation issue, default boolean value issue #302
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,90 @@ | ||
| import { createTestClient } from '@zenstackhq/testtools'; | ||
| import { expect, it } from 'vitest'; | ||
|
|
||
| it('verifies issue 2028', async () => { | ||
| const db = await createTestClient( | ||
| ` | ||
| enum FooType { | ||
| Bar | ||
| Baz | ||
| } | ||
|
|
||
| model User { | ||
| id String @id @default(cuid()) | ||
| userFolders UserFolder[] | ||
| @@allow('all', true) | ||
| } | ||
|
|
||
| model Foo { | ||
| id String @id @default(cuid()) | ||
| type FooType | ||
|
|
||
| userFolders UserFolder[] | ||
|
|
||
| @@delegate(type) | ||
| @@allow('all', true) | ||
| } | ||
|
|
||
| model Bar extends Foo { | ||
| name String | ||
| } | ||
|
|
||
| model Baz extends Foo { | ||
| age Int | ||
| } | ||
|
|
||
| model UserFolder { | ||
| id String @id @default(cuid()) | ||
| userId String | ||
| fooId String | ||
|
|
||
| user User @relation(fields: [userId], references: [id]) | ||
| foo Foo @relation(fields: [fooId], references: [id]) | ||
|
|
||
| @@unique([userId, fooId]) | ||
| @@allow('all', true) | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| // Ensure we can query by the CompoundUniqueInput | ||
| const user = await db.user.create({ data: {} }); | ||
| const bar = await db.bar.create({ data: { name: 'bar' } }); | ||
| const baz = await db.baz.create({ data: { age: 1 } }); | ||
|
|
||
| const userFolderA = await db.userFolder.create({ | ||
| data: { | ||
| userId: user.id, | ||
| fooId: bar.id, | ||
| }, | ||
| }); | ||
|
|
||
| const userFolderB = await db.userFolder.create({ | ||
| data: { | ||
| userId: user.id, | ||
| fooId: baz.id, | ||
| }, | ||
| }); | ||
|
|
||
| await expect( | ||
| db.userFolder.findUnique({ | ||
| where: { | ||
| userId_fooId: { | ||
| userId: user.id, | ||
| fooId: bar.id, | ||
| }, | ||
| }, | ||
| }), | ||
| ).resolves.toMatchObject(userFolderA); | ||
|
|
||
| await expect( | ||
| db.userFolder.findUnique({ | ||
| where: { | ||
| userId_fooId: { | ||
| userId: user.id, | ||
| fooId: baz.id, | ||
| }, | ||
| }, | ||
| }), | ||
| ).resolves.toMatchObject(userFolderB); | ||
| }); |
This file contains hidden or 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,25 @@ | ||
| import { createTestClient } from '@zenstackhq/testtools'; | ||
| import { expect, it } from 'vitest'; | ||
|
|
||
| it('verifies issue 2038', async () => { | ||
| const db = await createTestClient( | ||
| ` | ||
| model User { | ||
| id Int @id @default(autoincrement()) | ||
| flag Boolean | ||
| @@allow('all', true) | ||
| } | ||
|
|
||
| model Post { | ||
| id Int @id @default(autoincrement()) | ||
| published Boolean @default(auth().flag) | ||
| @@allow('all', true) | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| const authDb = db.$setAuth({ id: 1, flag: true }); | ||
| await expect(authDb.post.create({ data: {} })).resolves.toMatchObject({ | ||
| published: true, | ||
| }); | ||
| }); |
This file contains hidden or 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,27 @@ | ||
| import { createTestClient } from '@zenstackhq/testtools'; | ||
| import { expect, it } from 'vitest'; | ||
|
|
||
| it('verifies issue 2039', async () => { | ||
| const db = await createTestClient( | ||
| ` | ||
| type Foo { | ||
| a String | ||
| } | ||
|
|
||
| model Bar { | ||
| id String @id @default(cuid()) | ||
| foo Foo @json @default("{ \\"a\\": \\"a\\" }") | ||
| fooList Foo[] @json @default("[{ \\"a\\": \\"b\\" }]") | ||
| @@allow('all', true) | ||
| } | ||
| `, | ||
| { provider: 'postgresql' }, | ||
| ); | ||
|
|
||
| // Ensure default values are correctly set | ||
| await expect(db.bar.create({ data: {} })).resolves.toMatchObject({ | ||
| id: expect.any(String), | ||
| foo: { a: 'a' }, | ||
| fooList: [{ a: 'b' }], | ||
| }); | ||
| }); |
This file contains hidden or 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,16 @@ | ||
| import { createTestClient } from '@zenstackhq/testtools'; | ||
| import { expect, it } from 'vitest'; | ||
|
|
||
| it('verifies issue 2106', async () => { | ||
| const db = await createTestClient( | ||
| ` | ||
| model User { | ||
| id Int @id | ||
| age BigInt | ||
| @@allow('all', true) | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| await expect(db.user.create({ data: { id: 1, age: 1n } })).toResolveTruthy(); | ||
| }); |
This file contains hidden or 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,79 @@ | ||
| import { createTestClient } from '@zenstackhq/testtools'; | ||
| import { expect, it } from 'vitest'; | ||
|
|
||
| it('verifies issue 2246', async () => { | ||
| const db = await createTestClient( | ||
| ` | ||
| model Media { | ||
| id Int @id @default(autoincrement()) | ||
| title String | ||
| mediaType String | ||
|
|
||
| @@delegate(mediaType) | ||
| @@allow('all', true) | ||
| } | ||
|
|
||
| model Movie extends Media { | ||
| director Director @relation(fields: [directorId], references: [id]) | ||
| directorId Int | ||
| duration Int | ||
| rating String | ||
| } | ||
|
|
||
| model Director { | ||
| id Int @id @default(autoincrement()) | ||
| name String | ||
| email String | ||
| movies Movie[] | ||
|
|
||
| @@allow('all', true) | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| await db.director.create({ | ||
| data: { | ||
| name: 'Christopher Nolan', | ||
| email: '[email protected]', | ||
| movies: { | ||
| create: { | ||
| title: 'Inception', | ||
| duration: 148, | ||
| rating: 'PG-13', | ||
| }, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| await expect( | ||
| db.director.findMany({ | ||
| include: { | ||
| movies: { | ||
| where: { title: 'Inception' }, | ||
| }, | ||
| }, | ||
| }), | ||
| ).resolves.toHaveLength(1); | ||
|
|
||
| await expect( | ||
| db.director.findFirst({ | ||
| include: { | ||
| _count: { select: { movies: { where: { title: 'Inception' } } } }, | ||
| }, | ||
| }), | ||
| ).resolves.toMatchObject({ _count: { movies: 1 } }); | ||
|
|
||
| await expect( | ||
| db.movie.findMany({ | ||
| where: { title: 'Interstellar' }, | ||
| }), | ||
| ).resolves.toHaveLength(0); | ||
|
|
||
| await expect( | ||
| db.director.findFirst({ | ||
| include: { | ||
| _count: { select: { movies: { where: { title: 'Interstellar' } } } }, | ||
| }, | ||
| }), | ||
| ).resolves.toMatchObject({ _count: { movies: 0 } }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.