@@ -229,6 +229,9 @@ describe('CountItems::CountWorker', () => {
229
229
mongoMock . close . mockImplementationOnce ( cb => cb ( ) ) ;
230
230
mongoMock . client . isConnected . mockImplementationOnce ( ( ) => false ) ;
231
231
mongoMock . getObjectMDStats . mockImplementationOnce ( ( _a , _b , _c , _d , cb ) => cb ( null , { value : 42 } ) ) ;
232
+ mongoMock . isLocationTransient . mockImplementationOnce ( ( _a , _b , cb ) => {
233
+ cb ( null , false ) ;
234
+ } ) ;
232
235
mongoMock . getObject = jest . fn ( ( _a , _b , _c , _d , cb ) => {
233
236
getObjectCall += 1 ;
234
237
if ( getObjectCall === 1 ) {
@@ -246,11 +249,45 @@ describe('CountItems::CountWorker', () => {
246
249
_owner : 'any' ,
247
250
_ownerDisplayName : 'any' ,
248
251
_creationDate : Date . now ( ) . toString ( ) ,
252
+ getLocationConstraint : jest . fn ( ( ) => 'test-location' ) ,
249
253
} ;
250
254
w . countItems ( bucketInfo , ( err , results ) => {
251
255
expect ( err ) . toBeNull ( ) ;
252
256
expect ( results ) . toEqual ( { value : 42 } ) ;
253
257
done ( ) ;
254
258
} ) ;
255
- } ) ;
259
+ } ) ;
260
+
261
+ test ( 'should call isLocationTransient if defined' , done => {
262
+ const testSendFn = jest . fn ( ) ;
263
+ const w = new CountWorker ( {
264
+ log : new DummyLogger ( ) ,
265
+ sendFn : testSendFn ,
266
+ client : mongoMock ,
267
+ } ) ;
268
+
269
+ mongoMock . setup . mockImplementationOnce ( cb => cb ( ) ) ;
270
+ mongoMock . close . mockImplementationOnce ( cb => cb ( ) ) ;
271
+ mongoMock . client . isConnected . mockImplementationOnce ( ( ) => false ) ;
272
+ mongoMock . isLocationTransient . mockImplementationOnce ( ( _a , _b , cb ) => {
273
+ cb ( null , true ) ;
274
+ } ) ;
275
+ mongoMock . getObjectMDStats . mockImplementationOnce ( ( _a , _b , _c , _d , cb ) => cb ( null , { value : 42 } ) ) ;
276
+
277
+ const bucketInfo = {
278
+ getLocationConstraint : ( ) => 'some-location' ,
279
+ _name : 'test-bucket' ,
280
+ _owner : 'any' ,
281
+ _ownerDisplayName : 'any' ,
282
+ _creationDate : Date . now ( ) . toString ( ) ,
283
+ } ;
284
+
285
+ w . countItems ( bucketInfo , ( err , results ) => {
286
+ expect ( err ) . toBeNull ( ) ;
287
+ expect ( results ) . toEqual ( { value : 42 } ) ;
288
+ expect ( mongoMock . isLocationTransient ) . toHaveBeenCalledTimes ( 2 ) ;
289
+ done ( ) ;
290
+ } ) ;
291
+ } ) ;
292
+
256
293
} ) ;
0 commit comments