@@ -216,4 +216,78 @@ describe('CountItems::CountWorker', () => {
216216 done ( ) ;
217217 } ) ;
218218 } ) ;
219+
220+ test ( 'should use real getIsTransient and not crash' , done => {
221+ const testSendFn = jest . fn ( ) ;
222+ let getObjectCall = 0 ;
223+ const w = new CountWorker ( {
224+ log : new DummyLogger ( ) ,
225+ sendFn : testSendFn ,
226+ client : mongoMock ,
227+ } ) ;
228+ mongoMock . setup . mockImplementationOnce ( cb => cb ( ) ) ;
229+ mongoMock . close . mockImplementationOnce ( cb => cb ( ) ) ;
230+ mongoMock . client . isConnected . mockImplementationOnce ( ( ) => false ) ;
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+ } ) ;
235+ mongoMock . getObject = jest . fn ( ( _a , _b , _c , _d , cb ) => {
236+ getObjectCall += 1 ;
237+ if ( getObjectCall === 1 ) {
238+ cb ( null , 'v1' ) ;
239+ } else {
240+ cb ( null , {
241+ locations : {
242+ undefined : { isTransient : true } ,
243+ } ,
244+ } ) ;
245+ }
246+ } ) ;
247+ const bucketInfo = {
248+ _name : 'test-bucket' ,
249+ _owner : 'any' ,
250+ _ownerDisplayName : 'any' ,
251+ _creationDate : Date . now ( ) . toString ( ) ,
252+ getLocationConstraint : jest . fn ( ( ) => 'test-location' ) ,
253+ } ;
254+ w . countItems ( bucketInfo , ( err , results ) => {
255+ expect ( err ) . toBeNull ( ) ;
256+ expect ( results ) . toEqual ( { value : 42 } ) ;
257+ done ( ) ;
258+ } ) ;
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+
219293} ) ;
0 commit comments