diff --git a/apps/backend/src/tests/e2e/auth.test.ts b/apps/backend/src/tests/e2e/auth.test.ts index 69aa3c9..64b1704 100644 --- a/apps/backend/src/tests/e2e/auth.test.ts +++ b/apps/backend/src/tests/e2e/auth.test.ts @@ -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); + }); });