Skip to content

Commit

Permalink
Fixup test and coverage improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
benzekrimaha committed Dec 12, 2024
1 parent e05c7b0 commit 83a5d2b
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion tests/unit/utils/LocationStatusStream.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('LocationStatusStream', () => {
const lss = new LocationStatusStream('lifecycle', mongoConfig, pauseStub, null, FakeLogger);
lss._locationStatusColl = {
find: () => ({
toArray: sinon.stub().yields(null, locations),
toArray: sinon.stub().resolves(locations),
}),
};
lss._initializeLocationStatuses(err => {
Expand Down Expand Up @@ -161,6 +161,30 @@ describe('LocationStatusStream', () => {
});
});

it('_initializeLocationStatuses:: should handle errors when fetching location statuses', done => {
const error = new Error('MongoDB error');
const lss = new LocationStatusStream('lifecycle', mongoConfig, null, null, FakeLogger);
lss._locationStatusColl = {
find: () => ({
toArray: sinon.stub().rejects(error),
}),
};
const errorSpy = sinon.spy(lss._log, 'error');
lss._initializeLocationStatuses(err => {
assert(err);
assert.strictEqual(err.message, 'MongoDB error');
assert(errorSpy.calledOnce);
assert(errorSpy.calledWith(
'Could not fetch location statuses from mongo',
sinon.match({
method: 'ServiceStatusManager._initializeLocationStatuses',
error: 'MongoDB error',
})
));
return done();
});
});

it('should use resumeAfter with mongo 3.6', done => {
const lss = new LocationStatusStream('lifecycle', mongoConfig, null, null, FakeLogger);
lss._mongoVersion = '3.6.2';
Expand Down

0 comments on commit 83a5d2b

Please sign in to comment.