diff --git a/backend/tests/auth.spec.js b/backend/tests/auth.spec.js new file mode 100644 index 0000000..9fa0fae --- /dev/null +++ b/backend/tests/auth.spec.js @@ -0,0 +1,56 @@ +// Test für Auth-API Endpunkte +import { test, expect } from '@playwright/test'; + +test.describe('Auth API Tests', () => { + test('should register a new user', async ({ request }) => { + const response = await request.post('/auth/register', { + data: { + email: 'test@example.com', + password: 'password123', + name: 'Test User' + } + }); + + expect(response.status()).toBe(201); + const responseBody = await response.json(); + expect(responseBody).toHaveProperty('userId'); + expect(responseBody).toHaveProperty('email', 'test@example.com'); + }); + + test('should login with valid credentials', async ({ request }) => { + const response = await request.post('/auth/login', { + data: { + email: 'test@example.com', + password: 'password123' + } + }); + + expect(response.status()).toBe(200); + const responseBody = await response.json(); + expect(responseBody).toHaveProperty('token'); + expect(responseBody).toHaveProperty('userId'); + }); + + test('should not login with invalid credentials', async ({ request }) => { + const response = await request.post('/auth/login', { + data: { + email: 'test@example.com', + password: 'wrongpassword' + } + }); + + expect(response.status()).toBe(401); + }); + + test('should not register with existing email', async ({ request }) => { + const response = await request.post('/auth/register', { + data: { + email: 'test@example.com', + password: 'password123', + name: 'Test User' + } + }); + + expect(response.status()).toBe(409); + }); +}); \ No newline at end of file