Files
unionflow-mobile-apps/test/features/settings/domain/usecases/get_settings_test.dart
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

95 lines
2.8 KiB
Dart

/// Tests unitaires pour GetSettings use case
library get_settings_test;
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'package:unionflow_mobile_apps/features/settings/domain/repositories/system_config_repository.dart';
import 'package:unionflow_mobile_apps/features/settings/domain/usecases/get_settings.dart';
import 'package:unionflow_mobile_apps/features/settings/data/models/system_config_model.dart';
@GenerateMocks([ISystemConfigRepository])
import 'get_settings_test.mocks.dart';
void main() {
late GetSettings useCase;
late MockISystemConfigRepository mockRepository;
setUp(() {
mockRepository = MockISystemConfigRepository();
useCase = GetSettings(mockRepository);
});
group('GetSettings Use Case', () {
final tConfig = SystemConfigModel(
applicationName: 'UnionFlow',
version: '1.0.0',
maintenanceMode: false,
defaultLanguage: 'fr',
timezone: 'Europe/Paris',
sessionTimeoutMinutes: 30,
);
test('should return system configuration', () async {
// Arrange
when(mockRepository.getConfig()).thenAnswer((_) async => tConfig);
// Act
final result = await useCase();
// Assert
expect(result, equals(tConfig));
expect(result.applicationName, equals('UnionFlow'));
expect(result.maintenanceMode, isFalse);
verify(mockRepository.getConfig());
verifyNoMoreInteractions(mockRepository);
});
test('should return config with all optional fields', () async {
// Arrange
final fullConfig = SystemConfigModel(
applicationName: 'UnionFlow',
version: '1.0.0',
maintenanceMode: false,
defaultLanguage: 'fr',
timezone: 'Europe/Paris',
networkTimeout: 30000,
sessionTimeoutMinutes: 60,
twoFactorAuthEnabled: true,
);
when(mockRepository.getConfig()).thenAnswer((_) async => fullConfig);
// Act
final result = await useCase();
// Assert
expect(result.networkTimeout, equals(30000));
expect(result.twoFactorAuthEnabled, isTrue);
});
test('should handle minimal config', () async {
// Arrange
final minimalConfig = SystemConfigModel(
applicationName: 'UnionFlow',
);
when(mockRepository.getConfig()).thenAnswer((_) async => minimalConfig);
// Act
final result = await useCase();
// Assert
expect(result.applicationName, isNotNull);
verify(mockRepository.getConfig());
});
test('should throw exception when config retrieval fails', () async {
// Arrange
when(mockRepository.getConfig())
.thenThrow(Exception('Config not found'));
// Act & Assert
expect(() => useCase(), throwsException);
});
});
}