Veranstaltungen-APP/TESTING_GUIDE.md

272 lines
6.6 KiB
Markdown

# 🧪 Quick Testing Guide
Schnelle Tests aller neuen Features.
## Web-Seiten (Browser)
### 1. Registrierung testen
```
1. Öffnen Sie http://localhost:8000/register
2. Füllen Sie das Formular aus:
- Name: "Test User"
- Email: "test@example.com"
- Passwort: "TestPass123"
- Passwort wiederholen: "TestPass123"
3. Klicken Sie "Registrieren"
4. Sie sollten zur Startseite umgeleitet werden
5. Öffnen Sie Browser Console → Application → Cookies
6. Der auth_token sollte gespeichert sein
```
### 2. Anmeldung testen
```
1. Öffnen Sie http://localhost:8000/login
2. Geben Sie ein:
- Email: test@example.com
- Passwort: TestPass123
3. Klicken Sie "Anmelden"
4. Sie sollten zur Startseite umgeleitet werden
5. Token wird in localStorage gespeichert
```
### 3. Passwort vergessen testen
```
1. Öffnen Sie http://localhost:8000/login
2. Klicken Sie "Passwort vergessen?"
3. Geben Sie Ihre Email ein: test@example.com
4. Klicken Sie "Token anfordern"
5. Ein Token wird in der Info-Box angezeigt
6. Kopieren Sie den Token
7. Klicken Sie "Zum Zurücksetzen klicken"
8. Geben Sie ein:
- Passwort: NewPass123
- Passwort wiederholen: NewPass123
9. Klicken Sie "Passwort zurücksetzen"
10. Sie werden zur Anmeldungsseite umgeleitet
11. Melden Sie sich mit NewPass123 an
```
## API Tests (Terminal)
### 1. Login-Test
```bash
curl -X POST http://localhost:8000/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"user@example.com","password":"password123"}'
```
Erwartet: 200 OK mit Token
### 2. User Profile
```bash
TOKEN="1|l5z3Had9t8AiOnP2gAQZ4yb4QcbfZcs3UQihqVNib46e5d77"
curl -X GET http://localhost:8000/api/user/profile \
-H "Authorization: Bearer $TOKEN"
```
Erwartet: 200 OK mit Benutzerprofil
### 3. User Stats
```bash
curl -X GET http://localhost:8000/api/user/stats \
-H "Authorization: Bearer $TOKEN"
```
Erwartet: 200 OK mit Statistiken
### 4. User Favorites
```bash
curl -X GET http://localhost:8000/api/user/favorites \
-H "Authorization: Bearer $TOKEN"
```
Erwartet: 200 OK mit paginierten Events
### 5. Toggle Favorite
```bash
curl -X POST http://localhost:8000/api/user/favorites/1/toggle \
-H "Authorization: Bearer $TOKEN"
```
Erwartet: 200 OK mit is_favorite Flag
### 6. Forgot Password
```bash
curl -X POST http://localhost:8000/api/auth/forgot-password \
-H "Content-Type: application/json" \
-d '{"email":"user@example.com"}'
```
Erwartet: 200 OK mit Token
### 7. Verify Reset Token
```bash
TOKEN="xyz123"
curl -X POST http://localhost:8000/api/auth/verify-reset-token \
-H "Content-Type: application/json" \
-d '{"email":"user@example.com","token":"'$TOKEN'"}'
```
Erwartet: 200 OK mit valid:true
### 8. Reset Password
```bash
TOKEN="xyz123"
curl -X POST http://localhost:8000/api/auth/reset-password \
-H "Content-Type: application/json" \
-d '{
"email":"user@example.com",
"token":"'$TOKEN'",
"password":"newPassword123",
"password_confirmation":"newPassword123"
}'
```
Erwartet: 200 OK mit Success-Meldung
## Fehlertest
### 1. Ungültige Email
```bash
curl -X POST http://localhost:8000/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"nonexistent@example.com","password":"password123"}'
```
Erwartet: 401 Unauthorized
### 2. Falsches Passwort
```bash
curl -X POST http://localhost:8000/api/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"user@example.com","password":"wrongpassword"}'
```
Erwartet: 401 Unauthorized
### 3. Abgelaufener Token
```bash
curl -X POST http://localhost:8000/api/auth/verify-reset-token \
-H "Content-Type: application/json" \
-d '{"email":"user@example.com","token":"expired-token-from-1-hour-ago"}'
```
Erwartet: 422 Unprocessable Entity
### 4. Passwörter stimmen nicht überein
```bash
curl -X POST http://localhost:8000/api/auth/reset-password \
-H "Content-Type: application/json" \
-d '{
"email":"user@example.com",
"token":"valid-token",
"password":"newPassword123",
"password_confirmation":"differentPassword123"
}'
```
Erwartet: 422 Validation Error
## Demo-Benutzer
Die folgenden Benutzer sind nach `php artisan migrate:fresh --seed` verfügbar:
```
Email: user@example.com
Password: password123
Role: user
Email: organizer@example.com
Password: password123
Role: organizer
Email: admin@example.com
Password: password123
Role: admin
```
## Datenbank Reset
Wenn Sie die Datenbank zurücksetzen möchten:
```bash
cd /Users/meinholdc/Entwicklung/Veranstaltungen-APP
php artisan migrate:fresh --seed
```
Dies:
- Löscht alle Tabellen
- Führt alle Migrationen erneut aus
- Lädt Seeders (erstellt Demo-Benutzer und Events)
## Browser DevTools Tipps
### Tokens anzeigen
```javascript
// Öffnen Sie Console und geben Sie ein:
localStorage.getItem('auth_token')
localStorage.getItem('user')
// Token setzen (für manuelles Testen)
localStorage.setItem('auth_token', 'TOKEN_HERE')
```
### Netzwerk-Requests debugging
1. Öffnen Sie F12 → Network Tab
2. Aktualisieren Sie die Seite
3. Klicken Sie auf einen Request
4. Schauen Sie sich die Response an
5. Mit "Pretty Print" JSON formatieren
## Häufige Probleme
### Problem: 500 Error beim Login
**Lösung**: Datenbank migrieren
```bash
php artisan migrate:fresh --seed
```
### Problem: "Table personal_access_tokens doesn't exist"
**Lösung**: Personal Access Tokens Migration laufen lassen
```bash
php artisan migrate
```
### Problem: Token funktioniert nicht
**Lösung**: Token muss im Format `id|token` sein
```bash
# Richtig:
curl -X GET http://localhost:8000/api/user/profile \
-H "Authorization: Bearer 1|l5z3Had9t8AiOnP2gAQZ4yb4QcbfZcs3UQihqVNib46e5d77"
# Falsch:
curl -X GET http://localhost:8000/api/user/profile \
-H "Authorization: Bearer l5z3Had9t8AiOnP2gAQZ4yb4QcbfZcs3UQihqVNib46e5d77"
```
### Problem: CORS Fehler
**Lösung**: CORS ist bereits konfiguriert. Wenn Sie noch Fehler sehen:
1. Browser Console öffnen
2. Netzwerk-Request anschauen
3. Response Headers prüfen auf `Access-Control-Allow-*`
## Performance-Tipps
### Pagination nutzen
```bash
# Seite 2 mit 20 Items pro Seite
curl -X GET "http://localhost:8000/api/user/favorites?page=2&per_page=20" \
-H "Authorization: Bearer $TOKEN"
```
### N+1 Query Problem vermeiden
Alle Endpunkte verwenden bereits `->with()` für Eager Loading:
- `/api/user/favorites` lädt `location`, `occurrences`, `source`
- `/api/user/events` lädt `location`, `occurrences`, `source`
Keine zusätzlichen Queries nötig!
## SSL/HTTPS
Wenn Sie HTTPS testen möchten:
```bash
php artisan serve --port=8000 --host=localhost --cert
```
Oder verwenden Sie ngrok für öffentliche HTTPS-URLs:
```bash
ngrok http 8000
```
---
**Viel Spaß beim Testen!** 🚀