-
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(policy): incorrect policy injection for
createManyAndReturn
whe…
…n the model contains array fields (#1956)
- Loading branch information
Showing
17 changed files
with
130 additions
and
25 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
import { createPostgresDb, dropPostgresDb, loadSchema } from '@zenstackhq/testtools'; | ||
|
||
describe('issue 1955', () => { | ||
it('simple policy', async () => { | ||
const dbUrl = await createPostgresDb('issue-1955-1'); | ||
let _prisma: any; | ||
|
||
try { | ||
const { enhance, prisma } = await loadSchema( | ||
` | ||
model Post { | ||
id Int @id @default(autoincrement()) | ||
name String | ||
expections String[] | ||
@@allow('all', true) | ||
} | ||
`, | ||
{ provider: 'postgresql', dbUrl } | ||
); | ||
_prisma = prisma; | ||
|
||
const db = enhance(); | ||
await expect( | ||
db.post.createManyAndReturn({ | ||
data: [ | ||
{ | ||
name: 'bla', | ||
}, | ||
{ | ||
name: 'blu', | ||
}, | ||
], | ||
}) | ||
).resolves.toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ name: 'bla' }), | ||
expect.objectContaining({ name: 'blu' }), | ||
]) | ||
); | ||
} finally { | ||
await _prisma.$disconnect(); | ||
await dropPostgresDb('issue-1955'); | ||
} | ||
}); | ||
|
||
it('complex policy', async () => { | ||
const dbUrl = await createPostgresDb('issue-1955-2'); | ||
let _prisma: any; | ||
|
||
try { | ||
const { enhance, prisma } = await loadSchema( | ||
` | ||
model Post { | ||
id Int @id @default(autoincrement()) | ||
name String | ||
expections String[] | ||
comments Comment[] | ||
@@allow('all', comments^[private]) | ||
} | ||
model Comment { | ||
id Int @id @default(autoincrement()) | ||
private Boolean @default(false) | ||
postId Int | ||
post Post @relation(fields: [postId], references: [id]) | ||
} | ||
`, | ||
{ provider: 'postgresql', dbUrl } | ||
); | ||
_prisma = prisma; | ||
|
||
const db = enhance(); | ||
await expect( | ||
db.post.createManyAndReturn({ | ||
data: [ | ||
{ | ||
name: 'bla', | ||
}, | ||
{ | ||
name: 'blu', | ||
}, | ||
], | ||
}) | ||
).resolves.toEqual( | ||
expect.arrayContaining([ | ||
expect.objectContaining({ name: 'bla' }), | ||
expect.objectContaining({ name: 'blu' }), | ||
]) | ||
); | ||
} finally { | ||
await _prisma.$disconnect(); | ||
await dropPostgresDb('issue-1955-2'); | ||
} | ||
}); | ||
}); |