more unit test fixes + some integration
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 1h21m56s
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 1h21m56s
This commit is contained in:
@@ -97,6 +97,13 @@ describe('Admin User Management Routes (/api/admin/users)', () => {
|
||||
expect(response.body).toEqual(mockUsers);
|
||||
expect(adminRepo.getAllUsers).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should return 500 if the database call fails', async () => {
|
||||
const dbError = new Error('DB Error');
|
||||
vi.mocked(adminRepo.getAllUsers).mockRejectedValue(dbError);
|
||||
const response = await supertest(app).get('/api/admin/users');
|
||||
expect(response.status).toBe(500);
|
||||
});
|
||||
});
|
||||
|
||||
describe('GET /users/:id', () => {
|
||||
@@ -116,6 +123,13 @@ describe('Admin User Management Routes (/api/admin/users)', () => {
|
||||
expect(response.status).toBe(404);
|
||||
expect(response.body.message).toBe('User not found.');
|
||||
});
|
||||
|
||||
it('should return 500 on a generic database error', async () => {
|
||||
const dbError = new Error('DB Error');
|
||||
vi.mocked(userRepo.findUserProfileById).mockRejectedValue(dbError);
|
||||
const response = await supertest(app).get(`/api/admin/users/${userId}`);
|
||||
expect(response.status).toBe(500);
|
||||
});
|
||||
});
|
||||
|
||||
describe('PUT /users/:id', () => {
|
||||
@@ -141,6 +155,14 @@ describe('Admin User Management Routes (/api/admin/users)', () => {
|
||||
expect(response.body.message).toBe(`User with ID ${missingId} not found.`);
|
||||
});
|
||||
|
||||
it('should return 500 on a generic database error', async () => {
|
||||
const dbError = new Error('DB Error');
|
||||
vi.mocked(adminRepo.updateUserRole).mockRejectedValue(dbError);
|
||||
const response = await supertest(app).put(`/api/admin/users/${userId}`).send({ role: 'admin' });
|
||||
expect(response.status).toBe(500);
|
||||
expect(response.body.message).toBe('DB Error');
|
||||
});
|
||||
|
||||
it('should return 400 for an invalid role', async () => {
|
||||
const response = await supertest(app)
|
||||
.put(`/api/admin/users/${userId}`)
|
||||
@@ -164,5 +186,13 @@ describe('Admin User Management Routes (/api/admin/users)', () => {
|
||||
expect(response.body.message).toMatch(/Admins cannot delete their own account/);
|
||||
expect(userRepo.deleteUserById).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should return 500 on a generic database error', async () => {
|
||||
const targetId = '123e4567-e89b-12d3-a456-426614174999';
|
||||
const dbError = new Error('DB Error');
|
||||
vi.mocked(userRepo.deleteUserById).mockRejectedValue(dbError);
|
||||
const response = await supertest(app).delete(`/api/admin/users/${targetId}`);
|
||||
expect(response.status).toBe(500);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user