Archived
1
0

feat: добавил тесты авторизации

This commit is contained in:
Egor Mikheev
2025-11-25 07:14:55 +03:00
parent 35fd995d2d
commit 354e00db56

View File

@ -33,4 +33,63 @@ describe('E2E: Authentication', () => {
expect(setCookieHeader).toBeDefined();
authCookie = setCookieHeader!;
});
test('should get current session with cookies', async () => {
const response = await fetch('http://localhost:3000/auth/api/get-session', {
headers: {
'Cookie': authCookie,
},
});
expect(response.status).toBe(200);
const data = await response.json() as any;
expect(data.user).toBeDefined();
expect(data.user.email).toBe(testUser.email);
});
test('should sign in with credentials', async () => {
const response = await fetch('http://localhost:3000/auth/api/sign-in/email', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: testUser.email,
password: testUser.password,
}),
});
expect(response.status).toBe(200);
const data = await response.json() as any;
expect(data.user).toBeDefined();
expect(data.user.email).toBe(testUser.email);
const setCookieHeader = response.headers.get('set-cookie');
expect(setCookieHeader).toBeDefined();
authCookie = setCookieHeader!;
});
test('should fail with wrong password', async () => {
const response = await fetch('http://localhost:3000/auth/api/sign-in/email', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: testUser.email,
password: 'WrongPassword',
}),
});
expect(response.status).toBeGreaterThanOrEqual(400);
});
test('should fail without cookies', async () => {
const response = await fetch('http://localhost:3000/auth/api/session');
// Должен вернуть 401 или отсутствующую сессию
expect(response.status).toBeGreaterThanOrEqual(400);
});
});