refactor(tests): update model instantiation to use const for improved performance

This commit is contained in:
mso7nueh
2025-12-03 06:16:34 +03:00
parent d0becb9e11
commit f3d4478c65
15 changed files with 1840 additions and 27 deletions

View File

@@ -0,0 +1,77 @@
import 'package:eatvio_app/features/notifications/models/notification_model.dart';
import 'package:eatvio_app/features/notifications/repository/notifications_repository.dart';
import 'package:eatvio_app/features/notifications/service/notifications_service.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
import 'package:mockito/mockito.dart';
import 'notifications_repository_test.mocks.dart';
@GenerateMocks([NotificationsService])
void main() {
group('NotificationsRepository', () {
late NotificationsRepository repository;
late MockNotificationsService mockNotificationsService;
setUp(() {
mockNotificationsService = MockNotificationsService();
repository = NotificationsRepository(notificationsService: mockNotificationsService);
});
test('getNotifications - успешная загрузка уведомлений', () async {
final notifications = [
ChosenPlanStartedToClientNotification(
type: NotificationType.chosenPlanStartedToClientNotification,
planName: 'Test Plan',
planId: 1,
isRead: false,
createdAt: DateTime.now(),
),
];
final result = {
'notifications': notifications,
'pagination': {
'current_page': 1,
'last_page': 1,
},
};
when(mockNotificationsService.getNotifications(page: 1))
.thenAnswer((_) async => result);
final response = await repository.getNotifications(page: 1);
expect(response, equals(result));
verify(mockNotificationsService.getNotifications(page: 1)).called(1);
});
test('getNotifications - проброс ошибки', () async {
final error = Exception('Ошибка загрузки');
when(mockNotificationsService.getNotifications(page: 1))
.thenThrow(error);
expect(() => repository.getNotifications(page: 1), throwsA(error));
verify(mockNotificationsService.getNotifications(page: 1)).called(1);
});
test('markNotificationsAsRead - успешная пометка как прочитанных', () async {
when(mockNotificationsService.markNotificationsAsRead())
.thenAnswer((_) async => {});
await repository.markNotificationsAsRead();
verify(mockNotificationsService.markNotificationsAsRead()).called(1);
});
test('markNotificationsAsRead - проброс ошибки', () async {
final error = Exception('Ошибка');
when(mockNotificationsService.markNotificationsAsRead())
.thenThrow(error);
expect(() => repository.markNotificationsAsRead(), throwsA(error));
verify(mockNotificationsService.markNotificationsAsRead()).called(1);
});
});
}