Initial commit: unionflow-mobile-apps
Application Flutter complète (sans build artifacts). Signed-off-by: lions dev Team
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
/// Tests unitaires pour ChangePassword use case
|
||||
library change_password_test;
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:unionflow_mobile_apps/features/profile/domain/repositories/profile_repository.dart';
|
||||
import 'package:unionflow_mobile_apps/features/profile/domain/usecases/change_password.dart';
|
||||
|
||||
@GenerateMocks([IProfileRepository])
|
||||
import 'change_password_test.mocks.dart';
|
||||
|
||||
void main() {
|
||||
late ChangePassword useCase;
|
||||
late MockIProfileRepository mockRepository;
|
||||
|
||||
setUp(() {
|
||||
mockRepository = MockIProfileRepository();
|
||||
useCase = ChangePassword(mockRepository);
|
||||
});
|
||||
|
||||
group('ChangePassword Use Case', () {
|
||||
const tMembreId = 'membre1';
|
||||
const tOldPassword = 'OldPassword123!';
|
||||
const tNewPassword = 'NewPassword456!';
|
||||
|
||||
test('should change password successfully', () async {
|
||||
// Arrange
|
||||
when(mockRepository.changePassword(tMembreId, tOldPassword, tNewPassword))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
// Act
|
||||
await useCase(tMembreId, tOldPassword, tNewPassword);
|
||||
|
||||
// Assert
|
||||
verify(mockRepository.changePassword(tMembreId, tOldPassword, tNewPassword));
|
||||
verifyNoMoreInteractions(mockRepository);
|
||||
});
|
||||
|
||||
test('should throw exception when old password is incorrect', () async {
|
||||
// Arrange
|
||||
when(mockRepository.changePassword(any, any, any))
|
||||
.thenThrow(Exception('Mot de passe incorrect'));
|
||||
|
||||
// Act & Assert
|
||||
expect(
|
||||
() => useCase(tMembreId, 'WrongPassword', tNewPassword),
|
||||
throwsA(isA<Exception>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('should throw exception when new password is too weak', () async {
|
||||
// Arrange
|
||||
when(mockRepository.changePassword(any, any, any))
|
||||
.thenThrow(Exception('Mot de passe trop faible'));
|
||||
|
||||
// Act & Assert
|
||||
expect(
|
||||
() => useCase(tMembreId, tOldPassword, 'weak'),
|
||||
throwsA(isA<Exception>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('should throw exception when Keycloak service fails', () async {
|
||||
// Arrange
|
||||
when(mockRepository.changePassword(any, any, any))
|
||||
.thenThrow(Exception('Keycloak service unavailable'));
|
||||
|
||||
// Act & Assert
|
||||
expect(
|
||||
() => useCase(tMembreId, tOldPassword, tNewPassword),
|
||||
throwsException,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
// Mocks generated by Mockito 5.4.4 from annotations
|
||||
// in unionflow_mobile_apps/test/features/profile/domain/usecases/change_password_test.dart.
|
||||
// Do not manually edit this file.
|
||||
|
||||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||
import 'dart:async' as _i4;
|
||||
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:unionflow_mobile_apps/features/members/data/models/membre_complete_model.dart'
|
||||
as _i2;
|
||||
import 'package:unionflow_mobile_apps/features/profile/domain/repositories/profile_repository.dart'
|
||||
as _i3;
|
||||
|
||||
// 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 _FakeMembreCompletModel_0 extends _i1.SmartFake
|
||||
implements _i2.MembreCompletModel {
|
||||
_FakeMembreCompletModel_0(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
/// A class which mocks [IProfileRepository].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockIProfileRepository extends _i1.Mock
|
||||
implements _i3.IProfileRepository {
|
||||
MockIProfileRepository() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.MembreCompletModel?> getMe() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getMe,
|
||||
[],
|
||||
),
|
||||
returnValue: _i4.Future<_i2.MembreCompletModel?>.value(),
|
||||
) as _i4.Future<_i2.MembreCompletModel?>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.MembreCompletModel?> getProfileByEmail(String? email) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getProfileByEmail,
|
||||
[email],
|
||||
),
|
||||
returnValue: _i4.Future<_i2.MembreCompletModel?>.value(),
|
||||
) as _i4.Future<_i2.MembreCompletModel?>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.MembreCompletModel> updateProfile(
|
||||
String? id,
|
||||
_i2.MembreCompletModel? membre,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#updateProfile,
|
||||
[
|
||||
id,
|
||||
membre,
|
||||
],
|
||||
),
|
||||
returnValue:
|
||||
_i4.Future<_i2.MembreCompletModel>.value(_FakeMembreCompletModel_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#updateProfile,
|
||||
[
|
||||
id,
|
||||
membre,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.MembreCompletModel>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.MembreCompletModel> updateAvatar(
|
||||
String? id,
|
||||
String? photoUrl,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#updateAvatar,
|
||||
[
|
||||
id,
|
||||
photoUrl,
|
||||
],
|
||||
),
|
||||
returnValue:
|
||||
_i4.Future<_i2.MembreCompletModel>.value(_FakeMembreCompletModel_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#updateAvatar,
|
||||
[
|
||||
id,
|
||||
photoUrl,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.MembreCompletModel>);
|
||||
|
||||
@override
|
||||
_i4.Future<void> changePassword(
|
||||
String? id,
|
||||
String? oldPassword,
|
||||
String? newPassword,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#changePassword,
|
||||
[
|
||||
id,
|
||||
oldPassword,
|
||||
newPassword,
|
||||
],
|
||||
),
|
||||
returnValue: _i4.Future<void>.value(),
|
||||
returnValueForMissingStub: _i4.Future<void>.value(),
|
||||
) as _i4.Future<void>);
|
||||
|
||||
@override
|
||||
_i4.Future<Map<String, dynamic>> updatePreferences(
|
||||
String? id,
|
||||
Map<String, dynamic>? preferences,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#updatePreferences,
|
||||
[
|
||||
id,
|
||||
preferences,
|
||||
],
|
||||
),
|
||||
returnValue:
|
||||
_i4.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
) as _i4.Future<Map<String, dynamic>>);
|
||||
|
||||
@override
|
||||
_i4.Future<void> deleteAccount(String? id) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteAccount,
|
||||
[id],
|
||||
),
|
||||
returnValue: _i4.Future<void>.value(),
|
||||
returnValueForMissingStub: _i4.Future<void>.value(),
|
||||
) as _i4.Future<void>);
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
/// Tests unitaires pour DeleteAccount use case
|
||||
library delete_account_test;
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:unionflow_mobile_apps/features/profile/domain/repositories/profile_repository.dart';
|
||||
import 'package:unionflow_mobile_apps/features/profile/domain/usecases/delete_account.dart';
|
||||
|
||||
@GenerateMocks([IProfileRepository])
|
||||
import 'delete_account_test.mocks.dart';
|
||||
|
||||
void main() {
|
||||
late DeleteAccount useCase;
|
||||
late MockIProfileRepository mockRepository;
|
||||
|
||||
setUp(() {
|
||||
mockRepository = MockIProfileRepository();
|
||||
useCase = DeleteAccount(mockRepository);
|
||||
});
|
||||
|
||||
group('DeleteAccount Use Case', () {
|
||||
const tMembreId = 'membre1';
|
||||
|
||||
test('should delete account successfully (soft delete)', () async {
|
||||
// Arrange
|
||||
when(mockRepository.deleteAccount(tMembreId))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
// Act
|
||||
await useCase(tMembreId);
|
||||
|
||||
// Assert
|
||||
verify(mockRepository.deleteAccount(tMembreId));
|
||||
verifyNoMoreInteractions(mockRepository);
|
||||
});
|
||||
|
||||
test('should throw exception when account not found', () async {
|
||||
// Arrange
|
||||
when(mockRepository.deleteAccount(any))
|
||||
.thenThrow(Exception('Compte non trouvé'));
|
||||
|
||||
// Act & Assert
|
||||
expect(
|
||||
() => useCase(tMembreId),
|
||||
throwsA(isA<Exception>()),
|
||||
);
|
||||
verify(mockRepository.deleteAccount(tMembreId));
|
||||
});
|
||||
|
||||
test('should throw exception when account is already deleted', () async {
|
||||
// Arrange
|
||||
when(mockRepository.deleteAccount(any))
|
||||
.thenThrow(Exception('Compte déjà désactivé'));
|
||||
|
||||
// Act & Assert
|
||||
expect(
|
||||
() => useCase(tMembreId),
|
||||
throwsA(isA<Exception>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('should throw exception when deletion fails', () async {
|
||||
// Arrange
|
||||
when(mockRepository.deleteAccount(any))
|
||||
.thenThrow(Exception('Deletion failed'));
|
||||
|
||||
// Act & Assert
|
||||
expect(
|
||||
() => useCase(tMembreId),
|
||||
throwsException,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
// Mocks generated by Mockito 5.4.4 from annotations
|
||||
// in unionflow_mobile_apps/test/features/profile/domain/usecases/delete_account_test.dart.
|
||||
// Do not manually edit this file.
|
||||
|
||||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||
import 'dart:async' as _i4;
|
||||
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:unionflow_mobile_apps/features/members/data/models/membre_complete_model.dart'
|
||||
as _i2;
|
||||
import 'package:unionflow_mobile_apps/features/profile/domain/repositories/profile_repository.dart'
|
||||
as _i3;
|
||||
|
||||
// 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 _FakeMembreCompletModel_0 extends _i1.SmartFake
|
||||
implements _i2.MembreCompletModel {
|
||||
_FakeMembreCompletModel_0(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
/// A class which mocks [IProfileRepository].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockIProfileRepository extends _i1.Mock
|
||||
implements _i3.IProfileRepository {
|
||||
MockIProfileRepository() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.MembreCompletModel?> getMe() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getMe,
|
||||
[],
|
||||
),
|
||||
returnValue: _i4.Future<_i2.MembreCompletModel?>.value(),
|
||||
) as _i4.Future<_i2.MembreCompletModel?>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.MembreCompletModel?> getProfileByEmail(String? email) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getProfileByEmail,
|
||||
[email],
|
||||
),
|
||||
returnValue: _i4.Future<_i2.MembreCompletModel?>.value(),
|
||||
) as _i4.Future<_i2.MembreCompletModel?>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.MembreCompletModel> updateProfile(
|
||||
String? id,
|
||||
_i2.MembreCompletModel? membre,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#updateProfile,
|
||||
[
|
||||
id,
|
||||
membre,
|
||||
],
|
||||
),
|
||||
returnValue:
|
||||
_i4.Future<_i2.MembreCompletModel>.value(_FakeMembreCompletModel_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#updateProfile,
|
||||
[
|
||||
id,
|
||||
membre,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.MembreCompletModel>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.MembreCompletModel> updateAvatar(
|
||||
String? id,
|
||||
String? photoUrl,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#updateAvatar,
|
||||
[
|
||||
id,
|
||||
photoUrl,
|
||||
],
|
||||
),
|
||||
returnValue:
|
||||
_i4.Future<_i2.MembreCompletModel>.value(_FakeMembreCompletModel_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#updateAvatar,
|
||||
[
|
||||
id,
|
||||
photoUrl,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.MembreCompletModel>);
|
||||
|
||||
@override
|
||||
_i4.Future<void> changePassword(
|
||||
String? id,
|
||||
String? oldPassword,
|
||||
String? newPassword,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#changePassword,
|
||||
[
|
||||
id,
|
||||
oldPassword,
|
||||
newPassword,
|
||||
],
|
||||
),
|
||||
returnValue: _i4.Future<void>.value(),
|
||||
returnValueForMissingStub: _i4.Future<void>.value(),
|
||||
) as _i4.Future<void>);
|
||||
|
||||
@override
|
||||
_i4.Future<Map<String, dynamic>> updatePreferences(
|
||||
String? id,
|
||||
Map<String, dynamic>? preferences,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#updatePreferences,
|
||||
[
|
||||
id,
|
||||
preferences,
|
||||
],
|
||||
),
|
||||
returnValue:
|
||||
_i4.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
) as _i4.Future<Map<String, dynamic>>);
|
||||
|
||||
@override
|
||||
_i4.Future<void> deleteAccount(String? id) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteAccount,
|
||||
[id],
|
||||
),
|
||||
returnValue: _i4.Future<void>.value(),
|
||||
returnValueForMissingStub: _i4.Future<void>.value(),
|
||||
) as _i4.Future<void>);
|
||||
}
|
||||
84
test/features/profile/domain/usecases/get_profile_test.dart
Normal file
84
test/features/profile/domain/usecases/get_profile_test.dart
Normal file
@@ -0,0 +1,84 @@
|
||||
/// Tests unitaires pour GetProfile use case
|
||||
library get_profile_test;
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:unionflow_mobile_apps/features/profile/domain/repositories/profile_repository.dart';
|
||||
import 'package:unionflow_mobile_apps/features/profile/domain/usecases/get_profile.dart';
|
||||
import 'package:unionflow_mobile_apps/features/members/data/models/membre_complete_model.dart';
|
||||
|
||||
@GenerateMocks([IProfileRepository])
|
||||
import 'get_profile_test.mocks.dart';
|
||||
|
||||
void main() {
|
||||
late GetProfile useCase;
|
||||
late MockIProfileRepository mockRepository;
|
||||
|
||||
setUp(() {
|
||||
mockRepository = MockIProfileRepository();
|
||||
useCase = GetProfile(mockRepository);
|
||||
});
|
||||
|
||||
group('GetProfile Use Case', () {
|
||||
final tMembre = MembreCompletModel(
|
||||
id: 'membre1',
|
||||
nom: 'Dupont',
|
||||
prenom: 'Jean',
|
||||
email: 'jean.dupont@example.com',
|
||||
telephone: '+33612345678',
|
||||
dateNaissance: DateTime(1990, 1, 1),
|
||||
);
|
||||
|
||||
test('should return current user profile from repository', () async {
|
||||
// Arrange
|
||||
when(mockRepository.getMe()).thenAnswer((_) async => tMembre);
|
||||
|
||||
// Act
|
||||
final result = await useCase();
|
||||
|
||||
// Assert
|
||||
expect(result, equals(tMembre));
|
||||
verify(mockRepository.getMe());
|
||||
verifyNoMoreInteractions(mockRepository);
|
||||
});
|
||||
|
||||
test('should return null when user is not authenticated', () async {
|
||||
// Arrange
|
||||
when(mockRepository.getMe()).thenAnswer((_) async => null);
|
||||
|
||||
// Act
|
||||
final result = await useCase();
|
||||
|
||||
// Assert
|
||||
expect(result, isNull);
|
||||
verify(mockRepository.getMe());
|
||||
});
|
||||
|
||||
test('should throw exception when repository throws', () async {
|
||||
// Arrange
|
||||
when(mockRepository.getMe()).thenThrow(Exception('Unauthorized'));
|
||||
|
||||
// Act & Assert
|
||||
expect(
|
||||
() => useCase(),
|
||||
throwsA(isA<Exception>()),
|
||||
);
|
||||
verify(mockRepository.getMe());
|
||||
});
|
||||
|
||||
test('should cache profile data on successful retrieval', () async {
|
||||
// Arrange
|
||||
when(mockRepository.getMe()).thenAnswer((_) async => tMembre);
|
||||
|
||||
// Act - Call twice
|
||||
final result1 = await useCase();
|
||||
final result2 = await useCase();
|
||||
|
||||
// Assert - Repository called twice (no caching at use case level)
|
||||
expect(result1, equals(tMembre));
|
||||
expect(result2, equals(tMembre));
|
||||
verify(mockRepository.getMe()).called(2);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
// Mocks generated by Mockito 5.4.4 from annotations
|
||||
// in unionflow_mobile_apps/test/features/profile/domain/usecases/get_profile_test.dart.
|
||||
// Do not manually edit this file.
|
||||
|
||||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||
import 'dart:async' as _i4;
|
||||
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:unionflow_mobile_apps/features/members/data/models/membre_complete_model.dart'
|
||||
as _i2;
|
||||
import 'package:unionflow_mobile_apps/features/profile/domain/repositories/profile_repository.dart'
|
||||
as _i3;
|
||||
|
||||
// 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 _FakeMembreCompletModel_0 extends _i1.SmartFake
|
||||
implements _i2.MembreCompletModel {
|
||||
_FakeMembreCompletModel_0(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
/// A class which mocks [IProfileRepository].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockIProfileRepository extends _i1.Mock
|
||||
implements _i3.IProfileRepository {
|
||||
MockIProfileRepository() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.MembreCompletModel?> getMe() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getMe,
|
||||
[],
|
||||
),
|
||||
returnValue: _i4.Future<_i2.MembreCompletModel?>.value(),
|
||||
) as _i4.Future<_i2.MembreCompletModel?>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.MembreCompletModel?> getProfileByEmail(String? email) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getProfileByEmail,
|
||||
[email],
|
||||
),
|
||||
returnValue: _i4.Future<_i2.MembreCompletModel?>.value(),
|
||||
) as _i4.Future<_i2.MembreCompletModel?>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.MembreCompletModel> updateProfile(
|
||||
String? id,
|
||||
_i2.MembreCompletModel? membre,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#updateProfile,
|
||||
[
|
||||
id,
|
||||
membre,
|
||||
],
|
||||
),
|
||||
returnValue:
|
||||
_i4.Future<_i2.MembreCompletModel>.value(_FakeMembreCompletModel_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#updateProfile,
|
||||
[
|
||||
id,
|
||||
membre,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.MembreCompletModel>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.MembreCompletModel> updateAvatar(
|
||||
String? id,
|
||||
String? photoUrl,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#updateAvatar,
|
||||
[
|
||||
id,
|
||||
photoUrl,
|
||||
],
|
||||
),
|
||||
returnValue:
|
||||
_i4.Future<_i2.MembreCompletModel>.value(_FakeMembreCompletModel_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#updateAvatar,
|
||||
[
|
||||
id,
|
||||
photoUrl,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.MembreCompletModel>);
|
||||
|
||||
@override
|
||||
_i4.Future<void> changePassword(
|
||||
String? id,
|
||||
String? oldPassword,
|
||||
String? newPassword,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#changePassword,
|
||||
[
|
||||
id,
|
||||
oldPassword,
|
||||
newPassword,
|
||||
],
|
||||
),
|
||||
returnValue: _i4.Future<void>.value(),
|
||||
returnValueForMissingStub: _i4.Future<void>.value(),
|
||||
) as _i4.Future<void>);
|
||||
|
||||
@override
|
||||
_i4.Future<Map<String, dynamic>> updatePreferences(
|
||||
String? id,
|
||||
Map<String, dynamic>? preferences,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#updatePreferences,
|
||||
[
|
||||
id,
|
||||
preferences,
|
||||
],
|
||||
),
|
||||
returnValue:
|
||||
_i4.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
) as _i4.Future<Map<String, dynamic>>);
|
||||
|
||||
@override
|
||||
_i4.Future<void> deleteAccount(String? id) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteAccount,
|
||||
[id],
|
||||
),
|
||||
returnValue: _i4.Future<void>.value(),
|
||||
returnValueForMissingStub: _i4.Future<void>.value(),
|
||||
) as _i4.Future<void>);
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/// Tests unitaires pour UpdateAvatar use case
|
||||
library update_avatar_test;
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:unionflow_mobile_apps/features/profile/domain/repositories/profile_repository.dart';
|
||||
import 'package:unionflow_mobile_apps/features/profile/domain/usecases/update_avatar.dart';
|
||||
import 'package:unionflow_mobile_apps/features/members/data/models/membre_complete_model.dart';
|
||||
|
||||
@GenerateMocks([IProfileRepository])
|
||||
import 'update_avatar_test.mocks.dart';
|
||||
|
||||
void main() {
|
||||
late UpdateAvatar useCase;
|
||||
late MockIProfileRepository mockRepository;
|
||||
|
||||
setUp(() {
|
||||
mockRepository = MockIProfileRepository();
|
||||
useCase = UpdateAvatar(mockRepository);
|
||||
});
|
||||
|
||||
group('UpdateAvatar Use Case', () {
|
||||
const tMembreId = 'membre1';
|
||||
const tPhotoUrl = 'https://example.com/avatar.jpg';
|
||||
|
||||
final tUpdatedMembre = MembreCompletModel(
|
||||
id: tMembreId,
|
||||
nom: 'Dupont',
|
||||
prenom: 'Jean',
|
||||
email: 'jean.dupont@example.com',
|
||||
photo: tPhotoUrl,
|
||||
);
|
||||
|
||||
test('should update avatar successfully', () async {
|
||||
// Arrange
|
||||
when(mockRepository.updateAvatar(tMembreId, tPhotoUrl))
|
||||
.thenAnswer((_) async => tUpdatedMembre);
|
||||
|
||||
// Act
|
||||
final result = await useCase(tMembreId, tPhotoUrl);
|
||||
|
||||
// Assert
|
||||
expect(result, equals(tUpdatedMembre));
|
||||
expect(result.photo, equals(tPhotoUrl));
|
||||
verify(mockRepository.updateAvatar(tMembreId, tPhotoUrl));
|
||||
verifyNoMoreInteractions(mockRepository);
|
||||
});
|
||||
|
||||
test('should handle empty photo URL', () async {
|
||||
// Arrange
|
||||
const emptyUrl = '';
|
||||
final emptyPhotoMembre = MembreCompletModel(
|
||||
id: tMembreId,
|
||||
nom: 'Dupont',
|
||||
prenom: 'Jean',
|
||||
email: 'jean.dupont@example.com',
|
||||
photo: emptyUrl,
|
||||
);
|
||||
when(mockRepository.updateAvatar(tMembreId, emptyUrl))
|
||||
.thenAnswer((_) async => emptyPhotoMembre);
|
||||
|
||||
// Act
|
||||
final result = await useCase(tMembreId, emptyUrl);
|
||||
|
||||
// Assert
|
||||
expect(result.photo, equals(emptyUrl));
|
||||
verify(mockRepository.updateAvatar(tMembreId, emptyUrl));
|
||||
});
|
||||
|
||||
test('should throw exception when member not found', () async {
|
||||
// Arrange
|
||||
when(mockRepository.updateAvatar(any, any))
|
||||
.thenThrow(Exception('Membre non trouvé'));
|
||||
|
||||
// Act & Assert
|
||||
expect(
|
||||
() => useCase(tMembreId, tPhotoUrl),
|
||||
throwsA(isA<Exception>()),
|
||||
);
|
||||
});
|
||||
|
||||
test('should throw exception when upload fails', () async {
|
||||
// Arrange
|
||||
when(mockRepository.updateAvatar(any, any))
|
||||
.thenThrow(Exception('Upload failed'));
|
||||
|
||||
// Act & Assert
|
||||
expect(
|
||||
() => useCase(tMembreId, tPhotoUrl),
|
||||
throwsException,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
// Mocks generated by Mockito 5.4.4 from annotations
|
||||
// in unionflow_mobile_apps/test/features/profile/domain/usecases/update_avatar_test.dart.
|
||||
// Do not manually edit this file.
|
||||
|
||||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||
import 'dart:async' as _i4;
|
||||
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:unionflow_mobile_apps/features/members/data/models/membre_complete_model.dart'
|
||||
as _i2;
|
||||
import 'package:unionflow_mobile_apps/features/profile/domain/repositories/profile_repository.dart'
|
||||
as _i3;
|
||||
|
||||
// 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 _FakeMembreCompletModel_0 extends _i1.SmartFake
|
||||
implements _i2.MembreCompletModel {
|
||||
_FakeMembreCompletModel_0(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
/// A class which mocks [IProfileRepository].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockIProfileRepository extends _i1.Mock
|
||||
implements _i3.IProfileRepository {
|
||||
MockIProfileRepository() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.MembreCompletModel?> getMe() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getMe,
|
||||
[],
|
||||
),
|
||||
returnValue: _i4.Future<_i2.MembreCompletModel?>.value(),
|
||||
) as _i4.Future<_i2.MembreCompletModel?>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.MembreCompletModel?> getProfileByEmail(String? email) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getProfileByEmail,
|
||||
[email],
|
||||
),
|
||||
returnValue: _i4.Future<_i2.MembreCompletModel?>.value(),
|
||||
) as _i4.Future<_i2.MembreCompletModel?>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.MembreCompletModel> updateProfile(
|
||||
String? id,
|
||||
_i2.MembreCompletModel? membre,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#updateProfile,
|
||||
[
|
||||
id,
|
||||
membre,
|
||||
],
|
||||
),
|
||||
returnValue:
|
||||
_i4.Future<_i2.MembreCompletModel>.value(_FakeMembreCompletModel_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#updateProfile,
|
||||
[
|
||||
id,
|
||||
membre,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.MembreCompletModel>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.MembreCompletModel> updateAvatar(
|
||||
String? id,
|
||||
String? photoUrl,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#updateAvatar,
|
||||
[
|
||||
id,
|
||||
photoUrl,
|
||||
],
|
||||
),
|
||||
returnValue:
|
||||
_i4.Future<_i2.MembreCompletModel>.value(_FakeMembreCompletModel_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#updateAvatar,
|
||||
[
|
||||
id,
|
||||
photoUrl,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.MembreCompletModel>);
|
||||
|
||||
@override
|
||||
_i4.Future<void> changePassword(
|
||||
String? id,
|
||||
String? oldPassword,
|
||||
String? newPassword,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#changePassword,
|
||||
[
|
||||
id,
|
||||
oldPassword,
|
||||
newPassword,
|
||||
],
|
||||
),
|
||||
returnValue: _i4.Future<void>.value(),
|
||||
returnValueForMissingStub: _i4.Future<void>.value(),
|
||||
) as _i4.Future<void>);
|
||||
|
||||
@override
|
||||
_i4.Future<Map<String, dynamic>> updatePreferences(
|
||||
String? id,
|
||||
Map<String, dynamic>? preferences,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#updatePreferences,
|
||||
[
|
||||
id,
|
||||
preferences,
|
||||
],
|
||||
),
|
||||
returnValue:
|
||||
_i4.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
) as _i4.Future<Map<String, dynamic>>);
|
||||
|
||||
@override
|
||||
_i4.Future<void> deleteAccount(String? id) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteAccount,
|
||||
[id],
|
||||
),
|
||||
returnValue: _i4.Future<void>.value(),
|
||||
returnValueForMissingStub: _i4.Future<void>.value(),
|
||||
) as _i4.Future<void>);
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/// Tests unitaires pour UpdatePreferences use case
|
||||
library update_preferences_test;
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:unionflow_mobile_apps/features/profile/domain/repositories/profile_repository.dart';
|
||||
import 'package:unionflow_mobile_apps/features/profile/domain/usecases/update_preferences.dart';
|
||||
|
||||
@GenerateMocks([IProfileRepository])
|
||||
import 'update_preferences_test.mocks.dart';
|
||||
|
||||
void main() {
|
||||
late UpdatePreferences useCase;
|
||||
late MockIProfileRepository mockRepository;
|
||||
|
||||
setUp(() {
|
||||
mockRepository = MockIProfileRepository();
|
||||
useCase = UpdatePreferences(mockRepository);
|
||||
});
|
||||
|
||||
group('UpdatePreferences Use Case', () {
|
||||
const tMembreId = 'membre1';
|
||||
final tPreferences = {
|
||||
'language': 'fr',
|
||||
'theme': 'dark',
|
||||
'notifications': true,
|
||||
'emailNotifications': false,
|
||||
};
|
||||
|
||||
final tUpdatedPreferences = {
|
||||
...tPreferences,
|
||||
'lastUpdated': '2026-03-14T10:00:00Z',
|
||||
};
|
||||
|
||||
test('should update preferences successfully', () async {
|
||||
// Arrange
|
||||
when(mockRepository.updatePreferences(tMembreId, tPreferences))
|
||||
.thenAnswer((_) async => tUpdatedPreferences);
|
||||
|
||||
// Act
|
||||
final result = await useCase(tMembreId, tPreferences);
|
||||
|
||||
// Assert
|
||||
expect(result, equals(tUpdatedPreferences));
|
||||
expect(result['language'], equals('fr'));
|
||||
expect(result['theme'], equals('dark'));
|
||||
verify(mockRepository.updatePreferences(tMembreId, tPreferences));
|
||||
verifyNoMoreInteractions(mockRepository);
|
||||
});
|
||||
|
||||
test('should update partial preferences', () async {
|
||||
// Arrange
|
||||
final partialPrefs = {'theme': 'light'};
|
||||
final expectedResult = {'theme': 'light'};
|
||||
when(mockRepository.updatePreferences(tMembreId, partialPrefs))
|
||||
.thenAnswer((_) async => expectedResult);
|
||||
|
||||
// Act
|
||||
final result = await useCase(tMembreId, partialPrefs);
|
||||
|
||||
// Assert
|
||||
expect(result['theme'], equals('light'));
|
||||
verify(mockRepository.updatePreferences(tMembreId, partialPrefs));
|
||||
});
|
||||
|
||||
test('should handle empty preferences map', () async {
|
||||
// Arrange
|
||||
final emptyPrefs = <String, dynamic>{};
|
||||
when(mockRepository.updatePreferences(tMembreId, emptyPrefs))
|
||||
.thenAnswer((_) async => emptyPrefs);
|
||||
|
||||
// Act
|
||||
final result = await useCase(tMembreId, emptyPrefs);
|
||||
|
||||
// Assert
|
||||
expect(result, isEmpty);
|
||||
verify(mockRepository.updatePreferences(tMembreId, emptyPrefs));
|
||||
});
|
||||
|
||||
test('should throw exception when update fails', () async {
|
||||
// Arrange
|
||||
when(mockRepository.updatePreferences(any, any))
|
||||
.thenThrow(Exception('Failed to update preferences'));
|
||||
|
||||
// Act & Assert
|
||||
expect(
|
||||
() => useCase(tMembreId, tPreferences),
|
||||
throwsException,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
// Mocks generated by Mockito 5.4.4 from annotations
|
||||
// in unionflow_mobile_apps/test/features/profile/domain/usecases/update_preferences_test.dart.
|
||||
// Do not manually edit this file.
|
||||
|
||||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||
import 'dart:async' as _i4;
|
||||
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:unionflow_mobile_apps/features/members/data/models/membre_complete_model.dart'
|
||||
as _i2;
|
||||
import 'package:unionflow_mobile_apps/features/profile/domain/repositories/profile_repository.dart'
|
||||
as _i3;
|
||||
|
||||
// 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 _FakeMembreCompletModel_0 extends _i1.SmartFake
|
||||
implements _i2.MembreCompletModel {
|
||||
_FakeMembreCompletModel_0(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
/// A class which mocks [IProfileRepository].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockIProfileRepository extends _i1.Mock
|
||||
implements _i3.IProfileRepository {
|
||||
MockIProfileRepository() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.MembreCompletModel?> getMe() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getMe,
|
||||
[],
|
||||
),
|
||||
returnValue: _i4.Future<_i2.MembreCompletModel?>.value(),
|
||||
) as _i4.Future<_i2.MembreCompletModel?>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.MembreCompletModel?> getProfileByEmail(String? email) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getProfileByEmail,
|
||||
[email],
|
||||
),
|
||||
returnValue: _i4.Future<_i2.MembreCompletModel?>.value(),
|
||||
) as _i4.Future<_i2.MembreCompletModel?>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.MembreCompletModel> updateProfile(
|
||||
String? id,
|
||||
_i2.MembreCompletModel? membre,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#updateProfile,
|
||||
[
|
||||
id,
|
||||
membre,
|
||||
],
|
||||
),
|
||||
returnValue:
|
||||
_i4.Future<_i2.MembreCompletModel>.value(_FakeMembreCompletModel_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#updateProfile,
|
||||
[
|
||||
id,
|
||||
membre,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.MembreCompletModel>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.MembreCompletModel> updateAvatar(
|
||||
String? id,
|
||||
String? photoUrl,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#updateAvatar,
|
||||
[
|
||||
id,
|
||||
photoUrl,
|
||||
],
|
||||
),
|
||||
returnValue:
|
||||
_i4.Future<_i2.MembreCompletModel>.value(_FakeMembreCompletModel_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#updateAvatar,
|
||||
[
|
||||
id,
|
||||
photoUrl,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.MembreCompletModel>);
|
||||
|
||||
@override
|
||||
_i4.Future<void> changePassword(
|
||||
String? id,
|
||||
String? oldPassword,
|
||||
String? newPassword,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#changePassword,
|
||||
[
|
||||
id,
|
||||
oldPassword,
|
||||
newPassword,
|
||||
],
|
||||
),
|
||||
returnValue: _i4.Future<void>.value(),
|
||||
returnValueForMissingStub: _i4.Future<void>.value(),
|
||||
) as _i4.Future<void>);
|
||||
|
||||
@override
|
||||
_i4.Future<Map<String, dynamic>> updatePreferences(
|
||||
String? id,
|
||||
Map<String, dynamic>? preferences,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#updatePreferences,
|
||||
[
|
||||
id,
|
||||
preferences,
|
||||
],
|
||||
),
|
||||
returnValue:
|
||||
_i4.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
) as _i4.Future<Map<String, dynamic>>);
|
||||
|
||||
@override
|
||||
_i4.Future<void> deleteAccount(String? id) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteAccount,
|
||||
[id],
|
||||
),
|
||||
returnValue: _i4.Future<void>.value(),
|
||||
returnValueForMissingStub: _i4.Future<void>.value(),
|
||||
) as _i4.Future<void>);
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/// Tests unitaires pour UpdateProfile use case
|
||||
library update_profile_test;
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:unionflow_mobile_apps/features/profile/domain/repositories/profile_repository.dart';
|
||||
import 'package:unionflow_mobile_apps/features/profile/domain/usecases/update_profile.dart';
|
||||
import 'package:unionflow_mobile_apps/features/members/data/models/membre_complete_model.dart';
|
||||
|
||||
@GenerateMocks([IProfileRepository])
|
||||
import 'update_profile_test.mocks.dart';
|
||||
|
||||
void main() {
|
||||
late UpdateProfile useCase;
|
||||
late MockIProfileRepository mockRepository;
|
||||
|
||||
setUp(() {
|
||||
mockRepository = MockIProfileRepository();
|
||||
useCase = UpdateProfile(mockRepository);
|
||||
});
|
||||
|
||||
group('UpdateProfile Use Case', () {
|
||||
const tMembreId = 'membre1';
|
||||
final tMembre = MembreCompletModel(
|
||||
id: tMembreId,
|
||||
nom: 'Dupont',
|
||||
prenom: 'Jean',
|
||||
email: 'jean.dupont@example.com',
|
||||
telephone: '+33612345678',
|
||||
dateNaissance: DateTime(1990, 1, 1),
|
||||
);
|
||||
|
||||
final tUpdatedMembre = MembreCompletModel(
|
||||
id: tMembreId,
|
||||
nom: 'Dupont',
|
||||
prenom: 'Jean',
|
||||
email: 'jean.dupont@example.com',
|
||||
telephone: '+33698765432', // Updated phone
|
||||
dateNaissance: DateTime(1990, 1, 1),
|
||||
adresse: '123 Rue de Paris', // Added address
|
||||
);
|
||||
|
||||
test('should update profile successfully', () async {
|
||||
// Arrange
|
||||
when(mockRepository.updateProfile(tMembreId, tMembre))
|
||||
.thenAnswer((_) async => tUpdatedMembre);
|
||||
|
||||
// Act
|
||||
final result = await useCase(tMembreId, tMembre);
|
||||
|
||||
// Assert
|
||||
expect(result, equals(tUpdatedMembre));
|
||||
verify(mockRepository.updateProfile(tMembreId, tMembre));
|
||||
verifyNoMoreInteractions(mockRepository);
|
||||
});
|
||||
|
||||
test('should update only specified fields', () async {
|
||||
// Arrange
|
||||
when(mockRepository.updateProfile(any, any))
|
||||
.thenAnswer((_) async => tUpdatedMembre);
|
||||
|
||||
// Act
|
||||
final result = await useCase(tMembreId, tMembre);
|
||||
|
||||
// Assert
|
||||
expect(result.telephone, equals('+33698765432'));
|
||||
expect(result.adresse, equals('123 Rue de Paris'));
|
||||
verify(mockRepository.updateProfile(tMembreId, tMembre));
|
||||
});
|
||||
|
||||
test('should throw exception when profile not found', () async {
|
||||
// Arrange
|
||||
when(mockRepository.updateProfile(any, any))
|
||||
.thenThrow(Exception('Profil non trouvé'));
|
||||
|
||||
// Act & Assert
|
||||
expect(
|
||||
() => useCase(tMembreId, tMembre),
|
||||
throwsA(isA<Exception>()),
|
||||
);
|
||||
verify(mockRepository.updateProfile(tMembreId, tMembre));
|
||||
});
|
||||
|
||||
test('should throw exception when update fails', () async {
|
||||
// Arrange
|
||||
when(mockRepository.updateProfile(any, any))
|
||||
.thenThrow(Exception('Network error'));
|
||||
|
||||
// Act & Assert
|
||||
expect(
|
||||
() => useCase(tMembreId, tMembre),
|
||||
throwsException,
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
// Mocks generated by Mockito 5.4.4 from annotations
|
||||
// in unionflow_mobile_apps/test/features/profile/domain/usecases/update_profile_test.dart.
|
||||
// Do not manually edit this file.
|
||||
|
||||
// ignore_for_file: no_leading_underscores_for_library_prefixes
|
||||
import 'dart:async' as _i4;
|
||||
|
||||
import 'package:mockito/mockito.dart' as _i1;
|
||||
import 'package:unionflow_mobile_apps/features/members/data/models/membre_complete_model.dart'
|
||||
as _i2;
|
||||
import 'package:unionflow_mobile_apps/features/profile/domain/repositories/profile_repository.dart'
|
||||
as _i3;
|
||||
|
||||
// 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 _FakeMembreCompletModel_0 extends _i1.SmartFake
|
||||
implements _i2.MembreCompletModel {
|
||||
_FakeMembreCompletModel_0(
|
||||
Object parent,
|
||||
Invocation parentInvocation,
|
||||
) : super(
|
||||
parent,
|
||||
parentInvocation,
|
||||
);
|
||||
}
|
||||
|
||||
/// A class which mocks [IProfileRepository].
|
||||
///
|
||||
/// See the documentation for Mockito's code generation for more information.
|
||||
class MockIProfileRepository extends _i1.Mock
|
||||
implements _i3.IProfileRepository {
|
||||
MockIProfileRepository() {
|
||||
_i1.throwOnMissingStub(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.MembreCompletModel?> getMe() => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getMe,
|
||||
[],
|
||||
),
|
||||
returnValue: _i4.Future<_i2.MembreCompletModel?>.value(),
|
||||
) as _i4.Future<_i2.MembreCompletModel?>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.MembreCompletModel?> getProfileByEmail(String? email) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#getProfileByEmail,
|
||||
[email],
|
||||
),
|
||||
returnValue: _i4.Future<_i2.MembreCompletModel?>.value(),
|
||||
) as _i4.Future<_i2.MembreCompletModel?>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.MembreCompletModel> updateProfile(
|
||||
String? id,
|
||||
_i2.MembreCompletModel? membre,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#updateProfile,
|
||||
[
|
||||
id,
|
||||
membre,
|
||||
],
|
||||
),
|
||||
returnValue:
|
||||
_i4.Future<_i2.MembreCompletModel>.value(_FakeMembreCompletModel_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#updateProfile,
|
||||
[
|
||||
id,
|
||||
membre,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.MembreCompletModel>);
|
||||
|
||||
@override
|
||||
_i4.Future<_i2.MembreCompletModel> updateAvatar(
|
||||
String? id,
|
||||
String? photoUrl,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#updateAvatar,
|
||||
[
|
||||
id,
|
||||
photoUrl,
|
||||
],
|
||||
),
|
||||
returnValue:
|
||||
_i4.Future<_i2.MembreCompletModel>.value(_FakeMembreCompletModel_0(
|
||||
this,
|
||||
Invocation.method(
|
||||
#updateAvatar,
|
||||
[
|
||||
id,
|
||||
photoUrl,
|
||||
],
|
||||
),
|
||||
)),
|
||||
) as _i4.Future<_i2.MembreCompletModel>);
|
||||
|
||||
@override
|
||||
_i4.Future<void> changePassword(
|
||||
String? id,
|
||||
String? oldPassword,
|
||||
String? newPassword,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#changePassword,
|
||||
[
|
||||
id,
|
||||
oldPassword,
|
||||
newPassword,
|
||||
],
|
||||
),
|
||||
returnValue: _i4.Future<void>.value(),
|
||||
returnValueForMissingStub: _i4.Future<void>.value(),
|
||||
) as _i4.Future<void>);
|
||||
|
||||
@override
|
||||
_i4.Future<Map<String, dynamic>> updatePreferences(
|
||||
String? id,
|
||||
Map<String, dynamic>? preferences,
|
||||
) =>
|
||||
(super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#updatePreferences,
|
||||
[
|
||||
id,
|
||||
preferences,
|
||||
],
|
||||
),
|
||||
returnValue:
|
||||
_i4.Future<Map<String, dynamic>>.value(<String, dynamic>{}),
|
||||
) as _i4.Future<Map<String, dynamic>>);
|
||||
|
||||
@override
|
||||
_i4.Future<void> deleteAccount(String? id) => (super.noSuchMethod(
|
||||
Invocation.method(
|
||||
#deleteAccount,
|
||||
[id],
|
||||
),
|
||||
returnValue: _i4.Future<void>.value(),
|
||||
returnValueForMissingStub: _i4.Future<void>.value(),
|
||||
) as _i4.Future<void>);
|
||||
}
|
||||
Reference in New Issue
Block a user