From cdf51c43d73af431f104a97a84736822a9e66af5 Mon Sep 17 00:00:00 2001 From: Bruno Roesner Date: Wed, 4 Dec 2024 10:45:50 -0500 Subject: [PATCH] added update() tests --- server/__tests__/room.test.js | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/server/__tests__/room.test.js b/server/__tests__/room.test.js index 7c84697..8bafd73 100644 --- a/server/__tests__/room.test.js +++ b/server/__tests__/room.test.js @@ -136,7 +136,26 @@ describe('Rooms', () => { expect(result).toEqual(rooms); }); - // TODO : add update() test + // matchedCount : number of document matching the id + // modifiedCount : number of modified documents, matching the id + // expectedResult : true or false wether the update happened or not + const cases = [[0, 0, false], [0, 1, true], [1, 0, true], [1, 1, true]]; + test.each(cases)( + "Given %p as modified count and %p as matched count, return %p", + async (modifiedCount, matchedCount, expectedResult) => { + collection.updateOne.mockResolvedValue({ + matchedCount: matchedCount, + modifiedCount: modifiedCount + }); + + const updatedRoom = new Room('123456', 'roomName', 'hostname'); + const result = await roomRepo.update(updatedRoom); + + expect(db.connect).toHaveBeenCalled(); + expect(collection.updateOne).toHaveBeenCalled(); + expect(result).toBe(expectedResult); + } + ); it('should delete existing room', async () => { const mongoObjectID = new ObjectId();