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:eatvio_app/features/plans/services/plan_service.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mockito/annotations.dart'; import 'package:mockito/mockito.dart'; import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart'; import 'plan_service_test.mocks.dart'; @GenerateNiceMocks([MockSpec()]) void main() { group('PlanService', () { late MockPlanService mockPlanService; setUp(() { mockPlanService = MockPlanService(); }); test('getPlan returns PlanModel by slug', () async { const slug = 'test-plan-slug'; const expected = PlanModel( id: 1, slug: slug, name: 'Test Plan', image: 'https://someurl.com/img.jpg', duration: 30, state: 'active', type: PlanType(fit: true, slim: false, behavior: false, wellness: false), details: 'Test plan description', packetsCount: 1, author: Author(authorSlug: '', authorName: '', authorProfileIcon: '', authorIsMe: false), totalLikes: 1, totalViews: 1, totalComments: 1, isFavorite: false, minPriceOfOptions: 100.0, maxPriceOfOptions: 500.0, wasLikedByMe: false, ); when(mockPlanService.getPlan(slug)).thenAnswer((_) async => expected); final result = await mockPlanService.getPlan(slug); expect(result, isA()); expect(result.slug, slug); expect(result.name, 'Test Plan'); verify(mockPlanService.getPlan(slug)).called(1); }); test('likePlan likes plan by slug', () async { const slug = 'test-plan-slug'; when(mockPlanService.likePlan(slug: slug)).thenAnswer((_) async => Future.value()); await mockPlanService.likePlan(slug: slug); verify(mockPlanService.likePlan(slug: slug)).called(1); }); test('addToFavorite adds plan to favorite by slug', () async { const slug = 'test-plan-slug'; when(mockPlanService.addToFavorite(slug: slug)).thenAnswer((_) async => Future.value()); await mockPlanService.addToFavorite(slug: slug); verify(mockPlanService.addToFavorite(slug: slug)).called(1); }); test('removeFromFavorite removes plan from favorite by slug', () async { const slug = 'test-plan-slug'; when(mockPlanService.removeFromFavorite(slug: slug)).thenAnswer((_) async => Future.value()); await mockPlanService.removeFromFavorite(slug: slug); verify(mockPlanService.removeFromFavorite(slug: slug)).called(1); }); test('chosePlan chooses plan with option', () async { const slug = 'test-plan-slug'; final option = {'option_type': 'basic', 'start_date': '2024-01-01'}; final expected = ChosenPlanModel( id: 1, optionType: 'basic', startDate: DateTime(2024, 1, 1), chosenPlanState: ChosenPlanStateEnum.stateStarted, chatId: 'chat-123', consultantId: 1, plan: const PlanModel( id: 1, slug: slug, name: 'Test Plan', image: 'https://someurl.com/img.jpg', duration: 30, state: 'active', type: PlanType(fit: true, slim: false, behavior: false, wellness: false), details: 'Test plan description', packetsCount: 1, author: Author(authorSlug: '', authorName: '', authorProfileIcon: '', authorIsMe: false), totalLikes: 1, totalViews: 1, totalComments: 1, isFavorite: false, minPriceOfOptions: 100.0, maxPriceOfOptions: 500.0, wasLikedByMe: false, ), ); when(mockPlanService.chosePlan(slug: slug, option: option)).thenAnswer((_) async => expected); final result = await mockPlanService.chosePlan(slug: slug, option: option); expect(result, isA()); expect(result.plan.slug, slug); verify(mockPlanService.chosePlan(slug: slug, option: option)).called(1); }); }); }