import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart'; import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart'; import 'package:eatvio_app/features/plans/enums/chosen_plan_state_enum.dart'; import 'package:eatvio_app/features/plans/models/chosen_plan_model.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { group('ChosenPlanModel', () { test('создает ChosenPlanModel с правильными значениями', () { const plan = PlanModel( id: 1, slug: 'test-plan', name: 'Test Plan', image: 'https://example.com/image.jpg', duration: 7, state: 'active', type: PlanType(fit: true, slim: false, behavior: false, wellness: false), details: 'Test details', packetsCount: 3, author: Author( authorSlug: 'author', authorName: 'Author Name', authorProfileIcon: 'https://example.com/icon.jpg', authorIsMe: false, isEntitySubscribedByMe: null, authorPlaceInRating: null, ), totalLikes: 10, totalViews: 100, totalComments: 5, isFavorite: false, minPriceOfOptions: 1000, maxPriceOfOptions: 2000, wasLikedByMe: false, ); final chosenPlan = ChosenPlanModel( id: 1, optionType: 'options1', startDate: DateTime(2024, 1, 1), chosenPlanState: ChosenPlanStateEnum.stateInited, chatId: 'chat-1', consultantId: 1, plan: plan, ); expect(chosenPlan.id, 1); expect(chosenPlan.optionType, 'options1'); expect(chosenPlan.chosenPlanState, ChosenPlanStateEnum.stateInited); expect(chosenPlan.plan.id, 1); }); test('fromJson создает ChosenPlanModel из JSON', () { final json = { 'id': 1, 'option_type': 'options1', 'start_date': '2024-01-01T00:00:00Z', 'last_state': 'initied', 'chat_id': 'chat-1', 'consultant_id': 1, 'plan': { 'id': 1, 'slug': 'test-plan', 'name': 'Test Plan', 'image': 'https://example.com/image.jpg', 'duration': 7, 'state': 'active', 'type': {'fit': true, 'slim': false, 'behavior': false, 'wellness': false}, 'description_md': 'Test details', 'packets_count': 3, 'author': { 'author_slug': 'author', 'author_name': 'Author Name', 'author_profile_icon': 'https://example.com/icon.jpg', 'author_is_me': false, 'is_entity_subscribed_by_me': null, 'author_place_in_rating': null, }, 'total_likes': 10, 'total_views': 100, 'total_comments': 5, 'is_favorite': false, 'min_price_of_options': 1000.0, 'max_price_of_options': 2000.0, 'was_liked_by_me': false, }, }; final chosenPlan = ChosenPlanModel.fromJson(json); expect(chosenPlan.id, 1); expect(chosenPlan.optionType, 'options1'); expect(chosenPlan.chosenPlanState, ChosenPlanStateEnum.stateInited); expect(chosenPlan.chatId, 'chat-1'); }); }); group('parseChosenPlan', () { test('parseChosenPlan создает ChosenPlanModel из Map', () { final json = { 'id': 1, 'option_type': 'options1', 'start_date': '2024-01-01T00:00:00Z', 'last_state': 'initied', 'chat_id': 'chat-1', 'consultant_id': 1, 'plan': { 'id': 1, 'slug': 'test-plan', 'name': 'Test Plan', 'image': 'https://example.com/image.jpg', 'duration': 7, 'state': 'active', 'type': {'fit': true, 'slim': false, 'behavior': false, 'wellness': false}, 'description_md': 'Test details', 'packets_count': 3, 'author': { 'author_slug': 'author', 'author_name': 'Author Name', 'author_profile_icon': 'https://example.com/icon.jpg', 'author_is_me': false, 'is_entity_subscribed_by_me': null, 'author_place_in_rating': null, }, 'total_likes': 10, 'total_views': 100, 'total_comments': 5, 'is_favorite': false, 'min_price_of_options': 1000.0, 'max_price_of_options': 2000.0, 'was_liked_by_me': false, }, }; final result = parseChosenPlan(json); expect(result, isNotNull); expect(result!.id, 1); expect(result.optionType, 'options1'); }); test('parseChosenPlan возвращает null для не-Map значения', () { expect(parseChosenPlan(null), isNull); expect(parseChosenPlan('string'), isNull); expect(parseChosenPlan(123), isNull); expect(parseChosenPlan([]), isNull); }); }); }