feat: WebSocket temps réel + Finance Workflow + corrections
- Task #6: WebSocket /ws/dashboard + Kafka events (5 topics) * Backend: KafkaEventProducer, KafkaEventConsumer * Mobile: WebSocketService (reconnection, heartbeat, typed events) * DashboardBloc: Auto-refresh depuis WebSocket events - Finance Workflow: approbations + budgets (backend + mobile) * Backend: entities, services, resources, migrations Flyway V6 * Mobile: features finance_workflow complète avec BLoC - Corrections DI: interfaces IRepository partout * IProfileRepository, IOrganizationRepository, IMembreRepository * GetIt configuré avec @injectable - Spec-Kit: constitution + templates mis à jour * .specify/memory/constitution.md enrichie * Templates agent, plan, spec, tasks, checklist - Nettoyage: fichiers temporaires supprimés Signed-off-by: lions dev Team
This commit is contained in:
@@ -0,0 +1,141 @@
|
||||
/// Tests unitaires pour GetCompteAdherent use case
|
||||
library get_compte_adherent_test;
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:unionflow_mobile_apps/features/dashboard/domain/usecases/get_compte_adherent.dart';
|
||||
import 'package:unionflow_mobile_apps/features/dashboard/domain/repositories/dashboard_repository.dart';
|
||||
import 'package:unionflow_mobile_apps/features/dashboard/domain/entities/compte_adherent_entity.dart';
|
||||
import 'package:unionflow_mobile_apps/core/error/failures.dart';
|
||||
import 'package:unionflow_mobile_apps/core/usecases/usecase.dart';
|
||||
|
||||
@GenerateMocks([DashboardRepository])
|
||||
import 'get_compte_adherent_test.mocks.dart';
|
||||
|
||||
void main() {
|
||||
late GetCompteAdherent useCase;
|
||||
late MockDashboardRepository mockRepository;
|
||||
|
||||
setUp(() {
|
||||
mockRepository = MockDashboardRepository();
|
||||
useCase = GetCompteAdherent(mockRepository);
|
||||
});
|
||||
|
||||
group('GetCompteAdherent Use Case', () {
|
||||
final tCompteAdherent = CompteAdherentEntity(
|
||||
numeroMembre: 'M-2024-001',
|
||||
nomComplet: 'Amadou Diallo',
|
||||
organisationNom: 'Association Alpha',
|
||||
dateAdhesion: DateTime(2024, 1, 15),
|
||||
statutCompte: 'ACTIF',
|
||||
soldeCotisations: 50000.0,
|
||||
soldeEpargne: 125000.0,
|
||||
soldeBloque: 15000.0,
|
||||
soldeTotalDisponible: 160000.0,
|
||||
encoursCreditTotal: 75000.0,
|
||||
capaciteEmprunt: 200000.0,
|
||||
nombreCotisationsPayees: 12,
|
||||
nombreCotisationsTotal: 12,
|
||||
nombreCotisationsEnRetard: 0,
|
||||
engagementRate: 1.0,
|
||||
nombreComptesEpargne: 2,
|
||||
dateCalcul: DateTime(2024, 12, 15),
|
||||
);
|
||||
|
||||
test('should return compte adherent successfully', () async {
|
||||
// Arrange
|
||||
when(mockRepository.getCompteAdherent())
|
||||
.thenAnswer((_) async => Right(tCompteAdherent));
|
||||
|
||||
// Act
|
||||
final result = await useCase(NoParams());
|
||||
|
||||
// Assert
|
||||
expect(result, Right(tCompteAdherent));
|
||||
result.fold(
|
||||
(failure) => fail('Should not return failure'),
|
||||
(compte) {
|
||||
expect(compte.numeroMembre, equals('M-2024-001'));
|
||||
expect(compte.nomComplet, equals('Amadou Diallo'));
|
||||
expect(compte.soldeTotalDisponible, equals(160000.0));
|
||||
expect(compte.capaciteEmprunt, equals(200000.0));
|
||||
},
|
||||
);
|
||||
verify(mockRepository.getCompteAdherent());
|
||||
verifyNoMoreInteractions(mockRepository);
|
||||
});
|
||||
|
||||
test('should return compte with multiple epargne accounts', () async {
|
||||
// Arrange
|
||||
when(mockRepository.getCompteAdherent())
|
||||
.thenAnswer((_) async => Right(tCompteAdherent));
|
||||
|
||||
// Act
|
||||
final result = await useCase(NoParams());
|
||||
|
||||
// Assert
|
||||
result.fold(
|
||||
(failure) => fail('Should not return failure'),
|
||||
(compte) {
|
||||
expect(compte.nombreComptesEpargne, equals(2));
|
||||
expect(compte.soldeEpargne, equals(125000.0));
|
||||
expect(compte.engagementRate, equals(1.0));
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test('should return compte with overdue contributions', () async {
|
||||
// Arrange
|
||||
final compteWithOverdue = CompteAdherentEntity(
|
||||
numeroMembre: 'M-2024-002',
|
||||
nomComplet: 'Fatou Ndiaye',
|
||||
statutCompte: 'ACTIF',
|
||||
soldeCotisations: 25000.0,
|
||||
soldeEpargne: 50000.0,
|
||||
soldeBloque: 0.0,
|
||||
soldeTotalDisponible: 75000.0,
|
||||
encoursCreditTotal: 0.0,
|
||||
capaciteEmprunt: 100000.0,
|
||||
nombreCotisationsPayees: 8,
|
||||
nombreCotisationsTotal: 12,
|
||||
nombreCotisationsEnRetard: 4,
|
||||
engagementRate: 0.67,
|
||||
nombreComptesEpargne: 1,
|
||||
dateCalcul: DateTime(2024, 12, 15),
|
||||
);
|
||||
when(mockRepository.getCompteAdherent())
|
||||
.thenAnswer((_) async => Right(compteWithOverdue));
|
||||
|
||||
// Act
|
||||
final result = await useCase(NoParams());
|
||||
|
||||
// Assert
|
||||
result.fold(
|
||||
(failure) => fail('Should not return failure'),
|
||||
(compte) {
|
||||
expect(compte.nombreCotisationsEnRetard, equals(4));
|
||||
expect(compte.engagementRate, lessThan(1.0));
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test('should return ServerFailure when repository fails', () async {
|
||||
// Arrange
|
||||
final tFailure = ServerFailure('Erreur serveur');
|
||||
when(mockRepository.getCompteAdherent())
|
||||
.thenAnswer((_) async => Left(tFailure));
|
||||
|
||||
// Act
|
||||
final result = await useCase(NoParams());
|
||||
|
||||
// Assert
|
||||
expect(result, Left(tFailure));
|
||||
result.fold(
|
||||
(failure) => expect(failure, isA<ServerFailure>()),
|
||||
(compte) => fail('Should not return compte'),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
/// Tests unitaires pour GetDashboardData use case
|
||||
library get_dashboard_data_test;
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:unionflow_mobile_apps/features/dashboard/domain/usecases/get_dashboard_data.dart';
|
||||
import 'package:unionflow_mobile_apps/features/dashboard/domain/repositories/dashboard_repository.dart';
|
||||
import 'package:unionflow_mobile_apps/features/dashboard/domain/entities/dashboard_entity.dart';
|
||||
import 'package:unionflow_mobile_apps/core/error/failures.dart';
|
||||
|
||||
@GenerateMocks([DashboardRepository])
|
||||
import 'get_dashboard_data_test.mocks.dart';
|
||||
|
||||
void main() {
|
||||
late GetDashboardData useCase;
|
||||
late MockDashboardRepository mockRepository;
|
||||
|
||||
setUp(() {
|
||||
mockRepository = MockDashboardRepository();
|
||||
useCase = GetDashboardData(mockRepository);
|
||||
});
|
||||
|
||||
group('GetDashboardData Use Case', () {
|
||||
const tOrgId = 'org-123';
|
||||
const tUserId = 'user-456';
|
||||
final tParams = GetDashboardDataParams(
|
||||
organizationId: tOrgId,
|
||||
userId: tUserId,
|
||||
);
|
||||
|
||||
final tDashboardStats = DashboardStatsEntity(
|
||||
totalMembers: 250,
|
||||
activeMembers: 180,
|
||||
totalEvents: 45,
|
||||
upcomingEvents: 12,
|
||||
totalContributions: 1200,
|
||||
totalContributionAmount: 5750000.0,
|
||||
contributionsAmountOnly: 3250000.0,
|
||||
pendingRequests: 8,
|
||||
completedProjects: 23,
|
||||
monthlyGrowth: 0.15,
|
||||
engagementRate: 0.72,
|
||||
lastUpdated: DateTime(2024, 12, 15, 10, 30),
|
||||
totalOrganizations: 5,
|
||||
organizationTypeDistribution: {
|
||||
'association': 3,
|
||||
'cooperative': 2,
|
||||
},
|
||||
);
|
||||
|
||||
test('should return dashboard stats successfully', () async {
|
||||
// Arrange
|
||||
when(mockRepository.getDashboardStats(tOrgId, tUserId))
|
||||
.thenAnswer((_) async => Right(tDashboardStats));
|
||||
|
||||
// Act
|
||||
final result = await GetDashboardStats(mockRepository)(
|
||||
GetDashboardStatsParams(organizationId: tOrgId, userId: tUserId),
|
||||
);
|
||||
|
||||
// Assert
|
||||
expect(result, Right(tDashboardStats));
|
||||
result.fold(
|
||||
(failure) => fail('Should not return failure'),
|
||||
(stats) {
|
||||
expect(stats.totalMembers, equals(250));
|
||||
expect(stats.activeMembers, equals(180));
|
||||
expect(stats.totalContributionAmount, equals(5750000.0));
|
||||
expect(stats.monthlyGrowth, equals(0.15));
|
||||
expect(stats.hasGrowth, isTrue);
|
||||
},
|
||||
);
|
||||
verify(mockRepository.getDashboardStats(tOrgId, tUserId));
|
||||
verifyNoMoreInteractions(mockRepository);
|
||||
});
|
||||
|
||||
test('should return stats with high engagement rate', () async {
|
||||
// Arrange
|
||||
when(mockRepository.getDashboardStats(tOrgId, tUserId))
|
||||
.thenAnswer((_) async => Right(tDashboardStats));
|
||||
|
||||
// Act
|
||||
final result = await GetDashboardStats(mockRepository)(
|
||||
GetDashboardStatsParams(organizationId: tOrgId, userId: tUserId),
|
||||
);
|
||||
|
||||
// Assert
|
||||
result.fold(
|
||||
(failure) => fail('Should not return failure'),
|
||||
(stats) {
|
||||
expect(stats.engagementRate, equals(0.72));
|
||||
expect(stats.isHighEngagement, isTrue);
|
||||
expect(stats.memberActivityRate, closeTo(0.72, 0.01));
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test('should format contribution amount correctly', () async {
|
||||
// Arrange
|
||||
when(mockRepository.getDashboardStats(tOrgId, tUserId))
|
||||
.thenAnswer((_) async => Right(tDashboardStats));
|
||||
|
||||
// Act
|
||||
final result = await GetDashboardStats(mockRepository)(
|
||||
GetDashboardStatsParams(organizationId: tOrgId, userId: tUserId),
|
||||
);
|
||||
|
||||
// Assert
|
||||
result.fold(
|
||||
(failure) => fail('Should not return failure'),
|
||||
(stats) {
|
||||
expect(stats.formattedContributionAmount, equals('5.8M'));
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test('should return ServerFailure when repository fails', () async {
|
||||
// Arrange
|
||||
final tFailure = ServerFailure('Erreur serveur');
|
||||
when(mockRepository.getDashboardStats(any, any))
|
||||
.thenAnswer((_) async => Left(tFailure));
|
||||
|
||||
// Act
|
||||
final result = await GetDashboardStats(mockRepository)(
|
||||
GetDashboardStatsParams(organizationId: tOrgId, userId: tUserId),
|
||||
);
|
||||
|
||||
// Assert
|
||||
expect(result, Left(tFailure));
|
||||
result.fold(
|
||||
(failure) => expect(failure, isA<ServerFailure>()),
|
||||
(stats) => fail('Should not return stats'),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user