test: add auth API integration tests
Some checks are pending
Docker Test / test (push) Waiting to run
Some checks are pending
Docker Test / test (push) Waiting to run
This commit is contained in:
parent
e807195e22
commit
50431fa6a2
1 changed files with 56 additions and 0 deletions
56
backend/tests/auth.spec.js
Normal file
56
backend/tests/auth.spec.js
Normal file
|
|
@ -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);
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue