From 354e00db56a2f8e604a8625c065b079c69d41ad6 Mon Sep 17 00:00:00 2001 From: Egor Mikheev Date: Tue, 25 Nov 2025 07:14:55 +0300 Subject: [PATCH] =?UTF-8?q?feat:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=82=D0=B5=D1=81=D1=82=D1=8B=20=D0=B0=D0=B2=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/backend/src/tests/e2e/auth.test.ts | 59 +++++++++++++++++++++++++ 1 file changed, 59 insertions(+) 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); + }); });