import 'package:eatvio_app/features/consultations/models/consultation_model.dart'; import 'package:eatvio_app/features/plans/enums/chosen_plan_state_enum.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { group('DiaryStateEnum', () { test('has all expected values', () { expect(DiaryStateEnum.values.length, 8); expect(DiaryStateEnum.init, isNotNull); expect(DiaryStateEnum.started, isNotNull); expect(DiaryStateEnum.finished, isNotNull); expect(DiaryStateEnum.commented, isNotNull); expect(DiaryStateEnum.reviewedByUser, isNotNull); expect(DiaryStateEnum.lastDayStarted, isNotNull); expect(DiaryStateEnum.lastDayFinished, isNotNull); expect(DiaryStateEnum.lastDayCommented, isNotNull); }); }); group('DiaryModel', () { test('fromJson parses all fields correctly', () { final json = { 'id': 1, 'state': 'started', 'date': '2024-01-15', }; final model = DiaryModel.fromJson(json); expect(model.id, 1); expect(model.state, DiaryStateEnum.started); expect(model.date, isA()); expect(model.date.year, 2024); expect(model.date.month, 1); expect(model.date.day, 15); }); test('fromJson parses date with parseUnformattedDate', () { final json = { 'id': 2, 'state': 'finished', 'date': '2024-12-31', }; final model = DiaryModel.fromJson(json); expect(model.date.year, 2024); expect(model.date.month, 12); expect(model.date.day, 31); }); test('fromJson handles different states', () { final json = { 'id': 3, 'state': 'reviewed_by_user', 'date': '2024-01-01', }; final model = DiaryModel.fromJson(json); expect(model.state, DiaryStateEnum.reviewedByUser); }); test('toJson serializes all fields correctly', () { final model = DiaryModel( id: 1, state: DiaryStateEnum.started, date: DateTime(2024, 1, 15), ); final json = model.toJson(); expect(json['id'], 1); expect(json['state'], 'started'); expect(json['date'], isA()); }); }); group('ConsultationPaginationModel', () { test('fromJson parses data correctly', () { final json = { 'data': [], }; final model = ConsultationPaginationModel.fromJson(json); expect(model.data, isEmpty); }); test('fromJson parses data with consultations', () { final json = { 'data': [ { 'id': 1, 'last_state': 'started', 'plan_title': 'Test Plan', 'user_name': 'User 1', 'user_slug': 'user-1', 'consultant_payment': 1000.0, 'duration': 30, 'current_diary_day': 5, 'user_profile_photo_url': 'photo.jpg', 'consultation_option_price': 2000, 'start_date': '2024-01-01T00:00:00Z', 'end_date': '2024-01-31T00:00:00Z', 'consultant_id': 1, 'diaries': [], 'personal_diet_id': null, }, ], }; final model = ConsultationPaginationModel.fromJson(json); expect(model.data.length, 1); expect(model.data.first.id, 1); expect(model.data.first.planTitle, 'Test Plan'); }); test('toJson serializes data correctly', () { // Note: This test verifies the structure, actual serialization depends on ConsultationModel final model = ConsultationPaginationModel(data: []); final json = model.toJson(); expect(json.containsKey('data'), isTrue); expect(json['data'], isA()); }); test('toJson serializes ConsultationPaginationModel correctly', () { final consultation = ConsultationModel( id: 1, chosenPlanState: ChosenPlanStateEnum.stateStarted, planTitle: 'Test Plan', userName: 'User 1', userSlug: 'user-1', consultantPayment: 1000.0, duration: 30, currentDiaryDay: 5, userProfilePhotoUrl: 'photo.jpg', consultationOptionPrice: 2000, startDate: DateTime(2024, 1, 1), endDate: DateTime(2024, 1, 31), consultantId: 1, diaries: [], personalDietId: null, ); final model = ConsultationPaginationModel(data: [consultation]); final json = model.toJson(); expect(json.containsKey('data'), isTrue); expect((json['data'] as List).length, 1); }); }); group('ConsultationModel', () { test('toJson serializes ConsultationModel correctly', () { final model = ConsultationModel( id: 1, chosenPlanState: ChosenPlanStateEnum.stateStarted, planTitle: 'Test Plan', userName: 'User 1', userSlug: 'user-1', consultantPayment: 1000.0, duration: 30, currentDiaryDay: 5, userProfilePhotoUrl: 'photo.jpg', consultationOptionPrice: 2000, startDate: DateTime(2024, 1, 1), endDate: DateTime(2024, 1, 31), consultantId: 1, diaries: [ DiaryModel( id: 1, state: DiaryStateEnum.started, date: DateTime(2024, 1, 1), ), ], personalDietId: null, ); final json = model.toJson(); expect(json['id'], 1); expect(json['plan_title'], 'Test Plan'); expect(json['user_name'], 'User 1'); expect(json['duration'], 30); expect(json.containsKey('start_date'), isTrue); expect(json.containsKey('diaries'), isTrue); }); }); }