import 'package:eatvio_app/features/consultant/become_consultant/models/consultation_request_model.dart'; import 'package:eatvio_app/features/profile/models/profile_model.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { group('CompletedCoursesModel', () { test('fromJson parses all fields correctly', () { final json = { 'date': '2024-01-15', 'title': 'Course Title', }; final model = CompletedCoursesModel.fromJson(json); expect(model.date, '2024-01-15'); expect(model.title, 'Course Title'); }); test('toJson serializes all fields correctly', () { const model = CompletedCoursesModel(date: '2024-01-15', title: 'Course Title'); final json = model.toJson(); expect(json['date'], '2024-01-15'); expect(json['title'], 'Course Title'); }); }); group('EducationModel', () { test('fromJson parses all fields correctly', () { final json = { 'has_medical_education': 1, 'completed_courses': [ {'course1': {'date': '2024-01-01', 'title': 'Course 1'}}, ], 'vk_link': 'https://vk.com/user', 'insta_link': 'https://instagram.com/user', 'fb_link': 'https://facebook.com/user', 'tg_link': 'https://t.me/user', 'personal_site_link': 'https://example.com', 'request_state': 'approved', }; final model = EducationModel.fromJson(json); expect(model.hasMedicalEducation, 1); expect(model.completedCourses, isNotNull); expect(model.vkLink, 'https://vk.com/user'); expect(model.instaLink, 'https://instagram.com/user'); expect(model.fbLink, 'https://facebook.com/user'); expect(model.tgLink, 'https://t.me/user'); expect(model.personalSiteLink, 'https://example.com'); expect(model.requestState, ModerationStatus.approved); }); test('fromJson handles null optional fields', () { final json = { 'request_state': 'created', }; final model = EducationModel.fromJson(json); expect(model.hasMedicalEducation, isNull); expect(model.completedCourses, isNull); expect(model.vkLink, isNull); expect(model.requestState, ModerationStatus.created); }); test('toJson serializes all fields correctly', () { const model = EducationModel( hasMedicalEducation: 1, completedCourses: null, vkLink: 'https://vk.com/user', instaLink: 'https://instagram.com/user', fbLink: 'https://facebook.com/user', tgLink: 'https://t.me/user', personalSiteLink: 'https://example.com', requestState: ModerationStatus.approved, ); final json = model.toJson(); expect(json['has_medical_education'], 1); expect(json['vk_link'], 'https://vk.com/user'); expect(json['request_state'], 'approved'); }); }); group('ProfileDetailsModel', () { test('fromJson parses all fields correctly', () { final json = { 'first_name': 'John', 'last_name': 'Doe', 'birthdate': '1990-01-01', 'gender': 'male', 'country': 'Russia', 'city': 'Moscow', 'lang': 'ru', 'weight': 75.5, 'height': 175, 'chest_circumference': 100, 'waist_circumference': 80, 'hip_circumference': 95, 'blood_pressure_up': 120, 'blood_pressure_down': 80, 'has_hypo': false, 'has_hyper': false, 'about_alergy': 'No allergies', 'about_taking_pils': 'No pills', 'about_sport_hobbies': 'Running', 'favorite_foods': 'Pizza', 'unfavorite_foods': 'Broccoli', 'additional_info': 'Additional info', 'created_at': '2024-01-01T00:00:00Z', 'updated_at': '2024-01-02T00:00:00Z', 'is_mood_fillable': true, 'is_bedtime_fillable': true, 'activity_coefficient': 1.5, }; final model = ProfileDetailsModel.fromJson(json); expect(model.firstName, 'John'); expect(model.lastName, 'Doe'); expect(model.birthdate, '1990-01-01'); expect(model.gender, 'male'); expect(model.country, 'Russia'); expect(model.city, 'Moscow'); expect(model.lang, 'ru'); expect(model.weight, 75.5); expect(model.height, 175); expect(model.chestCircumference, 100); expect(model.waistCircumference, 80); expect(model.hipCircumference, 95); expect(model.bloodPressureUp, 120); expect(model.bloodPressureDown, 80); expect(model.hasHypo, isFalse); expect(model.hasHyper, isFalse); expect(model.aboutAlergy, 'No allergies'); expect(model.aboutTakingPils, 'No pills'); expect(model.aboutSportHobbies, 'Running'); expect(model.favoriteFoods, 'Pizza'); expect(model.unfavoriteFoods, 'Broccoli'); expect(model.additionalInfo, 'Additional info'); expect(model.isMoodFillable, isTrue); expect(model.isBedtimeFillable, isTrue); expect(model.activityCoefficient, 1.5); }); test('toJson serializes all fields correctly', () { final model = ProfileDetailsModel( firstName: 'John', lastName: 'Doe', birthdate: '1990-01-01', gender: 'male', country: 'Russia', city: 'Moscow', lang: 'ru', weight: 75.5, height: 175, chestCircumference: 100, waistCircumference: 80, hipCircumference: 95, bloodPressureUp: 120, bloodPressureDown: 80, hasHypo: false, hasHyper: false, aboutAlergy: 'No allergies', aboutTakingPils: 'No pills', aboutSportHobbies: 'Running', favoriteFoods: 'Pizza', unfavoriteFoods: 'Broccoli', additionalInfo: 'Additional info', createdAt: DateTime(2024, 1, 1), updatedAt: DateTime(2024, 1, 2), isMoodFillable: true, isBedtimeFillable: true, activityCoefficient: 1.5, ); final json = model.toJson(); expect(json['first_name'], 'John'); expect(json['last_name'], 'Doe'); expect(json['birthdate'], '1990-01-01'); expect(json['gender'], 'male'); expect(json['weight'], 75.5); expect(json['height'], 175); expect(json['is_mood_fillable'], isTrue); expect(json['activity_coefficient'], 1.5); }); }); group('ProfilePreviewModel', () { test('fromJson parses profilePhotoUrl correctly', () { final json = {'profile_photo_url': 'https://example.com/photo.jpg'}; final model = ProfilePreviewModel.fromJson(json); expect(model.profilePhotoUrl, 'https://example.com/photo.jpg'); }); test('toJson serializes profilePhotoUrl correctly', () { const model = ProfilePreviewModel(profilePhotoUrl: 'https://example.com/photo.jpg'); final json = model.toJson(); expect(json['profile_photo_url'], 'https://example.com/photo.jpg'); }); test('creates instance with profilePhotoUrl', () { const model = ProfilePreviewModel(profilePhotoUrl: 'https://example.com/photo2.jpg'); expect(model.profilePhotoUrl, 'https://example.com/photo2.jpg'); }); }); group('ProfileModel', () { test('fromJson parses all fields correctly', () { final json = { 'id': 1, 'name': 'John Doe', 'email': 'john@example.com', 'rating_place': 5, 'email_verified_at': '2024-01-01T00:00:00Z', 'phone_confirmation_state': 'confirmed', 'created_at': '2024-01-01T00:00:00Z', 'updated_at': '2024-01-02T00:00:00Z', 'is_public_profile': true, 'is_blocked_by_me': false, 'is_blocked_by_author': false, 'is_blocked_by_user': false, 'is_entity_subscribed_by_me': false, 'slug': 'john-doe', 'profile_photo_url': 'https://example.com/photo.jpg', 'roles': ['user'], 'badges': [ { 'id': 1, 'title': 'Badge 1', 'description': 'Description', 'image': 'https://example.com/badge1.jpg', 'type': 'type', }, ], 'subscriptions': ['user1', 'user2'], 'subscribers': ['user3'], 'education_resource': null, 'cert_photos': null, }; final model = ProfileModel.fromJson(json); expect(model.id, 1); expect(model.name, 'John Doe'); expect(model.email, 'john@example.com'); expect(model.ratingPlace, 5); expect(model.phoneConfirmationState, 'confirmed'); expect(model.isPublicProfile, isTrue); expect(model.slug, 'john-doe'); expect(model.roles.length, 1); expect(model.badges.length, 1); }); test('fromJson handles null optional fields', () { final json = { 'id': 1, 'name': 'John Doe', 'email': 'john@example.com', 'phone_confirmation_state': 'confirmed', 'is_public_profile': false, 'is_blocked_by_me': false, 'is_blocked_by_author': false, 'is_blocked_by_user': false, 'is_entity_subscribed_by_me': false, 'slug': 'john-doe', 'profile_photo_url': '', 'roles': [], 'badges': [], 'subscriptions': [], 'subscribers': [], }; final model = ProfileModel.fromJson(json); expect(model.ratingPlace, isNull); expect(model.emailVerifiedAt, isNull); expect(model.educationResource, isNull); expect(model.diplomasAndCertificates, isNull); }); test('toJson serializes ProfileModel correctly', () { const model = ProfileModel( id: 1, name: 'John Doe', email: 'john@example.com', ratingPlace: 5, emailVerifiedAt: null, phoneConfirmationState: 'confirmed', createdAt: null, updatedAt: null, isPublicProfile: true, isBlockedByMe: false, isBlockedByAuthor: false, isBlockedByUser: false, isEntitySubscribedByMe: false, slug: 'john-doe', profilePhotoUrl: 'https://example.com/photo.jpg', roles: ['user'], badges: [], subscriptions: [], subscribers: [], educationResource: null, diplomasAndCertificates: null, ); final json = model.toJson(); expect(json['id'], 1); expect(json['name'], 'John Doe'); expect(json['email'], 'john@example.com'); expect(json['rating_place'], 5); expect(json['phone_confirmation_state'], 'confirmed'); expect(json['is_public_profile'], isTrue); expect(json['slug'], 'john-doe'); }); }); group('DiplomasAndCertificatesModel', () { test('fromJson parses all fields correctly', () { final json = { 'id': 1, 'path': 'https://example.com/cert.jpg', }; final model = DiplomasAndCertificatesModel.fromJson(json); expect(model.id, 1); expect(model.path, 'https://example.com/cert.jpg'); }); test('toJson serializes DiplomasAndCertificatesModel correctly', () { const model = DiplomasAndCertificatesModel( id: 1, path: 'https://example.com/cert.jpg', ); final json = model.toJson(); expect(json['id'], 1); expect(json['path'], 'https://example.com/cert.jpg'); }); }); }