feat: добавил первый тест авторизации
This commit is contained in:
36
apps/backend/src/tests/e2e/auth.test.ts
Normal file
36
apps/backend/src/tests/e2e/auth.test.ts
Normal file
@ -0,0 +1,36 @@
|
||||
import { describe, expect, test, } from 'bun:test';
|
||||
|
||||
describe('E2E: Authentication', () => {
|
||||
const testUser = {
|
||||
name: 'Test User',
|
||||
email: `test-${Date.now()}@example.com`,
|
||||
password: 'TestPassword123!',
|
||||
};
|
||||
|
||||
let authCookie: string;
|
||||
let userId: string;
|
||||
|
||||
test('should register new user', async () => {
|
||||
const response = await fetch('http://localhost:3000/auth/api/sign-up/email', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(testUser),
|
||||
});
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
|
||||
const data = await response.json() as unknown as any;
|
||||
expect(data.user).toBeDefined();
|
||||
expect(data.user.email).toBe(testUser.email);
|
||||
expect(data.user.name).toBe(testUser.name);
|
||||
|
||||
userId = data.user.id;
|
||||
|
||||
// Получаем cookies из ответа
|
||||
const setCookieHeader = response.headers.get('set-cookie');
|
||||
expect(setCookieHeader).toBeDefined();
|
||||
authCookie = setCookieHeader!;
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user