-
-
Notifications
You must be signed in to change notification settings - Fork 12
fix: relation include orderBy validation issue, more test migrations #297
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 all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { loadSchema } from '@zenstackhq/testtools'; | ||
| import { describe, it } from 'vitest'; | ||
|
|
||
| // TODO: multi-schema support | ||
| describe.skip('Regression for issue 1647', () => { | ||
| it('inherits @@schema by default', async () => { | ||
| await loadSchema( | ||
| ` | ||
| model Asset { | ||
| id Int @id | ||
| type String | ||
| @@delegate(type) | ||
| @@schema('public') | ||
| } | ||
|
|
||
| model Post extends Asset { | ||
| title String | ||
| } | ||
| `, | ||
| ); | ||
| }); | ||
|
|
||
| it('respects sub model @@schema overrides', async () => { | ||
| await loadSchema( | ||
| ` | ||
| datasource db { | ||
| provider = 'postgresql' | ||
| url = env('DATABASE_URL') | ||
| schemas = ['public', 'post'] | ||
| } | ||
|
|
||
| generator client { | ||
| provider = 'prisma-client-js' | ||
| previewFeatures = ['multiSchema'] | ||
| } | ||
|
|
||
| model Asset { | ||
| id Int @id | ||
| type String | ||
| @@delegate(type) | ||
| @@schema('public') | ||
| } | ||
|
|
||
| model Post extends Asset { | ||
| title String | ||
| @@schema('post') | ||
| } | ||
| `, | ||
| ); | ||
| }); | ||
| }); |
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,42 @@ | ||
| import { createPolicyTestClient } from '@zenstackhq/testtools'; | ||
| import { expect, it } from 'vitest'; | ||
|
|
||
| it('verifies issue 1648', async () => { | ||
| const db = await createPolicyTestClient( | ||
| ` | ||
| model User { | ||
| id Int @id @default(autoincrement()) | ||
| profile Profile? | ||
| posts Post[] | ||
| } | ||
|
|
||
| model Profile { | ||
| id Int @id @default(autoincrement()) | ||
| someText String | ||
| user User @relation(fields: [userId], references: [id]) | ||
| userId Int @unique | ||
| } | ||
|
|
||
| model Post { | ||
| id Int @id @default(autoincrement()) | ||
| title String | ||
|
|
||
| userId Int | ||
| user User @relation(fields: [userId], references: [id]) | ||
|
|
||
| // this will always be true, even if the someText field is "canUpdate" | ||
| @@deny("post-update", user.profile.someText != "canUpdate") | ||
|
|
||
| @@allow("all", true) | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| await db.$unuseAll().user.create({ data: { id: 1, profile: { create: { someText: 'canUpdate' } } } }); | ||
| await db.$unuseAll().user.create({ data: { id: 2, profile: { create: { someText: 'nothing' } } } }); | ||
| await db.$unuseAll().post.create({ data: { id: 1, title: 'Post1', userId: 1 } }); | ||
| await db.$unuseAll().post.create({ data: { id: 2, title: 'Post2', userId: 2 } }); | ||
|
|
||
| await expect(db.post.update({ where: { id: 1 }, data: { title: 'Post1-1' } })).toResolveTruthy(); | ||
| await expect(db.post.update({ where: { id: 2 }, data: { title: 'Post2-2' } })).toBeRejectedByPolicy(); | ||
| }); | ||
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,80 @@ | ||
| import { createPolicyTestClient } from '@zenstackhq/testtools'; | ||
| import { expect, it } from 'vitest'; | ||
|
|
||
| it('verifies issue 1674', async () => { | ||
| const db = await createPolicyTestClient( | ||
| ` | ||
| model User { | ||
| id String @id @default(cuid()) | ||
| email String @unique @email @length(6, 32) | ||
| posts Post[] | ||
|
|
||
| // everybody can signup | ||
| @@allow('create', true) | ||
|
|
||
| // full access by self | ||
| @@allow('all', auth() == this) | ||
| } | ||
|
|
||
| model Blog { | ||
| id String @id @default(cuid()) | ||
| createdAt DateTime @default(now()) | ||
| updatedAt DateTime @updatedAt | ||
|
|
||
| post Post? @relation(fields: [postId], references: [id], onDelete: Cascade) | ||
| postId String? | ||
| } | ||
|
|
||
| model Post { | ||
| id String @id @default(cuid()) | ||
| createdAt DateTime @default(now()) | ||
| updatedAt DateTime @updatedAt | ||
| title String @length(1, 256) | ||
| content String | ||
| published Boolean @default(false) | ||
| author User @relation(fields: [authorId], references: [id]) | ||
| authorId String | ||
|
|
||
| blogs Blog[] | ||
|
|
||
| type String | ||
|
|
||
| @@delegate(type) | ||
| } | ||
|
|
||
| model PostA extends Post { | ||
| } | ||
|
|
||
| model PostB extends Post { | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| const user = await db.$unuseAll().user.create({ | ||
| data: { email: 'abc@def.com' }, | ||
| }); | ||
|
|
||
| const blog = await db.$unuseAll().blog.create({ | ||
| data: {}, | ||
| }); | ||
|
|
||
| const authDb = db.$setAuth(user); | ||
| await expect( | ||
| authDb.postA.create({ | ||
| data: { | ||
| content: 'content', | ||
| title: 'title', | ||
| blogs: { | ||
| connect: { | ||
| id: blog.id, | ||
| }, | ||
| }, | ||
| author: { | ||
| connect: { | ||
| id: user.id, | ||
| }, | ||
| }, | ||
| }, | ||
| }), | ||
| ).toBeRejectedByPolicy(); | ||
| }); |
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,29 @@ | ||
| import { createTestClient } from '@zenstackhq/testtools'; | ||
| import { expect, it } from 'vitest'; | ||
|
|
||
| it('verifies issue 1681', async () => { | ||
| const db = await createTestClient( | ||
| ` | ||
| model User { | ||
| id Int @id @default(autoincrement()) | ||
| posts Post[] | ||
| @@allow('all', true) | ||
| } | ||
|
|
||
| model Post { | ||
| id Int @id @default(autoincrement()) | ||
| title String | ||
| author User @relation(fields: [authorId], references: [id]) | ||
| authorId Int @default(auth().id) | ||
| @@allow('all', true) | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| const authDb = db.$setAuth({ id: 1 }); | ||
| const user = await db.user.create({ data: {} }); | ||
| await expect(authDb.post.createMany({ data: [{ title: 'Post1' }] })).resolves.toMatchObject({ count: 1 }); | ||
|
|
||
| const r = await authDb.post.createManyAndReturn({ data: [{ title: 'Post2' }] }); | ||
| expect(r[0].authorId).toBe(user.id); | ||
| }); |
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,18 @@ | ||
| import { loadSchema } from '@zenstackhq/testtools'; | ||
| import { it } from 'vitest'; | ||
|
|
||
| it('verifies issue 1693', async () => { | ||
| await loadSchema( | ||
| ` | ||
| model Animal { | ||
| id String @id @default(uuid()) | ||
| animalType String @default("") | ||
| @@delegate(animalType) | ||
| } | ||
|
|
||
| model Dog extends Animal { | ||
| name String | ||
| } | ||
| `, | ||
| ); | ||
| }); |
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,21 @@ | ||
| import { loadSchema } from '@zenstackhq/testtools'; | ||
| import { it } from 'vitest'; | ||
|
|
||
| it('verifies issue 1695', async () => { | ||
| await loadSchema( | ||
| ` | ||
| type SoftDelete { | ||
| deleted Int @default(0) | ||
| } | ||
|
|
||
| model MyModel with SoftDelete { | ||
| id String @id @default(cuid()) | ||
| name String | ||
|
|
||
| @@deny('update', deleted != 0) | ||
| @@deny('post-update', deleted != 0) | ||
| @@deny('read', this.deleted != 0) | ||
| } | ||
| `, | ||
| ); | ||
| }); |
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,72 @@ | ||
| import { createTestClient } from '@zenstackhq/testtools'; | ||
| import { expect, it } from 'vitest'; | ||
|
|
||
| it('verifies issue 1698', async () => { | ||
| const db = await createTestClient( | ||
| ` | ||
| model House { | ||
| id Int @id @default(autoincrement()) | ||
| doorTypeId Int | ||
| door Door @relation(fields: [doorTypeId], references: [id]) | ||
| houseType String | ||
| @@delegate(houseType) | ||
| } | ||
|
|
||
| model PrivateHouse extends House { | ||
| size Int | ||
| } | ||
|
|
||
| model Skyscraper extends House { | ||
| height Int | ||
| } | ||
|
|
||
| model Door { | ||
| id Int @id @default(autoincrement()) | ||
| color String | ||
| doorType String | ||
| houses House[] | ||
| @@delegate(doorType) | ||
| } | ||
|
|
||
| model IronDoor extends Door { | ||
| strength Int | ||
| } | ||
|
|
||
| model WoodenDoor extends Door { | ||
| texture String | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| const door1 = await db.ironDoor.create({ | ||
| data: { strength: 100, color: 'blue' }, | ||
| }); | ||
| console.log(door1); | ||
|
|
||
| const door2 = await db.woodenDoor.create({ | ||
| data: { texture: 'pine', color: 'red' }, | ||
| }); | ||
| console.log(door2); | ||
|
|
||
| const house1 = await db.privateHouse.create({ | ||
| data: { size: 5000, door: { connect: { id: door1.id } } }, | ||
| }); | ||
| console.log(house1); | ||
|
|
||
| const house2 = await db.skyscraper.create({ | ||
| data: { height: 3000, door: { connect: { id: door2.id } } }, | ||
| }); | ||
| console.log(house2); | ||
|
|
||
| const r1 = await db.privateHouse.findFirst({ include: { door: true } }); | ||
| console.log(r1); | ||
| expect(r1).toMatchObject({ | ||
| door: { color: 'blue', strength: 100 }, | ||
| }); | ||
|
|
||
| const r2 = (await db.skyscraper.findMany({ include: { door: true } }))[0]; | ||
| console.log(r2); | ||
| expect(r2).toMatchObject({ | ||
| door: { color: 'red', texture: 'pine' }, | ||
| }); | ||
| }); |
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.