test(groups): add test case for database error handling in findById method

This commit is contained in:
Mathis HERRIOT 2025-05-17 00:13:18 +02:00
parent b5c0e2e98d
commit 2a47417b47
No known key found for this signature in database
GPG Key ID: E7EB4A211D8D4907

View File

@ -161,7 +161,16 @@ describe('GroupsService', () => {
const id = 'nonexistent'; const id = 'nonexistent';
mockDb.select.mockImplementationOnce(() => mockDbOperations); mockDb.select.mockImplementationOnce(() => mockDbOperations);
mockDbOperations.from.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); await expect(service.findById(id)).rejects.toThrow(NotFoundException);
}); });