Skip to content

Commit 796b65a

Browse files
committed
fixup on tests
1 parent 8f20ab6 commit 796b65a

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

tests/mocks/mongoClient.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ module.exports = {
55
setup: jest.fn(),
66
close: jest.fn(),
77
getObjectMDStats: jest.fn(),
8+
isLocationTransient: jest.fn(),
89
getObject: jest.fn(),
910
getBucketInfos: jest.fn(),
1011
updateStorageConsumptionMetrics: jest.fn(),

tests/unit/CountItems/CountWorker.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ describe('CountItems::CountWorker', () => {
229229
mongoMock.close.mockImplementationOnce(cb => cb());
230230
mongoMock.client.isConnected.mockImplementationOnce(() => false);
231231
mongoMock.getObjectMDStats.mockImplementationOnce((_a, _b, _c, _d, cb) => cb(null, { value: 42 }));
232+
mongoMock.isLocationTransient.mockImplementationOnce((_a, _b, cb) => {
233+
cb(null, false);
234+
});
232235
mongoMock.getObject = jest.fn((_a, _b, _c, _d, cb) => {
233236
getObjectCall += 1;
234237
if (getObjectCall === 1) {
@@ -246,11 +249,45 @@ describe('CountItems::CountWorker', () => {
246249
_owner: 'any',
247250
_ownerDisplayName: 'any',
248251
_creationDate: Date.now().toString(),
252+
getLocationConstraint: jest.fn(() => 'test-location'),
249253
};
250254
w.countItems(bucketInfo, (err, results) => {
251255
expect(err).toBeNull();
252256
expect(results).toEqual({ value: 42 });
253257
done();
254258
});
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+
256293
});

0 commit comments

Comments
 (0)