File tree Expand file tree Collapse file tree 1 file changed +48
-0
lines changed
tests/integration/tests/enhancements/with-policy Expand file tree Collapse file tree 1 file changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -271,4 +271,52 @@ describe('With Policy: toplevel operations', () => {
271
271
272
272
expect ( await db . model . deleteMany ( ) ) . toEqual ( expect . objectContaining ( { count : 0 } ) ) ;
273
273
} ) ;
274
+
275
+ it ( 'list tests' , async ( ) => {
276
+ const { enhance, prisma } = await loadSchema (
277
+ `
278
+ model Model {
279
+ id String @id @default(uuid())
280
+
281
+ @@allow('create', true)
282
+ @@allow('list', true)
283
+ }
284
+ `
285
+ ) ;
286
+
287
+ const db = enhance ( ) ;
288
+
289
+ await expect (
290
+ db . model . create ( {
291
+ data : {
292
+ id : '1' ,
293
+ value : 1 ,
294
+ } ,
295
+ } )
296
+ ) . toBeRejectedByPolicy ( ) ;
297
+ const fromPrisma = await prisma . model . findUnique ( {
298
+ where : { id : '1' } ,
299
+ } ) ;
300
+ expect ( fromPrisma ) . toBeTruthy ( ) ;
301
+
302
+ expect ( await db . model . findMany ( ) ) . toHaveLength ( 0 ) ;
303
+ expect ( await db . model . findUnique ( { where : { id : '1' } } ) ) . toBeNull ( ) ;
304
+ expect ( await db . model . findFirst ( { where : { id : '1' } } ) ) . toBeNull ( ) ;
305
+ await expect ( db . model . findUniqueOrThrow ( { where : { id : '1' } } ) ) . toBeNotFound ( ) ;
306
+ await expect ( db . model . findFirstOrThrow ( { where : { id : '1' } } ) ) . toBeNotFound ( ) ;
307
+
308
+ const item2 = {
309
+ id : '2' ,
310
+ value : 2 ,
311
+ } ;
312
+ const r1 = await db . model . create ( {
313
+ data : item2 ,
314
+ } ) ;
315
+ expect ( r1 ) . toBeTruthy ( ) ;
316
+ expect ( await db . model . findMany ( ) ) . toHaveLength ( 1 ) ;
317
+ expect ( await db . model . findUnique ( { where : { id : '2' } } ) ) . toEqual ( expect . objectContaining ( item2 ) ) ;
318
+ expect ( await db . model . findFirst ( { where : { id : '2' } } ) ) . toEqual ( expect . objectContaining ( item2 ) ) ;
319
+ expect ( await db . model . findUniqueOrThrow ( { where : { id : '2' } } ) ) . toEqual ( expect . objectContaining ( item2 ) ) ;
320
+ expect ( await db . model . findFirstOrThrow ( { where : { id : '2' } } ) ) . toEqual ( expect . objectContaining ( item2 ) ) ;
321
+ } ) ;
274
322
} ) ;
You can’t perform that action at this time.
0 commit comments