Initial commit: unionflow-mobile-apps
Application Flutter complète (sans build artifacts). Signed-off-by: lions dev Team
This commit is contained in:
118
test/features/events/domain/usecases/create_event_test.dart
Normal file
118
test/features/events/domain/usecases/create_event_test.dart
Normal file
@@ -0,0 +1,118 @@
|
||||
/// Tests unitaires pour CreateEvent use case
|
||||
library create_event_test;
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:unionflow_mobile_apps/features/events/domain/repositories/evenement_repository.dart';
|
||||
import 'package:unionflow_mobile_apps/features/events/domain/usecases/create_event.dart';
|
||||
import 'package:unionflow_mobile_apps/features/events/data/models/evenement_model.dart';
|
||||
|
||||
@GenerateMocks([IEvenementRepository])
|
||||
import 'create_event_test.mocks.dart';
|
||||
|
||||
void main() {
|
||||
late CreateEvent useCase;
|
||||
late MockIEvenementRepository mockRepository;
|
||||
|
||||
setUp(() {
|
||||
mockRepository = MockIEvenementRepository();
|
||||
useCase = CreateEvent(mockRepository);
|
||||
});
|
||||
|
||||
group('CreateEvent Use Case', () {
|
||||
final tNewEvent = EvenementModel(
|
||||
titre: 'Nouvelle Réunion',
|
||||
description: 'Réunion mensuelle du comité',
|
||||
dateDebut: DateTime(2025, 1, 15, 10, 0),
|
||||
dateFin: DateTime(2025, 1, 15, 12, 0),
|
||||
lieu: 'Salle de réunion',
|
||||
type: TypeEvenement.reunion,
|
||||
statut: StatutEvenement.planifie,
|
||||
);
|
||||
|
||||
final tCreatedEvent = EvenementModel(
|
||||
id: 456,
|
||||
titre: 'Nouvelle Réunion',
|
||||
description: 'Réunion mensuelle du comité',
|
||||
dateDebut: DateTime(2025, 1, 15, 10, 0),
|
||||
dateFin: DateTime(2025, 1, 15, 12, 0),
|
||||
lieu: 'Salle de réunion',
|
||||
type: TypeEvenement.reunion,
|
||||
statut: StatutEvenement.planifie,
|
||||
);
|
||||
|
||||
test('should create event successfully', () async {
|
||||
// Arrange
|
||||
when(mockRepository.createEvenement(tNewEvent))
|
||||
.thenAnswer((_) async => tCreatedEvent);
|
||||
|
||||
// Act
|
||||
final result = await useCase(tNewEvent);
|
||||
|
||||
// Assert
|
||||
expect(result, equals(tCreatedEvent));
|
||||
expect(result.id, isNotNull);
|
||||
expect(result.id, equals(456));
|
||||
expect(result.titre, equals('Nouvelle Réunion'));
|
||||
verify(mockRepository.createEvenement(tNewEvent));
|
||||
verifyNoMoreInteractions(mockRepository);
|
||||
});
|
||||
|
||||
test('should create public event with registration', () async {
|
||||
// Arrange
|
||||
final publicEvent = EvenementModel(
|
||||
titre: 'Conférence Publique',
|
||||
dateDebut: DateTime(2025, 2, 1, 14, 0),
|
||||
dateFin: DateTime(2025, 2, 1, 17, 0),
|
||||
type: TypeEvenement.conference,
|
||||
statut: StatutEvenement.planifie,
|
||||
estPublic: true,
|
||||
inscriptionRequise: true,
|
||||
maxParticipants: 200,
|
||||
);
|
||||
final createdPublic = publicEvent.copyWith(id: 789);
|
||||
when(mockRepository.createEvenement(publicEvent))
|
||||
.thenAnswer((_) async => createdPublic);
|
||||
|
||||
// Act
|
||||
final result = await useCase(publicEvent);
|
||||
|
||||
// Assert
|
||||
expect(result.estPublic, isTrue);
|
||||
expect(result.inscriptionRequise, isTrue);
|
||||
expect(result.maxParticipants, equals(200));
|
||||
});
|
||||
|
||||
test('should create event with cost', () async {
|
||||
// Arrange
|
||||
final paidEvent = EvenementModel(
|
||||
titre: 'Séminaire Payant',
|
||||
dateDebut: DateTime(2025, 3, 1, 9, 0),
|
||||
dateFin: DateTime(2025, 3, 1, 18, 0),
|
||||
type: TypeEvenement.seminaire,
|
||||
statut: StatutEvenement.planifie,
|
||||
cout: 50000.0,
|
||||
devise: 'XOF',
|
||||
);
|
||||
when(mockRepository.createEvenement(any))
|
||||
.thenAnswer((_) async => paidEvent.copyWith(id: 999));
|
||||
|
||||
// Act
|
||||
final result = await useCase(paidEvent);
|
||||
|
||||
// Assert
|
||||
expect(result.cout, equals(50000.0));
|
||||
expect(result.devise, equals('XOF'));
|
||||
});
|
||||
|
||||
test('should throw exception when creation fails', () async {
|
||||
// Arrange
|
||||
when(mockRepository.createEvenement(any))
|
||||
.thenThrow(Exception('Validation error'));
|
||||
|
||||
// Act & Assert
|
||||
expect(() => useCase(tNewEvent), throwsException);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user