@@ -254,6 +254,8 @@ describe(`Access (${dbProvider})`, () => {
254254 }
255255
256256 for ( const l of lists ) {
257+ const itemQuery = `id ${ l . fields . map ( x => x . name ) . join ( ' ' ) } `
258+
257259 describe ( `${ l . name } ` , ( ) => {
258260 test . concurrent ( `list.access.${ l . expect . type } .query: ${ l . expect . query } ` , async ( ) => {
259261 const { context } = await suite ( )
@@ -262,7 +264,7 @@ describe(`Access (${dbProvider})`, () => {
262264 // test list.access.*.query
263265 const item = await context . query [ l . name ] . findOne ( {
264266 where : { id } ,
265- query : `id ${ l . fields . map ( x => x . name ) . join ( ' ' ) } `
267+ query : itemQuery
266268 } )
267269
268270 if ( ! l . expect . query ) {
@@ -294,7 +296,7 @@ describe(`Access (${dbProvider})`, () => {
294296 in : ids
295297 }
296298 } ,
297- query : `id ${ l . fields . map ( x => x . name ) . join ( ' ' ) } `
299+ query : itemQuery
298300 } )
299301
300302 expect ( items ) . not . toBe ( null )
@@ -347,7 +349,7 @@ describe(`Access (${dbProvider})`, () => {
347349 // test list.access.*.create
348350 const createPromise = context . query [ l . name ] . createOne ( {
349351 data : { } ,
350- query : `id ${ l . fields . map ( x => x . name ) . join ( ' ' ) } `
352+ query : itemQuery
351353 } )
352354
353355 if ( ! l . expect . create ) {
@@ -377,7 +379,7 @@ describe(`Access (${dbProvider})`, () => {
377379 // test list.access.*.create
378380 const createPromise = context . query [ l . name ] . createMany ( {
379381 data : [ ...Array ( count ) ] . map ( x => ( { } ) ) ,
380- query : `id ${ l . fields . map ( x => x . name ) . join ( ' ' ) } `
382+ query : itemQuery
381383 } )
382384
383385 if ( ! l . expect . create ) {
@@ -410,7 +412,7 @@ describe(`Access (${dbProvider})`, () => {
410412 const updatePromise = context . query [ l . name ] . updateOne ( {
411413 where : { id } ,
412414 data : { } ,
413- query : `id ${ l . fields . map ( x => x . name ) . join ( ' ' ) } `
415+ query : itemQuery
414416 } )
415417
416418 if ( ! l . expect . update ) {
@@ -445,7 +447,7 @@ describe(`Access (${dbProvider})`, () => {
445447 } ,
446448 data : { }
447449 } ) ) ,
448- query : `id ${ l . fields . map ( x => x . name ) . join ( ' ' ) } `
450+ query : itemQuery
449451 } )
450452
451453 if ( ! l . expect . update ) {
@@ -477,12 +479,16 @@ describe(`Access (${dbProvider})`, () => {
477479 // test list.access.*.delete
478480 const deletePromise = context . query [ l . name ] . deleteOne ( {
479481 where : { id } ,
480- query : `id ${ l . fields . map ( x => x . name ) . join ( ' ' ) } `
482+ query : itemQuery
481483 } )
482484
483485 if ( ! l . expect . delete ) {
484486 const error = deletePromise . catch ( e => e . message )
485- expect ( await error ) . resolves . toBe ( `Access denied: You cannot delete that ${ l . name } - it may not exist` )
487+ expect ( await error ) . toBe ( `Access denied: You cannot delete that ${ l . name } - it may not exist` )
488+
489+ // sudo required, as we might not have query/read access
490+ const count = await context . prisma [ l . name ] . count ( { where : { id } } )
491+ expect ( count ) . toBe ( 1 )
486492 return
487493 }
488494
@@ -500,8 +506,8 @@ describe(`Access (${dbProvider})`, () => {
500506 }
501507
502508 // sudo required, as we might not have query/read access
503- const item_ = await context . sudo ( ) . db [ l . name ] . findOne ( { where : { id } } )
504- expect ( item_ ) . toBe ( null )
509+ const count = await context . prisma [ l . name ] . count ( { where : { id } } )
510+ expect ( count ) . toBe ( 0 )
505511 } )
506512
507513 test . concurrent ( `list.access.${ l . expect . type } .delete: ${ l . expect . delete } (deleteMany)` , async ( ) => {
@@ -513,12 +519,15 @@ describe(`Access (${dbProvider})`, () => {
513519 where : ids . map ( ( id ) => ( {
514520 id
515521 } ) ) ,
516- query : `id ${ l . fields . map ( x => x . name ) . join ( ' ' ) } `
522+ query : itemQuery
517523 } )
518524
519525 if ( ! l . expect . delete ) {
520526 const error = deletePromise . catch ( e => e . message )
521- expect ( await error ) . resolves . toBe ( `Access denied: You cannot delete that ${ l . name } - it may not exist` )
527+ expect ( await error ) . toBe ( `Access denied: You cannot delete that ${ l . name } - it may not exist` )
528+
529+ const count = await context . prisma [ l . name ] . count ( { where : { id : { in : ids } } } )
530+ expect ( count ) . toBe ( ids . length ) // unchanged
522531 return
523532 }
524533
@@ -538,14 +547,8 @@ describe(`Access (${dbProvider})`, () => {
538547 }
539548
540549 // sudo required, as we might not have query/read access
541- const items_ = await context . sudo ( ) . db [ l . name ] . findMany ( {
542- where : {
543- id : {
544- in : items . map ( x => x . id )
545- }
546- }
547- } )
548- expect ( items_ ) . toHaveLength ( 0 )
550+ const count = await context . prisma [ l . name ] . count ( { where : { id : { in : ids } } } )
551+ expect ( count ) . toBe ( 0 ) // changed
549552 } )
550553
551554 // field operations tests
@@ -625,11 +628,11 @@ describe(`Access (${dbProvider})`, () => {
625628 // test field.access.create
626629 if ( ! f . expect . create ) {
627630 const error = createPromise . catch ( ( e : any ) => e . message )
628- await expect ( error ) . resolves . toBe ( `Access denied: You cannot create that ${ l . name } - you cannot create the fields ["${ f . name } "]` )
631+ expect ( await error ) . toBe ( `Access denied: You cannot create that ${ l . name } - you cannot create the fields ["${ f . name } "]` )
629632 return
630633 }
631634
632- await expect ( createPromise ) . resolves . not . toBe ( null )
635+ expect ( await createPromise ) . not . toBe ( null )
633636 const item = await createPromise
634637 expect ( item ) . not . toBe ( null )
635638 expect ( item . id ) . not . toBe ( null )
@@ -656,13 +659,13 @@ describe(`Access (${dbProvider})`, () => {
656659 data : [ ...Array ( count ) ] . map ( x => ( {
657660 [ f . name ] : 'foo'
658661 } ) ) ,
659- query : `id ${ l . fields . map ( x => x . name ) . join ( ' ' ) } `
662+ query : itemQuery
660663 } )
661664
662665 // test field.access.create
663666 if ( ! f . expect . create ) {
664667 const error = createPromise . catch ( e => e . message )
665- await expect ( error ) . resolves . toBe ( `Access denied: You cannot create that ${ l . name } - you cannot create the fields ["${ f . name } "]` )
668+ expect ( await error ) . toBe ( `Access denied: You cannot create that ${ l . name } - you cannot create the fields ["${ f . name } "]` )
666669 return
667670 }
668671
@@ -709,11 +712,11 @@ describe(`Access (${dbProvider})`, () => {
709712 // test field.access.update
710713 if ( ! f . expect . update ) {
711714 const error = updatePromise . catch ( e => e . message )
712- await expect ( error ) . resolves . toBe ( `Access denied: You cannot update that ${ l . name } - you cannot update the fields ["${ f . name } "]` )
715+ expect ( await error ) . toBe ( `Access denied: You cannot update that ${ l . name } - you cannot update the fields ["${ f . name } "]` )
713716 return
714717 }
715718
716- await expect ( updatePromise ) . resolves . not . toBe ( null )
719+ expect ( await updatePromise ) . not . toBe ( null )
717720 const item = await updatePromise
718721 expect ( item ) . not . toBe ( null )
719722 expect ( item ! . id ) . toBe ( id )
0 commit comments