feat(notifications): support payment-required and start-date-set types (#3054)

This commit is contained in:
2026-11-24 09:18:59 +03:00
parent cf5c42ff4b
commit c6915a0d94
7 changed files with 289 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
import 'package:dio/dio.dart';
import 'package:eatvio_app/features/notifications/models/notification_model.dart';
import 'package:eatvio_app/features/notifications/service/notifications_service.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockito/annotations.dart';
@@ -1617,6 +1618,100 @@ void main() {
expect(result!['notifications'], isA<List>());
expect(result['notifications'].length, 1);
});
test('getNotifications - распознаёт client-plan-payment-required', () async {
const page = 1;
final response = Response(
data: {
'data': [
{
'type': 'client-plan-payment-required',
'data': {
'plan_name': 'План 3054',
'plan_id': 101,
'author_name': 'Консультант',
'author_id': 7,
'author_photo_path': '/storage/a.jpg',
'chat_id': 'uuid-101',
'chat_url': 'https://eatvio.ru/ru/chat/uuid-101',
'start_date': '2026-11-27T00:00:00+03:00',
'payment_deadline_at': '2026-11-26T12:00:00+03:00',
},
'read_at': null,
'created_at': '2026-11-24T10: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);
final notifications = result!['notifications'] as List<BaseNotificationModel>;
final notification = notifications.single;
expect(notification, isA<ClientPlanPaymentRequiredNotification>());
expect(notification.type, NotificationType.clientPlanPaymentRequired);
expect(notification.isRead, isFalse);
final clientNotification = notification as ClientPlanPaymentRequiredNotification;
expect(clientNotification.planName, 'План 3054');
expect(clientNotification.authorName, 'Консультант');
expect(clientNotification.chatUrl, 'https://eatvio.ru/ru/chat/uuid-101');
expect(clientNotification.paymentDeadlineAt, isNotNull);
});
test('getNotifications - распознаёт consultant-plan-start-date-set', () async {
const page = 1;
final response = Response(
data: {
'data': [
{
'type': 'consultant-plan-start-date-set',
'data': {
'plan_name': 'План 3054',
'plan_id': 102,
'user_name': 'Клиент',
'user_id': 8,
'user_photo_path': '/storage/c.jpg',
'chat_id': 'uuid-102',
'chat_url': 'https://eatvio.ru/ru/chat/uuid-102',
'start_date': '2026-11-27T00:00:00+03:00',
'payment_deadline_at': null,
},
'read_at': '2026-11-24T11:00:00Z',
'created_at': '2026-11-24T10: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);
final notifications = result!['notifications'] as List<BaseNotificationModel>;
final notification = notifications.single;
expect(notification, isA<ConsultantPlanStartDateSetNotification>());
expect(notification.type, NotificationType.consultantPlanStartDateSet);
expect(notification.isRead, isTrue);
final consultantNotification = notification as ConsultantPlanStartDateSetNotification;
expect(consultantNotification.planName, 'План 3054');
expect(consultantNotification.clientName, 'Клиент');
expect(consultantNotification.chatUrl, 'https://eatvio.ru/ru/chat/uuid-102');
expect(consultantNotification.paymentDeadlineAt, isNull);
});
});
}