Initial commit: unionflow-mobile-apps

Application Flutter complète (sans build artifacts).

Signed-off-by: lions dev Team
This commit is contained in:
dahoud
2026-03-15 16:30:08 +00:00
commit d094d6db9c
1790 changed files with 507435 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
/// Tests unitaires pour ClearCache use case
library clear_cache_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/clear_cache.dart';
@GenerateMocks([ISystemConfigRepository])
import 'clear_cache_test.mocks.dart';
void main() {
late ClearCache useCase;
late MockISystemConfigRepository mockRepository;
setUp(() {
mockRepository = MockISystemConfigRepository();
useCase = ClearCache(mockRepository);
});
group('ClearCache Use Case', () {
test('should clear cache successfully', () async {
// Arrange
when(mockRepository.clearCache())
.thenAnswer((_) async => Future.value());
// Act
await useCase();
// Assert
verify(mockRepository.clearCache());
verifyNoMoreInteractions(mockRepository);
});
test('should complete without error when cache is empty', () async {
// Arrange
when(mockRepository.clearCache())
.thenAnswer((_) async => Future.value());
// Act
await useCase();
// Assert
verify(mockRepository.clearCache()).called(1);
});
test('should throw exception when clear operation fails', () async {
// Arrange
when(mockRepository.clearCache())
.thenThrow(Exception('Clear operation failed'));
// Act & Assert
expect(() => useCase(), throwsA(isA<Exception>()));
verify(mockRepository.clearCache());
});
test('should throw exception when permission denied', () async {
// Arrange
when(mockRepository.clearCache())
.thenThrow(Exception('Permission denied'));
// Act & Assert
expect(() => useCase(), throwsException);
});
});
}

View File

@@ -0,0 +1,184 @@
// Mocks generated by Mockito 5.4.4 from annotations
// in unionflow_mobile_apps/test/features/settings/domain/usecases/clear_cache_test.dart.
// Do not manually edit this file.
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i6;
import 'package:mockito/mockito.dart' as _i1;
import 'package:unionflow_mobile_apps/features/settings/data/models/cache_stats_model.dart'
as _i3;
import 'package:unionflow_mobile_apps/features/settings/data/models/system_config_model.dart'
as _i2;
import 'package:unionflow_mobile_apps/features/settings/data/models/system_metrics_model.dart'
as _i4;
import 'package:unionflow_mobile_apps/features/settings/domain/repositories/system_config_repository.dart'
as _i5;
// ignore_for_file: type=lint
// ignore_for_file: avoid_redundant_argument_values
// ignore_for_file: avoid_setters_without_getters
// ignore_for_file: comment_references
// ignore_for_file: deprecated_member_use
// ignore_for_file: deprecated_member_use_from_same_package
// ignore_for_file: implementation_imports
// ignore_for_file: invalid_use_of_visible_for_testing_member
// ignore_for_file: prefer_const_constructors
// ignore_for_file: unnecessary_parenthesis
// ignore_for_file: camel_case_types
// ignore_for_file: subtype_of_sealed_class
class _FakeSystemConfigModel_0 extends _i1.SmartFake
implements _i2.SystemConfigModel {
_FakeSystemConfigModel_0(
Object parent,
Invocation parentInvocation,
) : super(
parent,
parentInvocation,
);
}
class _FakeCacheStatsModel_1 extends _i1.SmartFake
implements _i3.CacheStatsModel {
_FakeCacheStatsModel_1(
Object parent,
Invocation parentInvocation,
) : super(
parent,
parentInvocation,
);
}
class _FakeSystemMetricsModel_2 extends _i1.SmartFake
implements _i4.SystemMetricsModel {
_FakeSystemMetricsModel_2(
Object parent,
Invocation parentInvocation,
) : super(
parent,
parentInvocation,
);
}
/// A class which mocks [ISystemConfigRepository].
///
/// See the documentation for Mockito's code generation for more information.
class MockISystemConfigRepository extends _i1.Mock
implements _i5.ISystemConfigRepository {
MockISystemConfigRepository() {
_i1.throwOnMissingStub(this);
}
@override
_i6.Future<_i2.SystemConfigModel> getConfig() => (super.noSuchMethod(
Invocation.method(
#getConfig,
[],
),
returnValue:
_i6.Future<_i2.SystemConfigModel>.value(_FakeSystemConfigModel_0(
this,
Invocation.method(
#getConfig,
[],
),
)),
) as _i6.Future<_i2.SystemConfigModel>);
@override
_i6.Future<_i2.SystemConfigModel> updateConfig(
Map<String, dynamic>? config) =>
(super.noSuchMethod(
Invocation.method(
#updateConfig,
[config],
),
returnValue:
_i6.Future<_i2.SystemConfigModel>.value(_FakeSystemConfigModel_0(
this,
Invocation.method(
#updateConfig,
[config],
),
)),
) as _i6.Future<_i2.SystemConfigModel>);
@override
_i6.Future<_i3.CacheStatsModel> getCacheStats() => (super.noSuchMethod(
Invocation.method(
#getCacheStats,
[],
),
returnValue:
_i6.Future<_i3.CacheStatsModel>.value(_FakeCacheStatsModel_1(
this,
Invocation.method(
#getCacheStats,
[],
),
)),
) as _i6.Future<_i3.CacheStatsModel>);
@override
_i6.Future<_i4.SystemMetricsModel> getMetrics() => (super.noSuchMethod(
Invocation.method(
#getMetrics,
[],
),
returnValue:
_i6.Future<_i4.SystemMetricsModel>.value(_FakeSystemMetricsModel_2(
this,
Invocation.method(
#getMetrics,
[],
),
)),
) as _i6.Future<_i4.SystemMetricsModel>);
@override
_i6.Future<void> clearCache() => (super.noSuchMethod(
Invocation.method(
#clearCache,
[],
),
returnValue: _i6.Future<void>.value(),
returnValueForMissingStub: _i6.Future<void>.value(),
) as _i6.Future<void>);
@override
_i6.Future<Map<String, dynamic>> testDatabase() => (super.noSuchMethod(
Invocation.method(
#testDatabase,
[],
),
returnValue:
_i6.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
) as _i6.Future<Map<String, dynamic>>);
@override
_i6.Future<Map<String, dynamic>> testEmail() => (super.noSuchMethod(
Invocation.method(
#testEmail,
[],
),
returnValue:
_i6.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
) as _i6.Future<Map<String, dynamic>>);
@override
_i6.Future<_i2.SystemConfigModel> resetConfig() => (super.noSuchMethod(
Invocation.method(
#resetConfig,
[],
),
returnValue:
_i6.Future<_i2.SystemConfigModel>.value(_FakeSystemConfigModel_0(
this,
Invocation.method(
#resetConfig,
[],
),
)),
) as _i6.Future<_i2.SystemConfigModel>);
}

View File

@@ -0,0 +1,96 @@
/// Tests unitaires pour GetCacheStats use case
library get_cache_stats_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_cache_stats.dart';
import 'package:unionflow_mobile_apps/features/settings/data/models/cache_stats_model.dart';
@GenerateMocks([ISystemConfigRepository])
import 'get_cache_stats_test.mocks.dart';
void main() {
late GetCacheStats useCase;
late MockISystemConfigRepository mockRepository;
setUp(() {
mockRepository = MockISystemConfigRepository();
useCase = GetCacheStats(mockRepository);
});
group('GetCacheStats Use Case', () {
final tCacheStats = CacheStatsModel(
totalEntries: 1000,
hits: 850,
misses: 150,
hitRate: 0.85,
totalSizeBytes: 1024 * 1024 * 50, // 50 MB
);
test('should return cache statistics', () async {
// Arrange
when(mockRepository.getCacheStats()).thenAnswer((_) async => tCacheStats);
// Act
final result = await useCase();
// Assert
expect(result, equals(tCacheStats));
expect(result.totalEntries, equals(1000));
expect(result.hitRate, equals(0.85));
verify(mockRepository.getCacheStats());
verifyNoMoreInteractions(mockRepository);
});
test('should handle empty cache', () async {
// Arrange
final emptyCacheStats = CacheStatsModel(
totalEntries: 0,
hits: 0,
misses: 0,
hitRate: 0.0,
totalSizeBytes: 0,
);
when(mockRepository.getCacheStats())
.thenAnswer((_) async => emptyCacheStats);
// Act
final result = await useCase();
// Assert
expect(result.totalEntries, equals(0));
expect(result.hitRate, equals(0.0));
});
test('should handle low hit rate cache', () async {
// Arrange
final lowHitCacheStats = CacheStatsModel(
totalEntries: 100,
hits: 20,
misses: 80,
hitRate: 0.20,
totalSizeBytes: 1024 * 100,
);
when(mockRepository.getCacheStats())
.thenAnswer((_) async => lowHitCacheStats);
// Act
final result = await useCase();
// Assert
expect(result.hitRate, lessThan(0.5));
expect(result.misses!, greaterThan(result.hits!));
});
test('should throw exception when stats retrieval fails', () async {
// Arrange
when(mockRepository.getCacheStats())
.thenThrow(Exception('Stats unavailable'));
// Act & Assert
expect(() => useCase(), throwsException);
});
});
}

View File

@@ -0,0 +1,184 @@
// Mocks generated by Mockito 5.4.4 from annotations
// in unionflow_mobile_apps/test/features/settings/domain/usecases/get_cache_stats_test.dart.
// Do not manually edit this file.
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i6;
import 'package:mockito/mockito.dart' as _i1;
import 'package:unionflow_mobile_apps/features/settings/data/models/cache_stats_model.dart'
as _i3;
import 'package:unionflow_mobile_apps/features/settings/data/models/system_config_model.dart'
as _i2;
import 'package:unionflow_mobile_apps/features/settings/data/models/system_metrics_model.dart'
as _i4;
import 'package:unionflow_mobile_apps/features/settings/domain/repositories/system_config_repository.dart'
as _i5;
// ignore_for_file: type=lint
// ignore_for_file: avoid_redundant_argument_values
// ignore_for_file: avoid_setters_without_getters
// ignore_for_file: comment_references
// ignore_for_file: deprecated_member_use
// ignore_for_file: deprecated_member_use_from_same_package
// ignore_for_file: implementation_imports
// ignore_for_file: invalid_use_of_visible_for_testing_member
// ignore_for_file: prefer_const_constructors
// ignore_for_file: unnecessary_parenthesis
// ignore_for_file: camel_case_types
// ignore_for_file: subtype_of_sealed_class
class _FakeSystemConfigModel_0 extends _i1.SmartFake
implements _i2.SystemConfigModel {
_FakeSystemConfigModel_0(
Object parent,
Invocation parentInvocation,
) : super(
parent,
parentInvocation,
);
}
class _FakeCacheStatsModel_1 extends _i1.SmartFake
implements _i3.CacheStatsModel {
_FakeCacheStatsModel_1(
Object parent,
Invocation parentInvocation,
) : super(
parent,
parentInvocation,
);
}
class _FakeSystemMetricsModel_2 extends _i1.SmartFake
implements _i4.SystemMetricsModel {
_FakeSystemMetricsModel_2(
Object parent,
Invocation parentInvocation,
) : super(
parent,
parentInvocation,
);
}
/// A class which mocks [ISystemConfigRepository].
///
/// See the documentation for Mockito's code generation for more information.
class MockISystemConfigRepository extends _i1.Mock
implements _i5.ISystemConfigRepository {
MockISystemConfigRepository() {
_i1.throwOnMissingStub(this);
}
@override
_i6.Future<_i2.SystemConfigModel> getConfig() => (super.noSuchMethod(
Invocation.method(
#getConfig,
[],
),
returnValue:
_i6.Future<_i2.SystemConfigModel>.value(_FakeSystemConfigModel_0(
this,
Invocation.method(
#getConfig,
[],
),
)),
) as _i6.Future<_i2.SystemConfigModel>);
@override
_i6.Future<_i2.SystemConfigModel> updateConfig(
Map<String, dynamic>? config) =>
(super.noSuchMethod(
Invocation.method(
#updateConfig,
[config],
),
returnValue:
_i6.Future<_i2.SystemConfigModel>.value(_FakeSystemConfigModel_0(
this,
Invocation.method(
#updateConfig,
[config],
),
)),
) as _i6.Future<_i2.SystemConfigModel>);
@override
_i6.Future<_i3.CacheStatsModel> getCacheStats() => (super.noSuchMethod(
Invocation.method(
#getCacheStats,
[],
),
returnValue:
_i6.Future<_i3.CacheStatsModel>.value(_FakeCacheStatsModel_1(
this,
Invocation.method(
#getCacheStats,
[],
),
)),
) as _i6.Future<_i3.CacheStatsModel>);
@override
_i6.Future<_i4.SystemMetricsModel> getMetrics() => (super.noSuchMethod(
Invocation.method(
#getMetrics,
[],
),
returnValue:
_i6.Future<_i4.SystemMetricsModel>.value(_FakeSystemMetricsModel_2(
this,
Invocation.method(
#getMetrics,
[],
),
)),
) as _i6.Future<_i4.SystemMetricsModel>);
@override
_i6.Future<void> clearCache() => (super.noSuchMethod(
Invocation.method(
#clearCache,
[],
),
returnValue: _i6.Future<void>.value(),
returnValueForMissingStub: _i6.Future<void>.value(),
) as _i6.Future<void>);
@override
_i6.Future<Map<String, dynamic>> testDatabase() => (super.noSuchMethod(
Invocation.method(
#testDatabase,
[],
),
returnValue:
_i6.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
) as _i6.Future<Map<String, dynamic>>);
@override
_i6.Future<Map<String, dynamic>> testEmail() => (super.noSuchMethod(
Invocation.method(
#testEmail,
[],
),
returnValue:
_i6.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
) as _i6.Future<Map<String, dynamic>>);
@override
_i6.Future<_i2.SystemConfigModel> resetConfig() => (super.noSuchMethod(
Invocation.method(
#resetConfig,
[],
),
returnValue:
_i6.Future<_i2.SystemConfigModel>.value(_FakeSystemConfigModel_0(
this,
Invocation.method(
#resetConfig,
[],
),
)),
) as _i6.Future<_i2.SystemConfigModel>);
}

View File

@@ -0,0 +1,94 @@
/// 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);
});
});
}

View File

@@ -0,0 +1,184 @@
// Mocks generated by Mockito 5.4.4 from annotations
// in unionflow_mobile_apps/test/features/settings/domain/usecases/get_settings_test.dart.
// Do not manually edit this file.
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i6;
import 'package:mockito/mockito.dart' as _i1;
import 'package:unionflow_mobile_apps/features/settings/data/models/cache_stats_model.dart'
as _i3;
import 'package:unionflow_mobile_apps/features/settings/data/models/system_config_model.dart'
as _i2;
import 'package:unionflow_mobile_apps/features/settings/data/models/system_metrics_model.dart'
as _i4;
import 'package:unionflow_mobile_apps/features/settings/domain/repositories/system_config_repository.dart'
as _i5;
// ignore_for_file: type=lint
// ignore_for_file: avoid_redundant_argument_values
// ignore_for_file: avoid_setters_without_getters
// ignore_for_file: comment_references
// ignore_for_file: deprecated_member_use
// ignore_for_file: deprecated_member_use_from_same_package
// ignore_for_file: implementation_imports
// ignore_for_file: invalid_use_of_visible_for_testing_member
// ignore_for_file: prefer_const_constructors
// ignore_for_file: unnecessary_parenthesis
// ignore_for_file: camel_case_types
// ignore_for_file: subtype_of_sealed_class
class _FakeSystemConfigModel_0 extends _i1.SmartFake
implements _i2.SystemConfigModel {
_FakeSystemConfigModel_0(
Object parent,
Invocation parentInvocation,
) : super(
parent,
parentInvocation,
);
}
class _FakeCacheStatsModel_1 extends _i1.SmartFake
implements _i3.CacheStatsModel {
_FakeCacheStatsModel_1(
Object parent,
Invocation parentInvocation,
) : super(
parent,
parentInvocation,
);
}
class _FakeSystemMetricsModel_2 extends _i1.SmartFake
implements _i4.SystemMetricsModel {
_FakeSystemMetricsModel_2(
Object parent,
Invocation parentInvocation,
) : super(
parent,
parentInvocation,
);
}
/// A class which mocks [ISystemConfigRepository].
///
/// See the documentation for Mockito's code generation for more information.
class MockISystemConfigRepository extends _i1.Mock
implements _i5.ISystemConfigRepository {
MockISystemConfigRepository() {
_i1.throwOnMissingStub(this);
}
@override
_i6.Future<_i2.SystemConfigModel> getConfig() => (super.noSuchMethod(
Invocation.method(
#getConfig,
[],
),
returnValue:
_i6.Future<_i2.SystemConfigModel>.value(_FakeSystemConfigModel_0(
this,
Invocation.method(
#getConfig,
[],
),
)),
) as _i6.Future<_i2.SystemConfigModel>);
@override
_i6.Future<_i2.SystemConfigModel> updateConfig(
Map<String, dynamic>? config) =>
(super.noSuchMethod(
Invocation.method(
#updateConfig,
[config],
),
returnValue:
_i6.Future<_i2.SystemConfigModel>.value(_FakeSystemConfigModel_0(
this,
Invocation.method(
#updateConfig,
[config],
),
)),
) as _i6.Future<_i2.SystemConfigModel>);
@override
_i6.Future<_i3.CacheStatsModel> getCacheStats() => (super.noSuchMethod(
Invocation.method(
#getCacheStats,
[],
),
returnValue:
_i6.Future<_i3.CacheStatsModel>.value(_FakeCacheStatsModel_1(
this,
Invocation.method(
#getCacheStats,
[],
),
)),
) as _i6.Future<_i3.CacheStatsModel>);
@override
_i6.Future<_i4.SystemMetricsModel> getMetrics() => (super.noSuchMethod(
Invocation.method(
#getMetrics,
[],
),
returnValue:
_i6.Future<_i4.SystemMetricsModel>.value(_FakeSystemMetricsModel_2(
this,
Invocation.method(
#getMetrics,
[],
),
)),
) as _i6.Future<_i4.SystemMetricsModel>);
@override
_i6.Future<void> clearCache() => (super.noSuchMethod(
Invocation.method(
#clearCache,
[],
),
returnValue: _i6.Future<void>.value(),
returnValueForMissingStub: _i6.Future<void>.value(),
) as _i6.Future<void>);
@override
_i6.Future<Map<String, dynamic>> testDatabase() => (super.noSuchMethod(
Invocation.method(
#testDatabase,
[],
),
returnValue:
_i6.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
) as _i6.Future<Map<String, dynamic>>);
@override
_i6.Future<Map<String, dynamic>> testEmail() => (super.noSuchMethod(
Invocation.method(
#testEmail,
[],
),
returnValue:
_i6.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
) as _i6.Future<Map<String, dynamic>>);
@override
_i6.Future<_i2.SystemConfigModel> resetConfig() => (super.noSuchMethod(
Invocation.method(
#resetConfig,
[],
),
returnValue:
_i6.Future<_i2.SystemConfigModel>.value(_FakeSystemConfigModel_0(
this,
Invocation.method(
#resetConfig,
[],
),
)),
) as _i6.Future<_i2.SystemConfigModel>);
}

View File

@@ -0,0 +1,92 @@
/// Tests unitaires pour ResetSettings use case
library reset_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/reset_settings.dart';
import 'package:unionflow_mobile_apps/features/settings/data/models/system_config_model.dart';
@GenerateMocks([ISystemConfigRepository])
import 'reset_settings_test.mocks.dart';
void main() {
late ResetSettings useCase;
late MockISystemConfigRepository mockRepository;
setUp(() {
mockRepository = MockISystemConfigRepository();
useCase = ResetSettings(mockRepository);
});
group('ResetSettings Use Case', () {
final tDefaultConfig = SystemConfigModel(
applicationName: 'UnionFlow',
version: '1.0.0',
maintenanceMode: false,
defaultLanguage: 'fr',
timezone: 'Europe/Paris',
);
test('should reset configuration to default values', () async {
// Arrange
when(mockRepository.resetConfig()).thenAnswer((_) async => tDefaultConfig);
// Act
final result = await useCase();
// Assert
expect(result, equals(tDefaultConfig));
expect(result.maintenanceMode, isFalse);
expect(result.applicationName, equals('UnionFlow'));
expect(result.version, equals('1.0.0'));
verify(mockRepository.resetConfig());
verifyNoMoreInteractions(mockRepository);
});
test('should handle fallback when reset endpoint fails', () async {
// Arrange
when(mockRepository.resetConfig()).thenAnswer((_) async => tDefaultConfig);
// Act
final result = await useCase();
// Assert
expect(result, isNotNull);
expect(result.applicationName, equals('UnionFlow'));
verify(mockRepository.resetConfig());
});
test('should throw exception when all reset strategies fail', () async {
// Arrange
when(mockRepository.resetConfig()).thenThrow(Exception('Reset failed'));
// Act & Assert
expect(
() => useCase(),
throwsA(isA<Exception>()),
);
verify(mockRepository.resetConfig());
});
test('should return valid config with minimal required fields', () async {
// Arrange
final tMinimalConfig = SystemConfigModel(
applicationName: 'UnionFlow',
version: '1.0.0',
maintenanceMode: false,
);
when(mockRepository.resetConfig()).thenAnswer((_) async => tMinimalConfig);
// Act
final result = await useCase();
// Assert
expect(result.applicationName, isNotNull);
expect(result.version, isNotNull);
expect(result.maintenanceMode, isNotNull);
verify(mockRepository.resetConfig());
});
});
}

View File

@@ -0,0 +1,184 @@
// Mocks generated by Mockito 5.4.4 from annotations
// in unionflow_mobile_apps/test/features/settings/domain/usecases/reset_settings_test.dart.
// Do not manually edit this file.
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i6;
import 'package:mockito/mockito.dart' as _i1;
import 'package:unionflow_mobile_apps/features/settings/data/models/cache_stats_model.dart'
as _i3;
import 'package:unionflow_mobile_apps/features/settings/data/models/system_config_model.dart'
as _i2;
import 'package:unionflow_mobile_apps/features/settings/data/models/system_metrics_model.dart'
as _i4;
import 'package:unionflow_mobile_apps/features/settings/domain/repositories/system_config_repository.dart'
as _i5;
// ignore_for_file: type=lint
// ignore_for_file: avoid_redundant_argument_values
// ignore_for_file: avoid_setters_without_getters
// ignore_for_file: comment_references
// ignore_for_file: deprecated_member_use
// ignore_for_file: deprecated_member_use_from_same_package
// ignore_for_file: implementation_imports
// ignore_for_file: invalid_use_of_visible_for_testing_member
// ignore_for_file: prefer_const_constructors
// ignore_for_file: unnecessary_parenthesis
// ignore_for_file: camel_case_types
// ignore_for_file: subtype_of_sealed_class
class _FakeSystemConfigModel_0 extends _i1.SmartFake
implements _i2.SystemConfigModel {
_FakeSystemConfigModel_0(
Object parent,
Invocation parentInvocation,
) : super(
parent,
parentInvocation,
);
}
class _FakeCacheStatsModel_1 extends _i1.SmartFake
implements _i3.CacheStatsModel {
_FakeCacheStatsModel_1(
Object parent,
Invocation parentInvocation,
) : super(
parent,
parentInvocation,
);
}
class _FakeSystemMetricsModel_2 extends _i1.SmartFake
implements _i4.SystemMetricsModel {
_FakeSystemMetricsModel_2(
Object parent,
Invocation parentInvocation,
) : super(
parent,
parentInvocation,
);
}
/// A class which mocks [ISystemConfigRepository].
///
/// See the documentation for Mockito's code generation for more information.
class MockISystemConfigRepository extends _i1.Mock
implements _i5.ISystemConfigRepository {
MockISystemConfigRepository() {
_i1.throwOnMissingStub(this);
}
@override
_i6.Future<_i2.SystemConfigModel> getConfig() => (super.noSuchMethod(
Invocation.method(
#getConfig,
[],
),
returnValue:
_i6.Future<_i2.SystemConfigModel>.value(_FakeSystemConfigModel_0(
this,
Invocation.method(
#getConfig,
[],
),
)),
) as _i6.Future<_i2.SystemConfigModel>);
@override
_i6.Future<_i2.SystemConfigModel> updateConfig(
Map<String, dynamic>? config) =>
(super.noSuchMethod(
Invocation.method(
#updateConfig,
[config],
),
returnValue:
_i6.Future<_i2.SystemConfigModel>.value(_FakeSystemConfigModel_0(
this,
Invocation.method(
#updateConfig,
[config],
),
)),
) as _i6.Future<_i2.SystemConfigModel>);
@override
_i6.Future<_i3.CacheStatsModel> getCacheStats() => (super.noSuchMethod(
Invocation.method(
#getCacheStats,
[],
),
returnValue:
_i6.Future<_i3.CacheStatsModel>.value(_FakeCacheStatsModel_1(
this,
Invocation.method(
#getCacheStats,
[],
),
)),
) as _i6.Future<_i3.CacheStatsModel>);
@override
_i6.Future<_i4.SystemMetricsModel> getMetrics() => (super.noSuchMethod(
Invocation.method(
#getMetrics,
[],
),
returnValue:
_i6.Future<_i4.SystemMetricsModel>.value(_FakeSystemMetricsModel_2(
this,
Invocation.method(
#getMetrics,
[],
),
)),
) as _i6.Future<_i4.SystemMetricsModel>);
@override
_i6.Future<void> clearCache() => (super.noSuchMethod(
Invocation.method(
#clearCache,
[],
),
returnValue: _i6.Future<void>.value(),
returnValueForMissingStub: _i6.Future<void>.value(),
) as _i6.Future<void>);
@override
_i6.Future<Map<String, dynamic>> testDatabase() => (super.noSuchMethod(
Invocation.method(
#testDatabase,
[],
),
returnValue:
_i6.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
) as _i6.Future<Map<String, dynamic>>);
@override
_i6.Future<Map<String, dynamic>> testEmail() => (super.noSuchMethod(
Invocation.method(
#testEmail,
[],
),
returnValue:
_i6.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
) as _i6.Future<Map<String, dynamic>>);
@override
_i6.Future<_i2.SystemConfigModel> resetConfig() => (super.noSuchMethod(
Invocation.method(
#resetConfig,
[],
),
returnValue:
_i6.Future<_i2.SystemConfigModel>.value(_FakeSystemConfigModel_0(
this,
Invocation.method(
#resetConfig,
[],
),
)),
) as _i6.Future<_i2.SystemConfigModel>);
}

View File

@@ -0,0 +1,91 @@
/// Tests unitaires pour UpdateSettings use case
library update_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/update_settings.dart';
import 'package:unionflow_mobile_apps/features/settings/data/models/system_config_model.dart';
@GenerateMocks([ISystemConfigRepository])
import 'update_settings_test.mocks.dart';
void main() {
late UpdateSettings useCase;
late MockISystemConfigRepository mockRepository;
setUp(() {
mockRepository = MockISystemConfigRepository();
useCase = UpdateSettings(mockRepository);
});
group('UpdateSettings Use Case', () {
final tConfigMap = {
'applicationName': 'UnionFlow Updated',
'maintenanceMode': true,
'sessionTimeoutMinutes': 45,
};
final tUpdatedConfig = SystemConfigModel(
applicationName: 'UnionFlow Updated',
maintenanceMode: true,
sessionTimeoutMinutes: 45,
);
test('should update configuration successfully', () async {
// Arrange
when(mockRepository.updateConfig(tConfigMap))
.thenAnswer((_) async => tUpdatedConfig);
// Act
final result = await useCase(tConfigMap);
// Assert
expect(result, equals(tUpdatedConfig));
expect(result.applicationName, equals('UnionFlow Updated'));
expect(result.maintenanceMode, isTrue);
verify(mockRepository.updateConfig(tConfigMap));
verifyNoMoreInteractions(mockRepository);
});
test('should update partial configuration', () async {
// Arrange
final partialConfig = {'maintenanceMode': false};
final expectedResult = SystemConfigModel(maintenanceMode: false);
when(mockRepository.updateConfig(partialConfig))
.thenAnswer((_) async => expectedResult);
// Act
final result = await useCase(partialConfig);
// Assert
expect(result.maintenanceMode, isFalse);
verify(mockRepository.updateConfig(partialConfig));
});
test('should handle empty config map', () async {
// Arrange
final emptyConfig = <String, dynamic>{};
final expectedResult = SystemConfigModel();
when(mockRepository.updateConfig(emptyConfig))
.thenAnswer((_) async => expectedResult);
// Act
final result = await useCase(emptyConfig);
// Assert
expect(result, isNotNull);
verify(mockRepository.updateConfig(emptyConfig));
});
test('should throw exception when update fails', () async {
// Arrange
when(mockRepository.updateConfig(any))
.thenThrow(Exception('Update failed'));
// Act & Assert
expect(() => useCase(tConfigMap), throwsException);
});
});
}

View File

@@ -0,0 +1,184 @@
// Mocks generated by Mockito 5.4.4 from annotations
// in unionflow_mobile_apps/test/features/settings/domain/usecases/update_settings_test.dart.
// Do not manually edit this file.
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i6;
import 'package:mockito/mockito.dart' as _i1;
import 'package:unionflow_mobile_apps/features/settings/data/models/cache_stats_model.dart'
as _i3;
import 'package:unionflow_mobile_apps/features/settings/data/models/system_config_model.dart'
as _i2;
import 'package:unionflow_mobile_apps/features/settings/data/models/system_metrics_model.dart'
as _i4;
import 'package:unionflow_mobile_apps/features/settings/domain/repositories/system_config_repository.dart'
as _i5;
// ignore_for_file: type=lint
// ignore_for_file: avoid_redundant_argument_values
// ignore_for_file: avoid_setters_without_getters
// ignore_for_file: comment_references
// ignore_for_file: deprecated_member_use
// ignore_for_file: deprecated_member_use_from_same_package
// ignore_for_file: implementation_imports
// ignore_for_file: invalid_use_of_visible_for_testing_member
// ignore_for_file: prefer_const_constructors
// ignore_for_file: unnecessary_parenthesis
// ignore_for_file: camel_case_types
// ignore_for_file: subtype_of_sealed_class
class _FakeSystemConfigModel_0 extends _i1.SmartFake
implements _i2.SystemConfigModel {
_FakeSystemConfigModel_0(
Object parent,
Invocation parentInvocation,
) : super(
parent,
parentInvocation,
);
}
class _FakeCacheStatsModel_1 extends _i1.SmartFake
implements _i3.CacheStatsModel {
_FakeCacheStatsModel_1(
Object parent,
Invocation parentInvocation,
) : super(
parent,
parentInvocation,
);
}
class _FakeSystemMetricsModel_2 extends _i1.SmartFake
implements _i4.SystemMetricsModel {
_FakeSystemMetricsModel_2(
Object parent,
Invocation parentInvocation,
) : super(
parent,
parentInvocation,
);
}
/// A class which mocks [ISystemConfigRepository].
///
/// See the documentation for Mockito's code generation for more information.
class MockISystemConfigRepository extends _i1.Mock
implements _i5.ISystemConfigRepository {
MockISystemConfigRepository() {
_i1.throwOnMissingStub(this);
}
@override
_i6.Future<_i2.SystemConfigModel> getConfig() => (super.noSuchMethod(
Invocation.method(
#getConfig,
[],
),
returnValue:
_i6.Future<_i2.SystemConfigModel>.value(_FakeSystemConfigModel_0(
this,
Invocation.method(
#getConfig,
[],
),
)),
) as _i6.Future<_i2.SystemConfigModel>);
@override
_i6.Future<_i2.SystemConfigModel> updateConfig(
Map<String, dynamic>? config) =>
(super.noSuchMethod(
Invocation.method(
#updateConfig,
[config],
),
returnValue:
_i6.Future<_i2.SystemConfigModel>.value(_FakeSystemConfigModel_0(
this,
Invocation.method(
#updateConfig,
[config],
),
)),
) as _i6.Future<_i2.SystemConfigModel>);
@override
_i6.Future<_i3.CacheStatsModel> getCacheStats() => (super.noSuchMethod(
Invocation.method(
#getCacheStats,
[],
),
returnValue:
_i6.Future<_i3.CacheStatsModel>.value(_FakeCacheStatsModel_1(
this,
Invocation.method(
#getCacheStats,
[],
),
)),
) as _i6.Future<_i3.CacheStatsModel>);
@override
_i6.Future<_i4.SystemMetricsModel> getMetrics() => (super.noSuchMethod(
Invocation.method(
#getMetrics,
[],
),
returnValue:
_i6.Future<_i4.SystemMetricsModel>.value(_FakeSystemMetricsModel_2(
this,
Invocation.method(
#getMetrics,
[],
),
)),
) as _i6.Future<_i4.SystemMetricsModel>);
@override
_i6.Future<void> clearCache() => (super.noSuchMethod(
Invocation.method(
#clearCache,
[],
),
returnValue: _i6.Future<void>.value(),
returnValueForMissingStub: _i6.Future<void>.value(),
) as _i6.Future<void>);
@override
_i6.Future<Map<String, dynamic>> testDatabase() => (super.noSuchMethod(
Invocation.method(
#testDatabase,
[],
),
returnValue:
_i6.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
) as _i6.Future<Map<String, dynamic>>);
@override
_i6.Future<Map<String, dynamic>> testEmail() => (super.noSuchMethod(
Invocation.method(
#testEmail,
[],
),
returnValue:
_i6.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
) as _i6.Future<Map<String, dynamic>>);
@override
_i6.Future<_i2.SystemConfigModel> resetConfig() => (super.noSuchMethod(
Invocation.method(
#resetConfig,
[],
),
returnValue:
_i6.Future<_i2.SystemConfigModel>.value(_FakeSystemConfigModel_0(
this,
Invocation.method(
#resetConfig,
[],
),
)),
) as _i6.Future<_i2.SystemConfigModel>);
}