From 50431fa6a2d8ce11da640db80914810c2901dbb8 Mon Sep 17 00:00:00 2001 From: OpenClaw Date: Sat, 7 Mar 2026 02:17:23 +0000 Subject: [PATCH] test: add auth API integration tests --- backend/tests/auth.spec.js | 56 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 backend/tests/auth.spec.js 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