-
-
Notifications
You must be signed in to change notification settings - Fork 12
fix(delegate): sort by fields from delegate base #294
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
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,49 @@ | ||
| import { createPolicyTestClient } from '@zenstackhq/testtools'; | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| // TODO: field-level policy support | ||
| describe.skip('Regression for issue 1014', () => { | ||
| it('update', async () => { | ||
| const db = await createPolicyTestClient( | ||
| ` | ||
| model User { | ||
| id Int @id() @default(autoincrement()) | ||
| name String | ||
| posts Post[] | ||
| } | ||
|
|
||
| model Post { | ||
| id Int @id() @default(autoincrement()) | ||
| title String | ||
| content String? | ||
| author User? @relation(fields: [authorId], references: [id]) | ||
| authorId Int? @allow('update', true, true) | ||
|
|
||
| @@allow('read', true) | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| const user = await db.$unuseAll().user.create({ data: { name: 'User1' } }); | ||
| const post = await db.$unuseAll().post.create({ data: { title: 'Post1' } }); | ||
| await expect(db.post.update({ where: { id: post.id }, data: { authorId: user.id } })).toResolveTruthy(); | ||
| }); | ||
|
|
||
| it('read', async () => { | ||
| const db = await createPolicyTestClient( | ||
| ` | ||
| model Post { | ||
| id Int @id() @default(autoincrement()) | ||
| title String @allow('read', true, true) | ||
| content String | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| const post = await db.$unuseAll().post.create({ data: { title: 'Post1', content: 'Content' } }); | ||
| await expect(db.post.findUnique({ where: { id: post.id } })).toResolveNull(); | ||
| await expect(db.post.findUnique({ where: { id: post.id }, select: { title: true } })).resolves.toEqual({ | ||
| title: 'Post1', | ||
| }); | ||
| }); | ||
| }); |
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,52 @@ | ||
| import { createTestClient } from '@zenstackhq/testtools'; | ||
| import { it } from 'vitest'; | ||
|
|
||
| it('verifies issue 1058', async () => { | ||
| const schema = ` | ||
| model User { | ||
| id String @id @default(cuid()) | ||
| name String | ||
| userRankings UserRanking[] | ||
| userFavorites UserFavorite[] | ||
| } | ||
| model Entity { | ||
| id String @id @default(cuid()) | ||
| name String | ||
| type String | ||
| userRankings UserRanking[] | ||
| userFavorites UserFavorite[] | ||
| @@delegate(type) | ||
| } | ||
| model Person extends Entity { | ||
| } | ||
| model Studio extends Entity { | ||
| } | ||
| model UserRanking { | ||
| id String @id @default(cuid()) | ||
| rank Int | ||
| entityId String | ||
| entity Entity @relation(fields: [entityId], references: [id], onUpdate: NoAction) | ||
| userId String | ||
| user User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: NoAction) | ||
| } | ||
| model UserFavorite { | ||
| id String @id @default(cuid()) | ||
| entityId String | ||
| entity Entity @relation(fields: [entityId], references: [id], onUpdate: NoAction) | ||
| userId String | ||
| user User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: NoAction) | ||
| } | ||
| `; | ||
|
|
||
| await createTestClient(schema, { provider: 'postgresql' }); | ||
| }); | ||
ymc9 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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,53 @@ | ||
| import { createPolicyTestClient } from '@zenstackhq/testtools'; | ||
| import { describe, expect, it } from 'vitest'; | ||
|
|
||
| describe('Regression for issue 1078', () => { | ||
| it('regression1', async () => { | ||
| const db = await createPolicyTestClient( | ||
| ` | ||
| model Counter { | ||
| id String @id | ||
|
|
||
| name String | ||
| value Int | ||
|
|
||
| @@validate(value >= 0) | ||
| @@allow('all', true) | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| await expect( | ||
| db.counter.create({ | ||
| data: { id: '1', name: 'It should create', value: 1 }, | ||
| }), | ||
| ).toResolveTruthy(); | ||
|
|
||
| //! This query fails validation | ||
| await expect( | ||
| db.counter.update({ | ||
| where: { id: '1' }, | ||
| data: { name: 'It should update' }, | ||
| }), | ||
| ).toResolveTruthy(); | ||
| }); | ||
|
|
||
| // TODO: field-level policy support | ||
| it.skip('regression2', async () => { | ||
| const db = await createPolicyTestClient( | ||
| ` | ||
| model Post { | ||
| id Int @id() @default(autoincrement()) | ||
| title String @allow('read', true, true) | ||
| content String | ||
| } | ||
| `, | ||
| ); | ||
|
|
||
| const post = await db.$unuseAll().post.create({ data: { title: 'Post1', content: 'Content' } }); | ||
| await expect(db.post.findUnique({ where: { id: post.id } })).toResolveNull(); | ||
| await expect(db.post.findUnique({ where: { id: post.id }, select: { title: true } })).resolves.toEqual({ | ||
| title: 'Post1', | ||
| }); | ||
| }); | ||
| }); |
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.