-
-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
115 additions
and
16 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 |
---|---|---|
|
@@ -9,7 +9,7 @@ plugins { | |
} | ||
|
||
group = "dev.zenstack" | ||
version = "2.5.0" | ||
version = "2.5.1" | ||
|
||
repositories { | ||
mavenCentral() | ||
|
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
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
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
91 changes: 91 additions & 0 deletions
91
tests/integration/tests/enhancements/with-policy/abstract.test.ts
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,91 @@ | ||
import { loadSchema } from '@zenstackhq/testtools'; | ||
|
||
describe('Abstract models', () => { | ||
it('connect test1', async () => { | ||
const { enhance } = await loadSchema( | ||
` | ||
model User { | ||
id Int @id @default(autoincrement()) | ||
profile Profile? @relation(fields: [profileId], references: [id]) | ||
profileId Int? @unique | ||
@@allow('create,read', true) | ||
@@allow('update', auth().id == 1) | ||
} | ||
abstract model BaseProfile { | ||
id Int @id @default(autoincrement()) | ||
user User? | ||
@@allow('all', true) | ||
} | ||
model Profile extends BaseProfile { | ||
name String | ||
} | ||
` | ||
); | ||
|
||
const db = enhance({ id: 2 }); | ||
const user = await db.user.create({ data: { id: 1 } }); | ||
const profile = await db.profile.create({ data: { id: 1, name: 'John' } }); | ||
await expect( | ||
db.profile.update({ where: { id: 1 }, data: { user: { connect: { id: user.id } } } }) | ||
).toBeRejectedByPolicy(); | ||
await expect( | ||
db.user.update({ where: { id: 1 }, data: { profile: { connect: { id: profile.id } } } }) | ||
).toBeRejectedByPolicy(); | ||
|
||
const db1 = enhance({ id: 1 }); | ||
await expect( | ||
db1.profile.update({ where: { id: 1 }, data: { user: { connect: { id: user.id } } } }) | ||
).toResolveTruthy(); | ||
await expect( | ||
db1.user.update({ where: { id: 1 }, data: { profile: { connect: { id: profile.id } } } }) | ||
).toResolveTruthy(); | ||
}); | ||
|
||
it('connect test2', async () => { | ||
const { enhance } = await loadSchema( | ||
` | ||
model User { | ||
id Int @id @default(autoincrement()) | ||
profile Profile? | ||
@@allow('all', true) | ||
} | ||
abstract model BaseProfile { | ||
id Int @id @default(autoincrement()) | ||
user User? @relation(fields: [userId], references: [id]) | ||
userId Int? @unique | ||
@@allow('create,read', true) | ||
@@allow('update', auth().id == 1) | ||
} | ||
model Profile extends BaseProfile { | ||
name String | ||
} | ||
` | ||
); | ||
|
||
const db = enhance({ id: 2 }); | ||
const user = await db.user.create({ data: { id: 1 } }); | ||
const profile = await db.profile.create({ data: { id: 1, name: 'John' } }); | ||
await expect( | ||
db.profile.update({ where: { id: 1 }, data: { user: { connect: { id: user.id } } } }) | ||
).toBeRejectedByPolicy(); | ||
await expect( | ||
db.user.update({ where: { id: 1 }, data: { profile: { connect: { id: profile.id } } } }) | ||
).toBeRejectedByPolicy(); | ||
|
||
const db1 = enhance({ id: 1 }); | ||
await expect( | ||
db1.profile.update({ where: { id: 1 }, data: { user: { connect: { id: user.id } } } }) | ||
).toResolveTruthy(); | ||
await expect( | ||
db1.user.update({ where: { id: 1 }, data: { profile: { connect: { id: profile.id } } } }) | ||
).toResolveTruthy(); | ||
}); | ||
}); |