67 lines
2.2 KiB
Dart
67 lines
2.2 KiB
Dart
/// Tests unitaires pour DeleteContribution use case
|
|
library delete_contribution_test;
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:mockito/annotations.dart';
|
|
import 'package:mockito/mockito.dart';
|
|
import 'package:unionflow_mobile_apps/features/contributions/domain/repositories/contribution_repository.dart';
|
|
import 'package:unionflow_mobile_apps/features/contributions/domain/usecases/delete_contribution.dart';
|
|
|
|
@GenerateMocks([IContributionRepository])
|
|
import 'delete_contribution_test.mocks.dart';
|
|
|
|
void main() {
|
|
late DeleteContribution useCase;
|
|
late MockIContributionRepository mockRepository;
|
|
|
|
setUp(() {
|
|
mockRepository = MockIContributionRepository();
|
|
useCase = DeleteContribution(mockRepository);
|
|
});
|
|
|
|
group('DeleteContribution Use Case', () {
|
|
const tContributionId = 'cont123';
|
|
|
|
test('should delete contribution successfully', () async {
|
|
// Arrange
|
|
when(mockRepository.deleteCotisation(tContributionId))
|
|
.thenAnswer((_) async => Future.value());
|
|
|
|
// Act
|
|
await useCase(tContributionId);
|
|
|
|
// Assert
|
|
verify(mockRepository.deleteCotisation(tContributionId));
|
|
verifyNoMoreInteractions(mockRepository);
|
|
});
|
|
|
|
test('should throw exception when contribution not found', () async {
|
|
// Arrange
|
|
when(mockRepository.deleteCotisation(any))
|
|
.thenThrow(Exception('Contribution non trouvée'));
|
|
|
|
// Act & Assert
|
|
expect(() => useCase('nonexistent'), throwsA(isA<Exception>()));
|
|
verify(mockRepository.deleteCotisation('nonexistent'));
|
|
});
|
|
|
|
test('should throw exception when contribution is already paid', () async {
|
|
// Arrange
|
|
when(mockRepository.deleteCotisation(any))
|
|
.thenThrow(Exception('Impossible de supprimer une cotisation payée'));
|
|
|
|
// Act & Assert
|
|
expect(() => useCase(tContributionId), throwsA(isA<Exception>()));
|
|
});
|
|
|
|
test('should throw exception when deletion fails', () async {
|
|
// Arrange
|
|
when(mockRepository.deleteCotisation(any))
|
|
.thenThrow(Exception('Erreur de suppression'));
|
|
|
|
// Act & Assert
|
|
expect(() => useCase(tContributionId), throwsException);
|
|
});
|
|
});
|
|
}
|