forked from eatvio/eatvio_app
feat(tests): updated tests coverage to 66.5%
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
import 'package:eatvio_app/features/consultant/become_consultant/models/consultant_cert_photo_model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('ConsultantCertPhotoModel', () {
|
||||
test('fromJson parses all fields correctly', () {
|
||||
final json = {
|
||||
'id': 1,
|
||||
'user_id': 100,
|
||||
'group': 'user_certs',
|
||||
'original_name': 'certificate.jpg',
|
||||
'path': '/path/to/certificate.jpg',
|
||||
'size': 1024,
|
||||
'specs': {'width': 800, 'height': 600},
|
||||
'url': 'https://example.com/certificate.jpg',
|
||||
};
|
||||
|
||||
final model = ConsultantCertPhotoModel.fromJson(json);
|
||||
|
||||
expect(model.id, 1);
|
||||
expect(model.userId, 100);
|
||||
expect(model.group, 'user_certs');
|
||||
expect(model.originalName, 'certificate.jpg');
|
||||
expect(model.path, '/path/to/certificate.jpg');
|
||||
expect(model.size, 1024);
|
||||
expect(model.specs, {'width': 800, 'height': 600});
|
||||
expect(model.url, 'https://example.com/certificate.jpg');
|
||||
});
|
||||
|
||||
test('fromJson handles optional fields', () {
|
||||
final json = {
|
||||
'id': 1,
|
||||
'group': 'user_certs',
|
||||
'original_name': 'certificate.jpg',
|
||||
'path': '/path/to/certificate.jpg',
|
||||
'size': 1024,
|
||||
'url': 'https://example.com/certificate.jpg',
|
||||
};
|
||||
|
||||
final model = ConsultantCertPhotoModel.fromJson(json);
|
||||
|
||||
expect(model.id, 1);
|
||||
expect(model.userId, isNull);
|
||||
expect(model.specs, isNull);
|
||||
});
|
||||
|
||||
test('toJson serializes all fields correctly', () {
|
||||
const model = ConsultantCertPhotoModel(
|
||||
id: 1,
|
||||
userId: 100,
|
||||
group: 'user_certs',
|
||||
originalName: 'certificate.jpg',
|
||||
path: '/path/to/certificate.jpg',
|
||||
size: 1024,
|
||||
specs: {'width': 800, 'height': 600},
|
||||
url: 'https://example.com/certificate.jpg',
|
||||
);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json['id'], 1);
|
||||
expect(json['user_id'], 100);
|
||||
expect(json['group'], 'user_certs');
|
||||
expect(json['original_name'], 'certificate.jpg');
|
||||
expect(json['path'], '/path/to/certificate.jpg');
|
||||
expect(json['size'], 1024);
|
||||
expect(json['specs'], {'width': 800, 'height': 600});
|
||||
expect(json['url'], 'https://example.com/certificate.jpg');
|
||||
});
|
||||
|
||||
test('isHidden returns true for hidden group', () {
|
||||
const hiddenModel = ConsultantCertPhotoModel(
|
||||
id: 1,
|
||||
group: ConsultantCertPhotoModel.hiddenGroup,
|
||||
originalName: 'cert.jpg',
|
||||
path: '/path',
|
||||
size: 1024,
|
||||
url: 'https://example.com/cert.jpg',
|
||||
);
|
||||
|
||||
expect(hiddenModel.isHidden, isTrue);
|
||||
});
|
||||
|
||||
test('isHidden returns false for visible group', () {
|
||||
const visibleModel = ConsultantCertPhotoModel(
|
||||
id: 1,
|
||||
group: ConsultantCertPhotoModel.visibleGroup,
|
||||
originalName: 'cert.jpg',
|
||||
path: '/path',
|
||||
size: 1024,
|
||||
url: 'https://example.com/cert.jpg',
|
||||
);
|
||||
|
||||
expect(visibleModel.isHidden, isFalse);
|
||||
});
|
||||
|
||||
test('constants are defined correctly', () {
|
||||
expect(ConsultantCertPhotoModel.visibleGroup, 'user_certs');
|
||||
expect(ConsultantCertPhotoModel.hiddenGroup, 'hidden_user_certs');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,119 @@
|
||||
import 'package:eatvio_app/features/consultant/become_consultant/models/consultant_profile_model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('SocialLinksModel', () {
|
||||
test('fromJson parses all fields correctly', () {
|
||||
final json = {
|
||||
'vk_link': 'https://vk.com/user',
|
||||
'tg_link': 'https://t.me/user',
|
||||
'fb_link': 'https://facebook.com/user',
|
||||
'insta_link': 'https://instagram.com/user',
|
||||
'personal_site_link': 'https://example.com',
|
||||
};
|
||||
|
||||
final model = SocialLinksModel.fromJson(json);
|
||||
|
||||
expect(model.vkLink, 'https://vk.com/user');
|
||||
expect(model.tgLink, 'https://t.me/user');
|
||||
expect(model.fbLink, 'https://facebook.com/user');
|
||||
expect(model.instaLink, 'https://instagram.com/user');
|
||||
expect(model.personalSiteLink, 'https://example.com');
|
||||
});
|
||||
|
||||
test('fromJson handles null fields', () {
|
||||
final json = <String, dynamic>{};
|
||||
|
||||
final model = SocialLinksModel.fromJson(json);
|
||||
|
||||
expect(model.vkLink, isNull);
|
||||
expect(model.tgLink, isNull);
|
||||
expect(model.fbLink, isNull);
|
||||
expect(model.instaLink, isNull);
|
||||
expect(model.personalSiteLink, isNull);
|
||||
});
|
||||
|
||||
test('toJson serializes all fields correctly', () {
|
||||
const model = SocialLinksModel(
|
||||
vkLink: 'https://vk.com/user',
|
||||
tgLink: 'https://t.me/user',
|
||||
fbLink: 'https://facebook.com/user',
|
||||
instaLink: 'https://instagram.com/user',
|
||||
personalSiteLink: 'https://example.com',
|
||||
);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json['vk_link'], 'https://vk.com/user');
|
||||
expect(json['tg_link'], 'https://t.me/user');
|
||||
expect(json['fb_link'], 'https://facebook.com/user');
|
||||
expect(json['insta_link'], 'https://instagram.com/user');
|
||||
expect(json['personal_site_link'], 'https://example.com');
|
||||
});
|
||||
});
|
||||
|
||||
group('CertificatesModel', () {
|
||||
test('fromJson parses all fields correctly', () {
|
||||
final json = {'title': 'Certificate Title', 'date': '2024-01-15'};
|
||||
|
||||
final model = CertificatesModel.fromJson(json);
|
||||
|
||||
expect(model.title, 'Certificate Title');
|
||||
expect(model.date, '2024-01-15');
|
||||
});
|
||||
|
||||
test('toJson serializes all fields correctly', () {
|
||||
const model = CertificatesModel(title: 'Certificate Title', date: '2024-01-15');
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json['title'], 'Certificate Title');
|
||||
expect(json['date'], '2024-01-15');
|
||||
});
|
||||
});
|
||||
|
||||
group('ConsultantProfileModel', () {
|
||||
test('fromJson parses all fields correctly', () {
|
||||
final json = {
|
||||
'has_medical_education': true,
|
||||
'social_links': {'vk_link': 'https://vk.com/user'},
|
||||
'cert_photos': ['photo1.jpg', 'photo2.jpg'],
|
||||
'completed_courses': [
|
||||
{'title': 'Course 1', 'date': '2024-01-01'},
|
||||
],
|
||||
};
|
||||
|
||||
final model = ConsultantProfileModel.fromJson(json);
|
||||
|
||||
expect(model.hasMedicalEducation, isTrue);
|
||||
expect(model.socialLinks, isNotNull);
|
||||
expect(model.photos, ['photo1.jpg', 'photo2.jpg']);
|
||||
expect(model.certificates, isNotNull);
|
||||
expect(model.certificates?.length, 1);
|
||||
});
|
||||
|
||||
test('fromJson handles null fields', () {
|
||||
final json = <String, dynamic>{};
|
||||
|
||||
final model = ConsultantProfileModel.fromJson(json);
|
||||
|
||||
expect(model.hasMedicalEducation, isNull);
|
||||
expect(model.socialLinks, isNull);
|
||||
expect(model.photos, isNull);
|
||||
expect(model.certificates, isNull);
|
||||
});
|
||||
|
||||
test('toJson serializes all fields correctly', () {
|
||||
const socialLinks = SocialLinksModel(vkLink: 'https://vk.com/user');
|
||||
const certificates = CertificatesModel(title: 'Course 1', date: '2024-01-01');
|
||||
const model = ConsultantProfileModel(hasMedicalEducation: true, socialLinks: socialLinks, photos: ['photo1.jpg'], certificates: [certificates]);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json['has_medical_education'], isTrue);
|
||||
expect(json['social_links'], isNotNull);
|
||||
expect(json['cert_photos'], ['photo1.jpg']);
|
||||
expect(json['completed_courses'], isNotNull);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
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('CertPhotosModel', () {
|
||||
test('fromJson parses url correctly', () {
|
||||
final json = {'url': 'https://example.com/photo.jpg'};
|
||||
|
||||
final model = CertPhotosModel.fromJson(json);
|
||||
|
||||
expect(model.url, 'https://example.com/photo.jpg');
|
||||
});
|
||||
|
||||
test('toJson serializes url correctly', () {
|
||||
const model = CertPhotosModel(url: 'https://example.com/photo.jpg');
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json['url'], 'https://example.com/photo.jpg');
|
||||
});
|
||||
});
|
||||
|
||||
group('ModerationStatus enum', () {
|
||||
test('has all expected values', () {
|
||||
expect(ModerationStatus.values.length, 3);
|
||||
expect(ModerationStatus.approved, isNotNull);
|
||||
expect(ModerationStatus.created, isNotNull);
|
||||
expect(ModerationStatus.canceled, isNotNull);
|
||||
});
|
||||
});
|
||||
|
||||
group('CanceledModerationModel', () {
|
||||
test('fromJson parses all fields correctly', () {
|
||||
final json = {
|
||||
'title': 'Test title',
|
||||
'status': 'canceled',
|
||||
'additional': ['reason1', 'reason2'],
|
||||
};
|
||||
|
||||
final model = CanceledModerationModel.fromJson(json);
|
||||
|
||||
expect(model.title, 'Test title');
|
||||
expect(model.status, ModerationStatus.canceled);
|
||||
expect(model.additional, ['reason1', 'reason2']);
|
||||
});
|
||||
|
||||
test('fromJson handles null additional field', () {
|
||||
final json = {'title': 'Test title', 'status': 'canceled', 'additional': null};
|
||||
|
||||
final model = CanceledModerationModel.fromJson(json);
|
||||
|
||||
expect(model.title, 'Test title');
|
||||
expect(model.status, ModerationStatus.canceled);
|
||||
expect(model.additional, isNull);
|
||||
});
|
||||
|
||||
test('toJson serializes all fields correctly', () {
|
||||
const model = CanceledModerationModel(title: 'Test title', status: ModerationStatus.canceled, additional: ['reason1', 'reason2']);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json['title'], 'Test title');
|
||||
expect(json['status'], 'canceled');
|
||||
expect(json['additional'], ['reason1', 'reason2']);
|
||||
});
|
||||
});
|
||||
|
||||
group('ConsultationRequestModel', () {
|
||||
test('fromJson parses all fields correctly', () {
|
||||
final json = {
|
||||
'rating_place': 5,
|
||||
'education_resource': {'request_state': 'approved'},
|
||||
'cert_photos': [
|
||||
{'url': 'https://example.com/photo1.jpg'},
|
||||
{'url': 'https://example.com/photo2.jpg'},
|
||||
],
|
||||
'canceled_moderation': null,
|
||||
};
|
||||
|
||||
final model = ConsultationRequestModel.fromJson(json);
|
||||
|
||||
expect(model.ratingPlace, 5);
|
||||
expect(model.educationModel.requestState, ModerationStatus.approved);
|
||||
expect(model.photos.length, 2);
|
||||
expect(model.photos[0].url, 'https://example.com/photo1.jpg');
|
||||
expect(model.canceledModeration, isNull);
|
||||
});
|
||||
|
||||
test('fromJson handles null ratingPlace and canceledModeration', () {
|
||||
final json = {
|
||||
'education_resource': {'request_state': 'created'},
|
||||
'cert_photos': [],
|
||||
};
|
||||
|
||||
final model = ConsultationRequestModel.fromJson(json);
|
||||
|
||||
expect(model.ratingPlace, isNull);
|
||||
expect(model.canceledModeration, isNull);
|
||||
expect(model.photos, isEmpty);
|
||||
});
|
||||
|
||||
test('fromJson handles canceledModeration', () {
|
||||
final json = {
|
||||
'rating_place': 10,
|
||||
'education_resource': {'request_state': 'canceled'},
|
||||
'cert_photos': [
|
||||
{'url': 'https://example.com/photo.jpg'},
|
||||
],
|
||||
'canceled_moderation': {
|
||||
'title': 'Rejected',
|
||||
'status': 'canceled',
|
||||
'additional': ['reason1'],
|
||||
},
|
||||
};
|
||||
|
||||
final model = ConsultationRequestModel.fromJson(json);
|
||||
|
||||
expect(model.ratingPlace, 10);
|
||||
expect(model.canceledModeration, isNotNull);
|
||||
expect(model.canceledModeration!.title, 'Rejected');
|
||||
expect(model.canceledModeration!.status, ModerationStatus.canceled);
|
||||
});
|
||||
|
||||
test('toJson serializes ConsultationRequestModel correctly', () {
|
||||
const educationModel = EducationModel(requestState: ModerationStatus.approved);
|
||||
const photos = [CertPhotosModel(url: 'https://example.com/photo1.jpg'), CertPhotosModel(url: 'https://example.com/photo2.jpg')];
|
||||
const model = ConsultationRequestModel(ratingPlace: 5, educationModel: educationModel, photos: photos, canceledModeration: null);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json['rating_place'], 5);
|
||||
expect(json.containsKey('education_resource'), isTrue);
|
||||
expect(json.containsKey('cert_photos'), isTrue);
|
||||
expect((json['cert_photos'] as List).length, 2);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
import 'package:eatvio_app/features/consultant/become_consultant/models/consultant_cert_photo_model.dart';
|
||||
import 'package:eatvio_app/features/consultant/become_consultant/models/consultant_profile_model.dart';
|
||||
import 'package:eatvio_app/features/consultant/become_consultant/presentation/bloc/register_consultant_cubit/register_consultant_state.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('RegisterConsultantState', () {
|
||||
test('creates instance with default values', () {
|
||||
const consultant = ConsultantProfileModel();
|
||||
const state = RegisterConsultantState(
|
||||
consultant: consultant,
|
||||
acceptOffer: false,
|
||||
loading: false,
|
||||
requestModel: null,
|
||||
);
|
||||
|
||||
expect(state.consultant, consultant);
|
||||
expect(state.acceptOffer, false);
|
||||
expect(state.loading, false);
|
||||
expect(state.requestModel, isNull);
|
||||
expect(state.certPhotos, isEmpty);
|
||||
});
|
||||
|
||||
test('creates instance with custom values', () {
|
||||
const consultant = ConsultantProfileModel();
|
||||
const certPhoto = ConsultantCertPhotoModel(
|
||||
id: 1,
|
||||
group: 'user_certs',
|
||||
originalName: 'photo.jpg',
|
||||
path: '/path/to/photo.jpg',
|
||||
size: 1024,
|
||||
url: 'https://example.com/photo.jpg',
|
||||
);
|
||||
const state = RegisterConsultantState(
|
||||
consultant: consultant,
|
||||
acceptOffer: true,
|
||||
loading: true,
|
||||
requestModel: null,
|
||||
certPhotos: [certPhoto],
|
||||
);
|
||||
|
||||
expect(state.acceptOffer, true);
|
||||
expect(state.loading, true);
|
||||
expect(state.certPhotos.length, 1);
|
||||
expect(state.certPhotos.first.url, 'https://example.com/photo.jpg');
|
||||
});
|
||||
|
||||
test('copyWith creates new instance with updated values', () {
|
||||
const consultant = ConsultantProfileModel();
|
||||
const originalState = RegisterConsultantState(
|
||||
consultant: consultant,
|
||||
acceptOffer: false,
|
||||
loading: false,
|
||||
requestModel: null,
|
||||
);
|
||||
|
||||
final updatedState = originalState.copyWith(
|
||||
acceptOffer: true,
|
||||
loading: true,
|
||||
);
|
||||
|
||||
expect(updatedState.acceptOffer, true);
|
||||
expect(updatedState.loading, true);
|
||||
expect(updatedState.consultant, originalState.consultant);
|
||||
expect(updatedState.requestModel, originalState.requestModel);
|
||||
});
|
||||
|
||||
test('copyWith updates certPhotos', () {
|
||||
const consultant = ConsultantProfileModel();
|
||||
const certPhoto1 = ConsultantCertPhotoModel(
|
||||
id: 1,
|
||||
group: 'user_certs',
|
||||
originalName: 'photo1.jpg',
|
||||
path: '/path/to/photo1.jpg',
|
||||
size: 1024,
|
||||
url: 'https://example.com/photo1.jpg',
|
||||
);
|
||||
const certPhoto2 = ConsultantCertPhotoModel(
|
||||
id: 2,
|
||||
group: 'user_certs',
|
||||
originalName: 'photo2.jpg',
|
||||
path: '/path/to/photo2.jpg',
|
||||
size: 2048,
|
||||
url: 'https://example.com/photo2.jpg',
|
||||
);
|
||||
const originalState = RegisterConsultantState(
|
||||
consultant: consultant,
|
||||
acceptOffer: false,
|
||||
loading: false,
|
||||
requestModel: null,
|
||||
certPhotos: [certPhoto1],
|
||||
);
|
||||
|
||||
final updatedState = originalState.copyWith(
|
||||
certPhotos: [certPhoto1, certPhoto2],
|
||||
);
|
||||
|
||||
expect(updatedState.certPhotos.length, 2);
|
||||
expect(updatedState.certPhotos.first.url, 'https://example.com/photo1.jpg');
|
||||
expect(updatedState.certPhotos.last.url, 'https://example.com/photo2.jpg');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -126,5 +126,19 @@ void main() {
|
||||
verify(() => repository.hideConsultantCertPhoto(101)).called(1);
|
||||
expect(cubit.state.certPhotos.any((photo) => photo.id == 101), isFalse);
|
||||
});
|
||||
|
||||
test('uploadCertPhotos - не загружает если список пуст', () async {
|
||||
await cubit.uploadCertPhotos([]);
|
||||
|
||||
verifyNever(() => repository.storeConsultantCertPhotos(files: any(named: 'files')));
|
||||
});
|
||||
|
||||
test('updateConsultantProfileModel - обновляет без acceptOffer', () {
|
||||
cubit.updateConsultantProfileModel(consultantProfile);
|
||||
|
||||
expect(cubit.state.consultant, consultantProfile);
|
||||
expect(cubit.state.acceptOffer, isFalse);
|
||||
expect(cubit.state.loading, isFalse);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user