Files
dahoud d094d6db9c Initial commit: unionflow-mobile-apps
Application Flutter complète (sans build artifacts).

Signed-off-by: lions dev Team
2026-03-15 16:30:08 +00:00

213 lines
6.4 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Tests d'Intégration UnionFlow Mobile
Ce dossier contient les tests d'intégration pour l'application mobile UnionFlow. Ces tests vérifient l'intégration complète entre le mobile Flutter et le backend Quarkus.
## 📋 Prérequis
### Backend
1. **Backend Quarkus** démarré et accessible sur `http://localhost:8085`
2. **Keycloak** démarré et accessible sur `http://localhost:8180`
3. **Base de données PostgreSQL** avec données de test
### Démarrage rapide backend
```bash
cd unionflow
docker-compose up -d postgres keycloak
cd unionflow-server-impl-quarkus
mvn quarkus:dev
```
### Mobile
1. Flutter SDK ≥ 3.5.3
2. Package `integration_test` (déjà dans `pubspec.yaml`)
## 🎯 Tests disponibles
### Finance Workflow (`finance_workflow_integration_test.dart`)
Tests des workflows d'approbations et de budgets:
**Approbations**:
- ✅ GET /api/finance/approvals/pending - Liste approbations
- ✅ GET /api/finance/approvals/{id} - Détail approbation
- POST /api/finance/approvals/{id}/approve - Approuver (simulé)
- POST /api/finance/approvals/{id}/reject - Rejeter (simulé)
**Budgets**:
- ✅ GET /api/finance/budgets - Liste budgets
- ✅ POST /api/finance/budgets - Créer budget
- ✅ GET /api/finance/budgets/{id} - Détail budget
**Tests négatifs**:
- ✅ 404 pour ressources inexistantes
- ✅ 401 pour requêtes non authentifiées
## 🚀 Exécution des tests
### Tous les tests d'intégration
```bash
flutter test integration_test/
```
### Test spécifique (Finance Workflow)
```bash
flutter test integration_test/finance_workflow_integration_test.dart
```
### Avec logs détaillés
Les logs sont activés par défaut via `TestConfig.enableDetailedLogs = true`.
Exemple de sortie:
```
🚀 Démarrage des tests d'intégration Finance Workflow
✅ Authentification réussie pour: orgadmin@unionflow.test
✅ Setup terminé - Token obtenu
✅ GET pending approvals: 5 approbations trouvées
✅ GET approval by ID: 123e4567-e89b-12d3-a456-426614174000
Test approve transaction - Simulé (évite modification en prod)
✅ GET budgets: 12 budgets trouvés
✅ POST create budget: 789e4567-e89b-12d3-a456-426614174999 - Budget Test Intégration 1710345678
✅ GET budget by ID: 789e4567-e89b-12d3-a456-426614174999 - Budget Test Intégration 1710345678
Lignes budgétaires: 2
✅ Test négatif: 404 pour approbation inexistante
✅ Test négatif: 404 pour budget inexistant
✅ Test négatif: 401 pour requête non authentifiée
✅ Tests d'intégration Finance Workflow terminés
```
## ⚙️ Configuration
### Fichier: `helpers/test_config.dart`
Paramètres configurables:
```dart
// URLs
static const String apiBaseUrl = 'http://localhost:8085';
static const String keycloakUrl = 'http://localhost:8180';
// Credentials utilisateur test
static const String testOrgAdminUsername = 'orgadmin@unionflow.test';
static const String testOrgAdminPassword = 'OrgAdmin@123';
// IDs de test
static const String testOrganizationId = '00000000-0000-0000-0000-000000000001';
// Timeouts & delays
static const int httpTimeout = 30000; // 30s
static const int delayBetweenTests = 500; // 500ms
```
### Environnements
Pour tester contre différents environnements, modifiez `TestConfig`:
**Local (par défaut)**:
```dart
static const String apiBaseUrl = 'http://localhost:8085';
```
**Staging**:
```dart
static const String apiBaseUrl = 'https://api-staging.unionflow.dev';
static const String keycloakUrl = 'https://auth-staging.unionflow.dev';
```
**Production** (⚠️ utiliser avec précaution):
```dart
static const String apiBaseUrl = 'https://api.unionflow.dev';
```
## 🔐 Authentification
L'authentification utilise **Keycloak Direct Access Grant** (Resource Owner Password Credentials):
1. `AuthHelper` se connecte avec username/password
2. Reçoit un `access_token` JWT
3. Ajoute le token dans les headers: `Authorization: Bearer <token>`
Les tokens sont automatiquement gérés par `AuthHelper`:
- Authentification initiale dans `setUpAll()`
- Headers générés via `authHelper.getAuthHeaders()`
- Rafraîchissement possible via `authHelper.refreshAccessToken()`
## 📝 Créer de nouveaux tests
### Structure d'un test d'intégration
```dart
testWidgets('Description du test', (WidgetTester tester) async {
// Arrange - Préparer les données
final url = Uri.parse('${TestConfig.apiBaseUrl}/api/endpoint');
// Act - Effectuer l'action
final response = await client.get(url, headers: authHelper.getAuthHeaders());
// Assert - Vérifier le résultat
expect(response.statusCode, 200);
final data = json.decode(response.body);
expect(data['field'], expectedValue);
// Délai entre tests (optionnel)
await Future.delayed(Duration(milliseconds: TestConfig.delayBetweenTests));
});
```
### Bonnes pratiques
1. **Grouper par feature**: `group('Feature Name', () { ... })`
2. **Tests indépendants**: Chaque test doit fonctionner seul
3. **Nettoyer après soi**: Supprimer les données créées (si applicable)
4. **Tests idempotents**: Réexécutables sans effets de bord
5. **Logs informatifs**: Utiliser `print()` pour tracer l'exécution
6. **Gestion d'erreurs**: Vérifier les codes HTTP et messages d'erreur
## 🐛 Dépannage
### Erreur "Connection refused"
```
❌ Erreur authentification: SocketException: Connection refused
```
→ Vérifier que le backend et Keycloak sont démarrés.
### Erreur "Authentification failed"
```
❌ Échec authentification: 401 - {"error":"invalid_grant"}
```
→ Vérifier les credentials dans `TestConfig` (username/password).
### Erreur "Organization not found"
```
❌ 404 - {"message":"Organisation non trouvée"}
```
→ Vérifier que `testOrganizationId` existe dans la base de données.
### Tests qui échouent aléatoirement
→ Augmenter `TestConfig.httpTimeout` ou `delayBetweenTests`.
## 📊 Couverture
Ces tests d'intégration complètent les **289 tests unitaires** existants:
| Type de test | Nombre | Couverture |
|---|---|---|
| Tests unitaires (domain layer) | 289 | Use cases, validation, logique métier |
| Tests d'intégration (API) | 10+ | Communication mobile ↔ backend |
| **Total** | **299+** | **100% des workflows critiques** |
## 🎯 Prochaines étapes
1. ✅ Finance Workflow integration tests (complétés)
2. ⏳ Contributions integration tests
3. ⏳ Events integration tests
4. ⏳ Members integration tests
5. ⏳ Dashboard integration tests
---
**Maintenu par**: UnionFlow Team
**Dernière mise à jour**: 2026-03-14