MORE UNIT TESTS - approc 90% before - 95% now?
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 45m25s
All checks were successful
Deploy to Test Environment / deploy-to-test (push) Successful in 45m25s
This commit is contained in:
@@ -322,6 +322,19 @@ describe('Auth Routes (/api/auth)', () => {
|
||||
expect(response.body.message).toBe('Database connection failed');
|
||||
});
|
||||
|
||||
it('should log a warning when passport authentication fails without a user', async () => {
|
||||
// This test specifically covers the `if (!user)` debug log line in the route.
|
||||
const response = await supertest(app)
|
||||
.post('/api/auth/login')
|
||||
.send({ email: 'notfound@test.com', password: 'any_password' });
|
||||
|
||||
expect(response.status).toBe(401);
|
||||
expect(mockLogger.warn).toHaveBeenCalledWith(
|
||||
{ info: { message: 'Login failed' } },
|
||||
'[API /login] Passport reported NO USER found.'
|
||||
);
|
||||
});
|
||||
|
||||
it('should set a long-lived cookie when rememberMe is true', async () => {
|
||||
// Arrange
|
||||
const loginCredentials = { email: 'test@test.com', password: 'password123', rememberMe: true };
|
||||
@@ -532,5 +545,14 @@ describe('Auth Routes (/api/auth)', () => {
|
||||
'Failed to delete refresh token from DB during logout.'
|
||||
);
|
||||
});
|
||||
|
||||
it('should return 200 OK and clear the cookie even if no refresh token is provided', async () => {
|
||||
// Act: Make a request without a cookie.
|
||||
const response = await supertest(app).post('/api/auth/logout');
|
||||
|
||||
// Assert: The response should still be successful and attempt to clear the cookie.
|
||||
expect(response.status).toBe(200);
|
||||
expect(response.headers['set-cookie'][0]).toContain('refreshToken=;');
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user