@@ -168,6 +168,42 @@ describe('AbacService integration (onRoomAttributesChanged)', () => {
168168 await usersCol . bulkWrite ( operations ) ;
169169 } ;
170170
171+ // It's utterly incredible i have to do this so the tests are "fast" because mongo is not warm
172+ // I could have increased the timeout for the first test too but...
173+ const dbWarmup = async ( ) => {
174+ const uniqueSuffix = `${ Date . now ( ) . toString ( 36 ) } -${ Math . random ( ) . toString ( 36 ) . slice ( 2 , 8 ) } ` ;
175+ const warmupAttributeKey = `warmup_seed_${ uniqueSuffix } ` ;
176+ const warmupUserId = `warmup-abac-user-${ uniqueSuffix } ` ;
177+ const warmupRid = await insertRoom ( [ ] ) ;
178+ const subscriptionCol = db . collection < any > ( 'rocketchat_subscription' ) ;
179+ const seedSubscriptionId = `warmup-${ uniqueSuffix } ` ;
180+
181+ await subscriptionCol . insertOne ( {
182+ _id : seedSubscriptionId ,
183+ rid : `warmup-room-${ uniqueSuffix } ` ,
184+ u : { _id : `warmup-user-${ uniqueSuffix } ` } ,
185+ } as any ) ;
186+ await insertDefinitions ( [ { key : warmupAttributeKey , values : [ 'a' ] } ] ) ;
187+ await insertUsers ( [ { _id : warmupUserId , member : true , extraRooms : [ warmupRid ] } ] ) ;
188+ await subscriptionCol . insertOne ( {
189+ _id : `warmup-sub-${ uniqueSuffix } ` ,
190+ rid : warmupRid ,
191+ u : { _id : warmupUserId } ,
192+ } as any ) ;
193+
194+ try {
195+ await service . setRoomAbacAttributes ( warmupRid , { [ warmupAttributeKey ] : [ 'a' ] } , fakeActor ) ;
196+ } finally {
197+ await roomsCol . deleteOne ( { _id : warmupRid } ) ;
198+ await usersCol . deleteOne ( { _id : warmupUserId } ) ;
199+ await subscriptionCol . deleteMany ( {
200+ _id : { $in : [ seedSubscriptionId , `warmup-sub-${ uniqueSuffix } ` ] } ,
201+ } ) ;
202+ await subscriptionCol . deleteMany ( { rid : warmupRid } ) ;
203+ await db . collection < any > ( 'rocketchat_abac_attributes' ) . deleteOne ( { key : warmupAttributeKey } ) ;
204+ }
205+ } ;
206+
171207 let debugSpy : jest . SpyInstance ;
172208 let auditSpy : jest . SpyInstance ;
173209
@@ -182,6 +218,8 @@ describe('AbacService integration (onRoomAttributesChanged)', () => {
182218 usersCol = db . collection < IUser > ( 'users' ) ;
183219 await usersCol . deleteMany ( { _id : { $in : staticUserIds } } ) ;
184220 await insertUsers ( staticTestUsers ) ;
221+
222+ await dbWarmup ( ) ;
185223 } , 30_000 ) ;
186224
187225 afterAll ( async ( ) => {
0 commit comments