forked from eatvio/eatvio_app
219 lines
6.1 KiB
Dart
219 lines
6.1 KiB
Dart
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('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('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', () {
|
|
final json = {
|
|
'id': 1,
|
|
'state': 'started',
|
|
'date': '2023-01-01',
|
|
};
|
|
|
|
final model = DiaryModel.fromJson(json);
|
|
|
|
expect(model.id, 1);
|
|
expect(model.state, DiaryStateEnum.started);
|
|
expect(model.date, DateTime(2023, 1, 1));
|
|
});
|
|
});
|
|
|
|
group('ConsultationPaginationModel', () {
|
|
test('creates ConsultationPaginationModel with empty list', () {
|
|
final model = ConsultationPaginationModel(data: []);
|
|
|
|
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', () {
|
|
final json = {
|
|
'data': [
|
|
{
|
|
'id': 1,
|
|
'last_state': 'in_progress',
|
|
'plan_title': 'Plan 1',
|
|
'user_name': 'User 1',
|
|
'user_slug': 'user-1',
|
|
'consultant_payment': 100.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,
|
|
'diaries': [],
|
|
'personal_diet_id': null,
|
|
},
|
|
],
|
|
};
|
|
|
|
final model = ConsultationPaginationModel.fromJson(json);
|
|
|
|
expect(model.data.length, 1);
|
|
expect(model.data[0].id, 1);
|
|
});
|
|
});
|
|
}
|
|
|