fix: show personal diet name and consultant notifications

This commit is contained in:
2026-11-06 14:22:55 +03:00
parent ad70d0988e
commit 6c4572af55
26 changed files with 323 additions and 34 deletions

View File

@@ -92,6 +92,7 @@ void main() {
DiaryReminderForUsersNotification.fromJson(base, NotificationType.diaryReminderForUsers);
DiaryReminderForUsersNotification.fromJson({'created_at': c, 'data': <String, dynamic>{}}, NotificationType.diaryReminderForUsers);
PersonalDietIsDefinedToCustomerNotification.fromJson(base, NotificationType.personalDietIsDefinedToCustomer);
PersonalDietIsDefinedToAuthorNotification.fromJson(base, NotificationType.personalDietIsDefinedToAuthor);
ConsultantEducationUpdatedNotification.fromJson(base, NotificationType.consultantEducationUpdated);
ComplaintRegisteredNotification.fromJson(base, NotificationType.complaintRegistered);
ContentUnpublishedNotification.fromJson(base, NotificationType.contentUnpublished);

View File

@@ -50,6 +50,7 @@ void main() {
'stay-on-track-to-customer': NotificationType.stayOnTrackToCustomer,
'diary-reminder-for-users': NotificationType.diaryReminderForUsers,
'personal-diet-is-defined-to-customer': NotificationType.personalDietIsDefinedToCustomer,
'personal-diet-is-defined-to-author': NotificationType.personalDietIsDefinedToAuthor,
};
cases.forEach((key, expected) {
@@ -671,6 +672,34 @@ void main() {
expect(notification.type, NotificationType.personalizedDietIsDefined);
});
test('PersonalDietIsDefinedToAuthorNotification.fromJson parses all fields', () {
final json = {
'chosen_plan_id': 12,
'diet_id': 34,
'plan_name': 'Plan',
'user_name': 'Client',
'consultant_name': 'Consultant',
'diet_name': 'Personal diet',
'role': 'consultant',
'peer_slug': 'client-slug',
'peer_image_path': 'avatars/client.png',
'created_at': '2024-01-30T12:00:00Z',
};
final notification = PersonalDietIsDefinedToAuthorNotification.fromJson(
json,
NotificationType.personalDietIsDefinedToAuthor,
isRead: false,
);
expect(notification.chosenPlanId, 12);
expect(notification.dietId, 34);
expect(notification.userName, 'Client');
expect(notification.dietName, 'Personal diet');
expect(notification.peerSlug, 'client-slug');
expect(notification.type, NotificationType.personalDietIsDefinedToAuthor);
});
test('ChosenPlanFinishedToClientNotification.fromJson parses all fields', () {
final json = {
'plan_name': 'Finished Plan',

View File

@@ -1212,6 +1212,31 @@ void main() {
expect(find.byType(NotificationWidget), findsOneWidget);
});
testWidgets('displays PersonalDietIsDefinedToAuthorNotification', (
tester,
) async {
final notification = PersonalDietIsDefinedToAuthorNotification(
type: NotificationType.personalDietIsDefinedToAuthor,
isRead: false,
createdAt: testDate,
chosenPlanId: 1,
dietId: 1,
planName: 'Plan',
userName: 'Client',
consultantName: 'Consultant',
dietName: 'Test Diet',
role: 'consultant',
peerSlug: 'client-slug',
peerImagePath: '',
);
await tester.pumpWidget(createTestWidget(notification));
await tester.pumpAndSettle();
expect(find.textContaining('Вы предложили персональную диету пользователю Client'), findsOneWidget);
expect(find.textContaining('Test Diet'), findsOneWidget);
});
testWidgets('displays UnknownNotification', (tester) async {
final notification = UnknownNotification(
type: NotificationType.unknown,

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';
@@ -1454,6 +1455,42 @@ void main() {
expect(result, isNotNull);
expect(result!['notifications'], isA<List>());
expect(result['notifications'].length, 1);
expect(result['notifications'].first, isA<PersonalDietIsDefinedToCustomerNotification>());
});
test('getNotifications - обрабатывает PersonalDietIsDefinedToAuthor', () async {
const page = 1;
final response = Response(
data: {
'data': [
{
'type': 'personal-diet-is-defined-to-author',
'data': {
'diet_name': 'Test Diet',
'diet_id': 1,
'user_name': 'Client',
},
'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<List>());
expect(result['notifications'].length, 1);
expect(result['notifications'].first, isA<PersonalDietIsDefinedToAuthorNotification>());
});
test('getNotifications - обрабатывает UserDailyReportCompleted', () async {