import 'package:dio/dio.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 '../../../fixtures/fixture_reader.dart'; import 'notifications_service_test.mocks.dart'; @GenerateNiceMocks([MockSpec()]) void main() { group('NotificationsService', () { late NotificationsService notificationsService; late MockDio mockDio; setUp(() { mockDio = MockDio(); notificationsService = NotificationsService(mockDio); }); test('getNotifications - возвращает уведомления', () async { const page = 1; final json = FixtureReader.readAsMap('notifications/notifications_response.json'); final response = Response( data: { 'data': json['notifications'], 'current_page': json['pagination']['current_page'], 'last_page': json['pagination']['last_page'], 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)) .thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isA?>()); expect(result, isNotNull); expect(result!['notifications'], isA()); verify(mockDio.get(any)).called(1); }); test('markNotificationsAsRead - помечает уведомления как прочитанные', () async { final response = Response( data: {}, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/mark_notifications_as_readed'), ); when(mockDio.post(any)) .thenAnswer((_) async => response); await notificationsService.markNotificationsAsRead(); verify(mockDio.post(any)).called(1); }); test('getNotifications - возвращает null при statusCode != 200', () async { const page = 1; final response = Response( data: {}, statusCode: 404, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNull); }); test('getNotifications - обрабатывает ошибку', () async { const page = 1; when(mockDio.get(any)).thenThrow(DioException( requestOptions: RequestOptions(path: '/api/profile/notifications'), )); expect(() => notificationsService.getNotifications(page: page), throwsA(isA())); }); test('getNotifications - определяет тип из поля type в корне', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'chosen-plan-started-to-client', 'data': { 'plan_name': 'Test Plan', 'plan_id': 1, }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - определяет тип из поля notification_class_name в корне', () async { const page = 1; final response = Response( data: { 'data': [ { 'notification_class_name': 'App\\Notifications\\Plan\\PlanSubscriptionStartedToAuthor', 'data': { 'plan_name': 'Test Plan', 'user_name': 'Test User', 'chat_id': 'chat-1', }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - определяет тип из поля type в data', () async { const page = 1; final response = Response( data: { 'data': [ { 'data': { 'type': 'diet-started', 'diet_name': 'Test Diet', }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает ошибку парсинга отдельного уведомления', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'invalid-type', 'data': null, // Invalid data 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); // При ошибке парсинга возвращается UnknownNotification expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает уведомление с read_at', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'chosen-plan-started-to-client', 'data': { 'plan_name': 'Test Plan', 'plan_id': 1, }, 'read_at': '2024-01-01T13:00:00Z', 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('markNotificationsAsRead - обрабатывает ошибку', () async { when(mockDio.post(any)).thenThrow(DioException( requestOptions: RequestOptions(path: '/api/profile/mark_notifications_as_readed'), )); expect(() => notificationsService.markNotificationsAsRead(), throwsA(isA())); }); test('getNotifications - определяет тип из поля notification_class_name в data', () async { const page = 1; final response = Response( data: { 'data': [ { 'data': { 'notification_class_name': 'App\\Notifications\\Diet\\DietStarted', 'diet_name': 'Test Diet', }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает уведомление без типа (unknown)', () async { const page = 1; final response = Response( data: { 'data': [ { 'data': { 'some_field': 'value', }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает уведомление с data не Map', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'chosen-plan-started-to-client', 'data': 'not-a-map', // data не является Map 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); // При ошибке парсинга возвращается UnknownNotification expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает уведомление с null data', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'chosen-plan-started-to-client', 'data': null, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); // При ошибке парсинга возвращается UnknownNotification expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает уведомление с пустым списком', () async { const page = 1; final response = Response( data: { 'data': [], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 0, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 0); expect(result['pagination']['total'], 0); }); test('getNotifications - обрабатывает уведомление с различными типами пагинации', () async { const page = 2; final response = Response( data: { 'data': [ { 'type': 'chosen-plan-started-to-client', 'data': { 'plan_name': 'Test Plan', 'plan_id': 1, }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 2, 'last_page': 3, 'per_page': 10, 'total': 25, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['pagination']['current_page'], 2); expect(result['pagination']['last_page'], 3); expect(result['pagination']['per_page'], 10); expect(result['pagination']['total'], 25); }); test('getNotifications - обрабатывает уведомление с type null', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': null, 'data': { 'some_field': 'value', }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает уведомление с notification_class_name null', () async { const page = 1; final response = Response( data: { 'data': [ { 'notification_class_name': null, 'data': { 'some_field': 'value', }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает PlanSubscriptionStartedToAuthor', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'plan-subscription-started-to-author', 'data': { 'plan_name': 'Test Plan', 'user_name': 'Test User', 'chat_id': 'chat-1', }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает PlanSubscriptionCanceledToAuthor', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'plan-subscription-canceled-to-author', 'data': { 'plan_name': 'Test Plan', 'user_name': 'Test User', 'chat_id': 'chat-1', }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает ChosenPlanStartedToConsultantNotification', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'chosen-plan-started-to-consultant-notification', 'data': { 'plan_name': 'Test Plan', 'plan_id': 1, }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает ChosenPlanTomorrowReminderToConsultantNotification', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'chosen-plan-tomorrow-reminder-to-consultant-notification', 'data': { 'plan_name': 'Test Plan', 'plan_id': 1, }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает PlanSubscriptionPaidToAuthor', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'plan-subscription-paid-to-author', 'data': { 'plan_name': 'Test Plan', 'user_name': 'Test User', 'chat_id': 'chat-1', }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает ChosenPlanFinishedToConsultant', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'chosen-plan-finished-to-consultant', 'data': { 'plan_name': 'Test Plan', 'plan_id': 1, }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает ChosenPlanLastDayFinishedForUser', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'chosen-plan-last-day-finished-for-user', 'data': { 'plan_name': 'Test Plan', 'plan_id': 1, }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает ChosenPlanConsultantLastDayStarted', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'chosen-plan-consultant-last-day-started', 'data': { 'plan_name': 'Test Plan', 'plan_id': 1, }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает ComplaintToModerationForUser', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'complaint-to-moderation-for-user', 'data': { 'complaint_id': 1, }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает CommentReplied', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'comment-replied', 'data': { 'comment_id': 1, }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает ScoreAdded', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'score-added', 'data': { 'score': 10, }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает EntityCommented', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'entity-commented', 'data': { 'entity_id': 1, 'entity_type': 'plan', }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает PlanSubscriptionExpired', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'plan-subscription-expired', 'data': { 'plan_name': 'Test Plan', 'plan_id': 1, }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает PlanSubscriptionRenewed', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'plan-subscription-renewed', 'data': { 'plan_name': 'Test Plan', 'plan_id': 1, }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает ConsultantAssigned', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'consultant-assigned', 'data': { 'consultant_name': 'Test Consultant', 'consultant_id': 1, }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает ConsultantUnassigned', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'consultant-unassigned', 'data': { 'consultant_name': 'Test Consultant', 'consultant_id': 1, }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает PaymentFailed', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'payment-failed', 'data': { 'amount': 100.0, 'plan_name': 'Test Plan', }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает PaymentSuccessful', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'payment-successful', 'data': { 'amount': 100.0, 'plan_name': 'Test Plan', }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает GoalAchieved', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'goal-achieved', 'data': { 'goal_name': 'Test Goal', 'goal_id': 1, }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает WorkoutReminder', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'workout-reminder', 'data': { 'workout_name': 'Test Workout', 'workout_id': 1, }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает MealReminder', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'meal-reminder', 'data': { 'meal_name': 'Test Meal', 'meal_id': 1, }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает BadgeAwarded', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'badge-awarded', 'data': { 'badge_name': 'Test Badge', 'badge_id': 1, }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает BadgeRevoked', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'badge-revoked', 'data': { 'badge_name': 'Test Badge', 'badge_id': 1, }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает PhoneChanged', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'phone-changed', 'data': { 'phone': '+1234567890', }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает Subscription', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'subscription', 'data': { 'subscription_name': 'Test Subscription', 'subscription_id': 1, }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает ScoreSubstracted', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'score-substracted', 'data': { 'score': -5, }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает ProductStatusUpdatedForAuthor', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'product-status-updated-for-author', 'data': { 'product_name': 'Test Product', 'product_id': 1, 'status': 'approved', }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает DiaryReminderForUsers', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'diary-reminder-for-users', 'diary_id': 1, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает PersonalDietIsDefinedToCustomer', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'personal-diet-is-defined-to-customer', 'data': { 'diet_name': 'Test Diet', 'diet_id': 1, }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает UserDailyReportCompleted', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'user-daily-report-completed', 'data': { 'report_date': '2024-01-01', }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает StayOnTrackToCustomer', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'stay-on-track-to-customer', 'data': { 'plan_name': 'Test Plan', 'plan_id': 1, }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает ConsultantRequestStarted', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'consultant-request-started', 'data': { 'request_id': 1, }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает ClientCloseComplaintSuccess', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'client-close-complaint-success', 'data': { 'complaint_id': 1, }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); test('getNotifications - обрабатывает ClientRefundSuccess', () async { const page = 1; final response = Response( data: { 'data': [ { 'type': 'client-refund-success', 'data': { 'refund_amount': 100.0, 'refund_id': 1, }, 'read_at': null, 'created_at': '2024-01-01T12:00:00Z', }, ], 'current_page': 1, 'last_page': 1, 'per_page': 10, 'total': 1, }, statusCode: 200, requestOptions: RequestOptions(path: '/api/profile/notifications'), ); when(mockDio.get(any)).thenAnswer((_) async => response); final result = await notificationsService.getNotifications(page: page); expect(result, isNotNull); expect(result!['notifications'], isA()); expect(result['notifications'].length, 1); }); }); }