Archived
1
0

feat/tests #5

Merged
mrqiz merged 7 commits from feat/tests into lord 2025-11-26 00:06:35 +03:00
2 changed files with 114 additions and 0 deletions
Showing only changes of commit 354e00db56 - Show all commits

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);
});
});