fix(chat): Correction race condition + Implémentation TODOs
## Corrections Critiques ### Race Condition - Statuts de Messages - Fix : Les icônes de statut (✓, ✓✓, ✓✓ bleu) ne s'affichaient pas - Cause : WebSocket delivery confirmations arrivaient avant messages locaux - Solution : Pattern Optimistic UI dans chat_bloc.dart - Création message temporaire immédiate - Ajout à la liste AVANT requête HTTP - Remplacement par message serveur à la réponse - Fichier : lib/presentation/state_management/chat_bloc.dart ## Implémentation TODOs (13/21) ### Social (social_header_widget.dart) - ✅ Copier lien du post dans presse-papiers - ✅ Partage natif via Share.share() - ✅ Dialogue de signalement avec 5 raisons ### Partage (share_post_dialog.dart) - ✅ Interface sélection d'amis avec checkboxes - ✅ Partage externe via Share API ### Média (media_upload_service.dart) - ✅ Parsing JSON réponse backend - ✅ Méthode deleteMedia() pour suppression - ✅ Génération miniature vidéo ### Posts (create_post_dialog.dart, edit_post_dialog.dart) - ✅ Extraction URL depuis uploads - ✅ Documentation chargement médias ### Chat (conversations_screen.dart) - ✅ Navigation vers notifications - ✅ ConversationSearchDelegate pour recherche ## Nouveaux Fichiers ### Configuration - build-prod.ps1 : Script build production avec dart-define - lib/core/constants/env_config.dart : Gestion environnements ### Documentation - TODOS_IMPLEMENTED.md : Documentation complète TODOs ## Améliorations ### Architecture - Refactoring injection de dépendances - Amélioration routing et navigation - Optimisation providers (UserProvider, FriendsProvider) ### UI/UX - Amélioration thème et couleurs - Optimisation animations - Meilleure gestion erreurs ### Services - Configuration API avec env_config - Amélioration datasources (events, users) - Optimisation modèles de données
This commit is contained in:
75
test/domain/usecases/get_user_test.dart
Normal file
75
test/domain/usecases/get_user_test.dart
Normal file
@@ -0,0 +1,75 @@
|
||||
import 'package:afterwork/core/errors/failures.dart';
|
||||
import 'package:afterwork/domain/entities/user.dart';
|
||||
import 'package:afterwork/domain/repositories/user_repository.dart';
|
||||
import 'package:afterwork/domain/usecases/get_user.dart';
|
||||
import 'package:dartz/dartz.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
|
||||
// Mock classes
|
||||
class MockUserRepository extends Mock implements UserRepository {}
|
||||
|
||||
void main() {
|
||||
group('GetUser', () {
|
||||
late GetUser usecase;
|
||||
late MockUserRepository mockRepository;
|
||||
|
||||
setUp(() {
|
||||
mockRepository = MockUserRepository();
|
||||
usecase = GetUser(mockRepository);
|
||||
});
|
||||
|
||||
const tUserId = 'user123';
|
||||
final tUser = User(
|
||||
userId: tUserId,
|
||||
email: 'test@example.com',
|
||||
userLastName: 'Doe',
|
||||
userFirstName: 'John',
|
||||
motDePasse: 'password123',
|
||||
profileImageUrl: 'https://test.com/profile.jpg',
|
||||
);
|
||||
|
||||
test('should return Right(User) when repository returns user', () async {
|
||||
// Arrange
|
||||
when(() => mockRepository.getUser(any())).thenAnswer((_) async => Right(tUser));
|
||||
|
||||
// Act
|
||||
final result = await usecase(tUserId);
|
||||
|
||||
// Assert
|
||||
expect(result, isA<Right<Failure, User>>());
|
||||
result.fold(
|
||||
(failure) => fail('Should not return failure'),
|
||||
(user) => expect(user.userId, tUserId),
|
||||
);
|
||||
verify(() => mockRepository.getUser(tUserId)).called(1);
|
||||
});
|
||||
|
||||
test('should return Left(ServerFailure) when repository throws exception', () async {
|
||||
// Arrange
|
||||
when(() => mockRepository.getUser(any())).thenThrow(Exception('Error'));
|
||||
|
||||
// Act
|
||||
final result = await usecase(tUserId);
|
||||
|
||||
// Assert
|
||||
expect(result, isA<Left<Failure, User>>());
|
||||
result.fold(
|
||||
(failure) => expect(failure, isA<ServerFailure>()),
|
||||
(user) => fail('Should not return user'),
|
||||
);
|
||||
});
|
||||
|
||||
test('should call repository with correct userId', () async {
|
||||
// Arrange
|
||||
when(() => mockRepository.getUser(any())).thenAnswer((_) async => Right(tUser));
|
||||
|
||||
// Act
|
||||
await usecase(tUserId);
|
||||
|
||||
// Assert
|
||||
verify(() => mockRepository.getUser(tUserId)).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user