Skip to content

Commit

Permalink
try
Browse files Browse the repository at this point in the history
  • Loading branch information
benzekrimaha committed Oct 10, 2024
1 parent 20d47f4 commit 4b01eb0
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions tests/unit/api/BackbeatAPI.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,22 @@ describe('BackbeatAPI', () => {

describe('_setupMongoClient', () => {
let mongoClientStub;
let infoSpy;
let errorSpy;
let debugSpy;

beforeEach(() => {
mongoClientStub = sinon.stub(MongoClient, 'connect');
infoSpy = sinon.spy(fakeLogger, 'info');
errorSpy = sinon.spy(fakeLogger, 'error');
debugSpy = sinon.spy(fakeLogger, 'debug');
});

afterEach(() => {
mongoClientStub.restore();
infoSpy.restore();
errorSpy.restore();
debugSpy.restore();
});

it('should connect to MongoDB when configuration is present', done => {
Expand All @@ -237,7 +246,7 @@ describe('BackbeatAPI', () => {
bbapi._setupMongoClient(err => {
assert.ifError(err);
assert(mongoClientStub.calledOnce);
assert(fakeLogger.info.calledWith('Connected to MongoDB', {
assert(infoSpy.calledWith('Connected to MongoDB', {
method: 'BackbeatAPI._setupMongoClient',
}));
done();
Expand All @@ -257,7 +266,7 @@ describe('BackbeatAPI', () => {
bbapi._setupMongoClient(err => {
assert.strictEqual(err, mockError);
assert(mongoClientStub.calledOnce);
assert(fakeLogger.error.calledWith('Could not connect to MongoDB', {
assert(errorSpy.calledWith('Could not connect to MongoDB', {
method: 'BackbeatAPI._setupMongoClient',
error: mockError.message,
}));
Expand All @@ -271,7 +280,7 @@ describe('BackbeatAPI', () => {
bbapi._setupMongoClient(err => {
assert.ifError(err);
assert(mongoClientStub.notCalled);
assert(fakeLogger.debug.calledWith('MongoDB configuration not found, skipping MongoDB client setup', {
assert(debugSpy.calledWith('MongoDB configuration not found, skipping MongoDB client setup', {
method: 'BackbeatAPI._setupMongoClient',
}));
done();
Expand Down

0 comments on commit 4b01eb0

Please sign in to comment.