From 2a47417b4715336ce6ebe2461aee5f41313be428 Mon Sep 17 00:00:00 2001 From: Mathis HERRIOT <197931332+0x485254@users.noreply.github.com> Date: Sat, 17 May 2025 00:13:18 +0200 Subject: [PATCH] test(groups): add test case for database error handling in findById method --- .../modules/groups/services/groups.service.spec.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/backend/src/modules/groups/services/groups.service.spec.ts b/backend/src/modules/groups/services/groups.service.spec.ts index 424396f..d30d80d 100644 --- a/backend/src/modules/groups/services/groups.service.spec.ts +++ b/backend/src/modules/groups/services/groups.service.spec.ts @@ -161,7 +161,16 @@ describe('GroupsService', () => { const id = 'nonexistent'; mockDb.select.mockImplementationOnce(() => mockDbOperations); mockDbOperations.from.mockImplementationOnce(() => mockDbOperations); - mockDbOperations.where.mockImplementationOnce(() => [undefined]); + mockDbOperations.where.mockImplementationOnce(() => []); + + await expect(service.findById(id)).rejects.toThrow(NotFoundException); + }); + + it('should throw NotFoundException if there is a database error', async () => { + const id = 'invalid-id'; + mockDb.select.mockImplementationOnce(() => { + throw new Error('Database error'); + }); await expect(service.findById(id)).rejects.toThrow(NotFoundException); });