@@ -3,7 +3,7 @@ import pino from 'pino';
33import { IPermitClient } from '../../index' ;
44import { UserRead } from '../../openapi' ;
55import { createTestClient , printBreak } from '../fixtures' ;
6- import { waitForCheck } from '../helpers/wait-for' ;
6+ import { waitFor , waitForCheck } from '../helpers/wait-for' ;
77
88// Direct-OPA (`useOpa`) checks require a reachable standalone OPA (port 8181),
99// which the dockerized PDP in CI does not expose. Opt in by setting
@@ -234,7 +234,13 @@ it('Permission check e2e test', async () => {
234234 }
235235
236236 logger . info ( 'testing positive permission check with complete user object' ) ;
237- expect ( await permit . check ( user , 'read' , { type : document . key , tenant : tenant . key } ) ) . toBe ( true ) ;
237+ // Gate on the complete-user object's read propagating before the multi-result
238+ // reads below (bulkCheck / getUserPermissions), which query separate PDP
239+ // endpoints that can lag behind a single check.
240+ await waitForCheck (
241+ ( ) => permit . check ( user , 'read' , { type : document . key , tenant : tenant . key } ) ,
242+ true ,
243+ ) ;
238244
239245 printBreak ( ) ;
240246
@@ -263,15 +269,27 @@ it('Permission check e2e test', async () => {
263269 printBreak ( ) ;
264270
265271 logger . info ( 'testing bulk check permissions' ) ;
266- const decisions = await permit . bulkCheck ( [
272+ const bulkQueries = [
267273 { user : user , action : 'read' , resource : { type : document . key , tenant : tenant . key } } ,
268274 { user : user , action : 'create' , resource : { type : document . key , tenant : tenant . key } } ,
269- ] ) ;
275+ ] ;
276+ await waitFor (
277+ async ( ) => {
278+ const d = await permit . bulkCheck ( bulkQueries ) ;
279+ return d . length === 2 && d [ 0 ] === true && d [ 1 ] === false ;
280+ } ,
281+ { timeoutMs : 60_000 , intervalMs : 1_000 , message : 'bulkCheck did not converge' } ,
282+ ) ;
283+ const decisions = await permit . bulkCheck ( bulkQueries ) ;
270284 expect ( decisions . length === 2 ) . toBe ( true ) ;
271285 expect ( decisions [ 0 ] ) . toBe ( true ) ;
272286 expect ( decisions [ 1 ] ) . toBe ( false ) ;
273287
274288 logger . info ( 'testing get user permissions matches assigned roles permissions' ) ;
289+ await waitFor (
290+ async ( ) => `__tenant:${ tenant . key } ` in ( await permit . getUserPermissions ( user . key ) ) ,
291+ { timeoutMs : 60_000 , intervalMs : 1_000 , message : 'getUserPermissions did not converge' } ,
292+ ) ;
275293 const userPermissions = await permit . getUserPermissions ( user . key ) ;
276294 expect ( `__tenant:${ tenant . key } ` in userPermissions ) . toBe ( true ) ;
277295 viewer . permissions ?. forEach ( ( permission ) => {
0 commit comments