feat(tests): updated tests coverage to 66.5%

This commit is contained in:
misha
2026-01-14 18:47:11 +03:00
parent 497ff19cfa
commit 13ccf56df0
102 changed files with 10146 additions and 379 deletions

View File

@@ -3,205 +3,107 @@ import 'package:eatvio_app/features/plans/enums/chosen_plan_state_enum.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('ConsultationModel', () {
test('creates ConsultationModel with all parameters', () {
final diaries = [
DiaryModel(
id: 1,
state: DiaryStateEnum.started,
date: DateTime(2023, 1, 1),
),
DiaryModel(
id: 2,
state: DiaryStateEnum.finished,
date: DateTime(2023, 1, 2),
),
];
final model = ConsultationModel(
id: 1,
chosenPlanState: ChosenPlanStateEnum.stateInProgress,
planTitle: 'Weight Loss Plan',
userName: 'John Doe',
userSlug: 'john-doe',
consultantPayment: 100.0,
duration: 30,
currentDiaryDay: 5,
userProfilePhotoUrl: 'photo.jpg',
consultationOptionPrice: 50,
startDate: DateTime(2023, 1, 1),
endDate: DateTime(2023, 1, 31),
consultantId: 10,
diaries: diaries,
personalDietId: 5,
);
expect(model.id, 1);
expect(model.chosenPlanState, ChosenPlanStateEnum.stateInProgress);
expect(model.planTitle, 'Weight Loss Plan');
expect(model.userName, 'John Doe');
expect(model.userSlug, 'john-doe');
expect(model.consultantPayment, 100.0);
expect(model.duration, 30);
expect(model.currentDiaryDay, 5);
expect(model.diaries.length, 2);
expect(model.personalDietId, 5);
});
test('creates ConsultationModel with null personalDietId', () {
final model = ConsultationModel(
id: 1,
chosenPlanState: ChosenPlanStateEnum.statePaid,
planTitle: 'Muscle Gain Plan',
userName: 'Jane Smith',
userSlug: 'jane-smith',
consultantPayment: 150.0,
duration: 60,
currentDiaryDay: 10,
userProfilePhotoUrl: 'photo2.jpg',
consultationOptionPrice: 75,
startDate: DateTime(2023, 2, 1),
endDate: DateTime(2023, 3, 31),
consultantId: 11,
diaries: [],
personalDietId: null,
);
expect(model.personalDietId, null);
});
test('creates ConsultationModel from JSON', () {
final json = {
'id': 1,
'last_state': 'in_progress',
'plan_title': 'Weight Loss Plan',
'user_name': 'John Doe',
'user_slug': 'john-doe',
'consultant_payment': 100.0,
'duration': 30,
'current_diary_day': 5,
'user_profile_photo_url': 'photo.jpg',
'consultation_option_price': 50,
'start_date': '2023-01-01T00:00:00Z',
'end_date': '2023-01-31T00:00:00Z',
'consultant_id': 10,
'diaries': [
{
'id': 1,
'state': 'started',
'date': '2023-01-01',
},
],
'personal_diet_id': 5,
};
final model = ConsultationModel.fromJson(json);
expect(model.id, 1);
expect(model.planTitle, 'Weight Loss Plan');
expect(model.diaries.length, 1);
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('creates DiaryModel with all parameters', () {
final model = DiaryModel(
id: 1,
state: DiaryStateEnum.started,
date: DateTime(2023, 1, 1),
);
expect(model.id, 1);
expect(model.state, DiaryStateEnum.started);
expect(model.date, DateTime(2023, 1, 1));
});
test('creates DiaryModel with different states', () {
final states = [
DiaryStateEnum.init,
DiaryStateEnum.started,
DiaryStateEnum.finished,
DiaryStateEnum.commented,
DiaryStateEnum.reviewedByUser,
];
for (var state in states) {
final model = DiaryModel(
id: 1,
state: state,
date: DateTime(2023, 1, 1),
);
expect(model.state, state);
}
});
test('creates DiaryModel from JSON', () {
test('fromJson parses all fields correctly', () {
final json = {
'id': 1,
'state': 'started',
'date': '2023-01-01',
'date': '2024-01-15',
};
final model = DiaryModel.fromJson(json);
expect(model.id, 1);
expect(model.state, DiaryStateEnum.started);
expect(model.date, DateTime(2023, 1, 1));
expect(model.date, isA<DateTime>());
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<String>());
});
});
group('ConsultationPaginationModel', () {
test('creates ConsultationPaginationModel with empty list', () {
final model = ConsultationPaginationModel(data: []);
test('fromJson parses data correctly', () {
final json = {
'data': [],
};
final model = ConsultationPaginationModel.fromJson(json);
expect(model.data, isEmpty);
});
test('creates ConsultationPaginationModel with consultations', () {
final consultations = [
ConsultationModel(
id: 1,
chosenPlanState: ChosenPlanStateEnum.stateInProgress,
planTitle: 'Plan 1',
userName: 'User 1',
userSlug: 'user-1',
consultantPayment: 100.0,
duration: 30,
currentDiaryDay: 5,
userProfilePhotoUrl: 'photo1.jpg',
consultationOptionPrice: 50,
startDate: DateTime(2023, 1, 1),
endDate: DateTime(2023, 1, 31),
consultantId: 10,
diaries: [],
personalDietId: null,
),
];
final model = ConsultationPaginationModel(data: consultations);
expect(model.data.length, 1);
expect(model.data[0].id, 1);
});
test('creates ConsultationPaginationModel from JSON', () {
test('fromJson parses data with consultations', () {
final json = {
'data': [
{
'id': 1,
'last_state': 'in_progress',
'plan_title': 'Plan 1',
'last_state': 'started',
'plan_title': 'Test Plan',
'user_name': 'User 1',
'user_slug': 'user-1',
'consultant_payment': 100.0,
'consultant_payment': 1000.0,
'duration': 30,
'current_diary_day': 5,
'user_profile_photo_url': 'photo1.jpg',
'consultation_option_price': 50,
'start_date': '2023-01-01T00:00:00Z',
'end_date': '2023-01-31T00:00:00Z',
'consultant_id': 10,
'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,
},
@@ -211,8 +113,82 @@ void main() {
final model = ConsultationPaginationModel.fromJson(json);
expect(model.data.length, 1);
expect(model.data[0].id, 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<List>());
});
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);
});
});
}