11/* eslint-disable @typescript-eslint/no-explicit-any */
22/// <reference types="@types/jest" />
33
4- import { loadSchema , run } from '@zenstackhq/testtools' ;
4+ import { withPolicy } from '@zenstackhq/runtime' ;
5+ import { CrudFailureReason } from '@zenstackhq/runtime/constants' ;
56import { ModelMeta } from '@zenstackhq/runtime/enhancements/types' ;
7+ import { loadSchema , run } from '@zenstackhq/testtools' ;
68import makeHandler from '../../src/api/rest' ;
79import { Response } from '../../src/types' ;
8- import { withPolicy } from '@zenstackhq/runtime' ;
910
1011let prisma : any ;
1112let zodSchemas : any ;
@@ -1844,6 +1845,13 @@ describe('REST server tests - enhanced prisma', () => {
18441845 @@allow('create,read', true)
18451846 @@allow('update', value > 0)
18461847 }
1848+
1849+ model Bar {
1850+ id Int @id
1851+ value Int
1852+
1853+ @@allow('create', true)
1854+ }
18471855 ` ;
18481856
18491857 beforeAll ( async ( ) => {
@@ -1862,7 +1870,7 @@ describe('REST server tests - enhanced prisma', () => {
18621870 run ( 'npx prisma db push' ) ;
18631871 } ) ;
18641872
1865- it ( 'policy rejection test' , async ( ) => {
1873+ it ( 'update policy rejection test' , async ( ) => {
18661874 let r = await handler ( {
18671875 method : 'post' ,
18681876 path : '/foo' ,
@@ -1885,6 +1893,20 @@ describe('REST server tests - enhanced prisma', () => {
18851893 } ) ;
18861894 expect ( r . status ) . toBe ( 403 ) ;
18871895 } ) ;
1896+
1897+ it ( 'read-back policy rejection test' , async ( ) => {
1898+ const r = await handler ( {
1899+ method : 'post' ,
1900+ path : '/bar' ,
1901+ query : { } ,
1902+ requestBody : {
1903+ data : { type : 'bar' , attributes : { id : 1 , value : 0 } } ,
1904+ } ,
1905+ prisma,
1906+ } ) ;
1907+ expect ( r . status ) . toBe ( 403 ) ;
1908+ expect ( ( r . body as any ) . errors [ 0 ] . reason ) . toBe ( CrudFailureReason . RESULT_NOT_READABLE ) ;
1909+ } ) ;
18881910} ) ;
18891911
18901912describe ( 'REST server tests - NextAuth project regression' , ( ) => {
0 commit comments