test(groups): add test case for database error handling in findById method
This commit is contained in:
parent
b5c0e2e98d
commit
2a47417b47
@ -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);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user