From 4b01eb09433088e7b766a912f8c6c1a25bf90779 Mon Sep 17 00:00:00 2001 From: Maha Benzekri Date: Thu, 10 Oct 2024 09:11:32 +0200 Subject: [PATCH] try --- tests/unit/api/BackbeatAPI.spec.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/unit/api/BackbeatAPI.spec.js b/tests/unit/api/BackbeatAPI.spec.js index d9b0cc1a3..6c9e3f653 100644 --- a/tests/unit/api/BackbeatAPI.spec.js +++ b/tests/unit/api/BackbeatAPI.spec.js @@ -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 => { @@ -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(); @@ -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, })); @@ -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();