From 1e7533be58b5bae8df41668a2171096535ba6053 Mon Sep 17 00:00:00 2001 From: Bruno Roesner Date: Wed, 4 Dec 2024 10:46:06 -0500 Subject: [PATCH] added console warn logSpy in tests --- server/__tests__/room.test.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/server/__tests__/room.test.js b/server/__tests__/room.test.js index 8bafd73..25ea974 100644 --- a/server/__tests__/room.test.js +++ b/server/__tests__/room.test.js @@ -28,7 +28,7 @@ describe('Rooms', () => { // Mock the collection object collection = { findOne: jest.fn(), - insertOne: jest.fn(), // Mock the insertOne method + insertOne: jest.fn(), find: jest.fn().mockReturnValue({ toArray: jest.fn() }), // Mock the find method deleteOne: jest.fn(), deleteMany: jest.fn(), @@ -97,6 +97,7 @@ describe('Rooms', () => { }); it('should get the room with existing id', async () => { + const logSpy = jest.spyOn(global.console, "warn"); const roomID = '123456'; collection.findOne.mockResolvedValue({ id: roomID }); @@ -106,9 +107,13 @@ describe('Rooms', () => { expect(db.getConnection).toHaveBeenCalled(); expect(collection.findOne).toHaveBeenCalled(); expect(result.id).toBe("123456"); + expect(logSpy).toHaveBeenCalledTimes(0); + + logSpy.mockClear(); }); it('should get null if no room with id is found', async () => { + const logSpy = jest.spyOn(global.console, "warn"); const roomID = '123456'; collection.findOne.mockResolvedValue(null); @@ -118,6 +123,9 @@ describe('Rooms', () => { expect(db.getConnection).toHaveBeenCalled(); expect(collection.findOne).toHaveBeenCalled(); expect(result).toBeNull(); + expect(logSpy).toHaveBeenCalledTimes(1); + + logSpy.mockClear(); }); it('should return all rooms', async () => { @@ -158,6 +166,7 @@ describe('Rooms', () => { ); it('should delete existing room', async () => { + const logSpy = jest.spyOn(global.console, "warn"); const mongoObjectID = new ObjectId(); const roomID = '123456'; @@ -168,9 +177,13 @@ describe('Rooms', () => { const result = await roomRepo.delete(roomID); expect(result).toBeTruthy(); + expect(logSpy).toHaveBeenCalledTimes(0); + + logSpy.mockClear(); }); it('should not delete un-existing room', async () => { + const logSpy = jest.spyOn(global.console, "warn"); const mongoObjectID = new ObjectId(); const roomID = '123456'; @@ -181,5 +194,8 @@ describe('Rooms', () => { const result = await roomRepo.delete(roomID); expect(result).toBeFalsy(); + expect(logSpy).toHaveBeenCalledTimes(1); + + logSpy.mockClear(); }); });