forked from eatvio/eatvio_app
feat(tests): updated tests coverage to 66.5%
This commit is contained in:
@@ -32,6 +32,24 @@ void main() {
|
||||
expect(model.id, 1);
|
||||
expect(model.title, 'Test Badge');
|
||||
});
|
||||
|
||||
test('toJson serializes BadgeModel correctly', () {
|
||||
const model = BadgeModel(
|
||||
id: 1,
|
||||
title: 'Test Badge',
|
||||
description: 'Test description',
|
||||
image: 'https://example.com/badge.jpg',
|
||||
type: 'achievement',
|
||||
);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json['id'], 1);
|
||||
expect(json['title'], 'Test Badge');
|
||||
expect(json['description'], 'Test description');
|
||||
expect(json['image'], 'https://example.com/badge.jpg');
|
||||
expect(json['type'], 'achievement');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -111,5 +111,58 @@ void main() {
|
||||
|
||||
expect(model.dietId, null);
|
||||
});
|
||||
|
||||
test('toJson serializes ChosenDietModel correctly', () {
|
||||
final model = ChosenDietModel(
|
||||
chosenDietID: 1,
|
||||
chosenPlanId: 10,
|
||||
state: 'active',
|
||||
startDate: DateTime(2023, 1, 1),
|
||||
dietId: 5,
|
||||
);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json['id'], 1);
|
||||
expect(json['chosen_plan_id'], 10);
|
||||
expect(json['state'], 'active');
|
||||
expect(json.containsKey('start_date'), isTrue);
|
||||
});
|
||||
|
||||
test('toJson serializes ChosenDietModel with null dietId correctly', () {
|
||||
final model = ChosenDietModel(
|
||||
chosenDietID: 1,
|
||||
chosenPlanId: 10,
|
||||
state: 'active',
|
||||
startDate: DateTime(2023, 1, 1),
|
||||
dietId: null,
|
||||
);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json['id'], 1);
|
||||
expect(json['diet'], isNull);
|
||||
});
|
||||
});
|
||||
|
||||
group('ChosenDietsPaginationModel toJson', () {
|
||||
test('toJson serializes ChosenDietsPaginationModel correctly', () {
|
||||
final diets = [
|
||||
ChosenDietModel(
|
||||
chosenDietID: 1,
|
||||
chosenPlanId: 10,
|
||||
state: 'active',
|
||||
startDate: DateTime(2023, 1, 1),
|
||||
dietId: 5,
|
||||
),
|
||||
];
|
||||
|
||||
final model = ChosenDietsPaginationModel(diets: diets);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json.containsKey('data'), isTrue);
|
||||
expect((json['data'] as List).length, 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
51
test/features/profile/models/circumference_model_test.dart
Normal file
51
test/features/profile/models/circumference_model_test.dart
Normal file
@@ -0,0 +1,51 @@
|
||||
import 'package:eatvio_app/features/profile/models/circumference_model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('CircumferenceModel', () {
|
||||
test('fromJson parses all fields correctly', () {
|
||||
final json = {
|
||||
'id': 1,
|
||||
'user_id': 123,
|
||||
'chest_circumference': 100,
|
||||
'waist_circumference': 80,
|
||||
'hip_circumference': 95,
|
||||
'created_at': '2024-01-15T10:00:00Z',
|
||||
'updated_at': '2024-01-16T10:00:00Z',
|
||||
};
|
||||
|
||||
final model = CircumferenceModel.fromJson(json);
|
||||
|
||||
expect(model.id, 1);
|
||||
expect(model.userId, 123);
|
||||
expect(model.chestCircumference, 100);
|
||||
expect(model.waistCircumference, 80);
|
||||
expect(model.hipCircumference, 95);
|
||||
expect(model.createdAt, isA<DateTime>());
|
||||
expect(model.updatedAt, isA<DateTime>());
|
||||
});
|
||||
|
||||
test('toJson serializes all fields correctly', () {
|
||||
final model = CircumferenceModel(
|
||||
id: 1,
|
||||
userId: 123,
|
||||
chestCircumference: 100,
|
||||
waistCircumference: 80,
|
||||
hipCircumference: 95,
|
||||
createdAt: DateTime(2024, 1, 15, 10, 0, 0),
|
||||
updatedAt: DateTime(2024, 1, 16, 10, 0, 0),
|
||||
);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json['id'], 1);
|
||||
expect(json['user_id'], 123);
|
||||
expect(json['chest_circumference'], 100);
|
||||
expect(json['waist_circumference'], 80);
|
||||
expect(json['hip_circumference'], 95);
|
||||
expect(json['created_at'], isA<String>());
|
||||
expect(json['updated_at'], isA<String>());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
355
test/features/profile/models/profile_models_test.dart
Normal file
355
test/features/profile/models/profile_models_test.dart
Normal file
@@ -0,0 +1,355 @@
|
||||
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');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -179,5 +179,74 @@ void main() {
|
||||
expect(sub.name, 'User One');
|
||||
expect(sub.isEntitySubscribedByMe, true);
|
||||
});
|
||||
|
||||
test('toJson serializes SubModel correctly', () {
|
||||
final sub = SubModel(
|
||||
slug: 'user1',
|
||||
name: 'User One',
|
||||
city: 'New York',
|
||||
birthdate: DateTime(1990, 1, 1),
|
||||
isEntitySubscribedByMe: true,
|
||||
profilePhotoUrl: 'photo1.jpg',
|
||||
roles: ['consultant'],
|
||||
);
|
||||
|
||||
final json = sub.toJson();
|
||||
|
||||
expect(json['slug'], 'user1');
|
||||
expect(json['name'], 'User One');
|
||||
expect(json['city'], 'New York');
|
||||
expect(json['is_entity_subscribed_by_me'], isTrue);
|
||||
expect(json['profile_photo_url'], 'photo1.jpg');
|
||||
expect(json['roles'], ['consultant']);
|
||||
expect(json.containsKey('birthdate'), isTrue);
|
||||
});
|
||||
});
|
||||
|
||||
group('SubPaginationModel', () {
|
||||
test('toJson serializes SubPaginationModel correctly', () {
|
||||
final subs = [
|
||||
SubModel(
|
||||
slug: 'user1',
|
||||
name: 'User One',
|
||||
city: 'New York',
|
||||
birthdate: DateTime(1990, 1, 1),
|
||||
isEntitySubscribedByMe: true,
|
||||
profilePhotoUrl: 'photo1.jpg',
|
||||
roles: ['consultant'],
|
||||
),
|
||||
];
|
||||
|
||||
const links = Links(
|
||||
first: 'http://example.com?page=1',
|
||||
last: 'http://example.com?page=1',
|
||||
prev: null,
|
||||
next: null,
|
||||
);
|
||||
|
||||
const meta = Meta(
|
||||
currentPage: 1,
|
||||
from: 1,
|
||||
lastPage: 1,
|
||||
links: [],
|
||||
path: '/api/subs',
|
||||
perPage: 10,
|
||||
to: 1,
|
||||
total: 1,
|
||||
);
|
||||
|
||||
final model = SubPaginationModel(
|
||||
data: subs,
|
||||
links: links,
|
||||
meta: meta,
|
||||
);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json.containsKey('data'), isTrue);
|
||||
expect((json['data'] as List).length, 1);
|
||||
expect(json.containsKey('links'), isTrue);
|
||||
expect(json.containsKey('meta'), isTrue);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
47
test/features/profile/models/weight_model_test.dart
Normal file
47
test/features/profile/models/weight_model_test.dart
Normal file
@@ -0,0 +1,47 @@
|
||||
import 'package:eatvio_app/features/profile/models/weight_model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('WeightModel', () {
|
||||
test('fromJson parses all fields correctly', () {
|
||||
final json = {
|
||||
'id': 1,
|
||||
'user_id': 123,
|
||||
'weight': 75,
|
||||
'created_at': '2024-01-15T10:00:00Z',
|
||||
'updated_at': '2024-01-16T10:00:00Z',
|
||||
'bmi': 22.5,
|
||||
};
|
||||
|
||||
final model = WeightModel.fromJson(json);
|
||||
|
||||
expect(model.id, 1);
|
||||
expect(model.userId, 123);
|
||||
expect(model.weight, 75);
|
||||
expect(model.createdAt, isA<DateTime>());
|
||||
expect(model.updatedAt, isA<DateTime>());
|
||||
expect(model.bmi, 22.5);
|
||||
});
|
||||
|
||||
test('toJson serializes all fields correctly', () {
|
||||
final model = WeightModel(
|
||||
id: 1,
|
||||
userId: 123,
|
||||
weight: 75,
|
||||
createdAt: DateTime(2024, 1, 15, 10, 0, 0),
|
||||
updatedAt: DateTime(2024, 1, 16, 10, 0, 0),
|
||||
bmi: 22.5,
|
||||
);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json['id'], 1);
|
||||
expect(json['user_id'], 123);
|
||||
expect(json['weight'], 75);
|
||||
expect(json['bmi'], 22.5);
|
||||
expect(json['created_at'], isA<String>());
|
||||
expect(json['updated_at'], isA<String>());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user