feat(consultant_scoring): adjusted data for new registration, added sbp banks endpoint

This commit is contained in:
misha
2026-07-22 17:58:02 +03:00
parent bd2de07b8f
commit 037f153273
23 changed files with 1514 additions and 279 deletions

View File

@@ -106,7 +106,17 @@ void main() {
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]);
const model = ConsultantProfileModel(
hasMedicalEducation: true,
socialLinks: socialLinks,
photos: ['photo1.jpg'],
certificates: [certificates],
legalType: 'individualPerson',
inn: '123456789012',
snils: '123-456-789 00',
agreementAccepted: true,
frdoAgreementAccepted: true,
);
final json = model.toJson();
@@ -114,6 +124,34 @@ void main() {
expect(json['social_links'], isNotNull);
expect(json['cert_photos'], ['photo1.jpg']);
expect(json['completed_courses'], isNotNull);
expect(json['legal_type'], 'individualPerson');
expect(json['inn'], '123456789012');
expect(json['snils'], '123-456-789 00');
expect(json['agreement_accepted'], isTrue);
expect(json['frdo_agreement_accepted'], isTrue);
});
test('hasValidPassportData validates required individualPerson fields', () {
const valid = ConsultantProfileModel(
lastName: 'Иванов',
firstName: 'Иван',
inn: '123456789012',
snils: '123-456-789 00',
passportSeries: '1234',
passportNumber: '567890',
passportIssueDate: '2020-01-15',
passportIssuer: 'ОВД',
passportIssuerCode: '772-053',
birthDate: '1990-05-20',
birthPlace: 'Москва',
registrationAddress: 'Адрес 1',
residenceAddress: 'Адрес 2',
citizenship: 'RU',
);
expect(valid.hasValidPassportData, isTrue);
expect(valid.copyWith(inn: '123').hasValidPassportData, isFalse);
expect(valid.copyWith(lastName: '').hasValidPassportData, isFalse);
});
});
}

View File

@@ -122,6 +122,47 @@ void main() {
expect(model.canceledModeration!.status, ModerationStatus.canceled);
});
test('fromJson parses legal_entity_resource', () {
final json = {
'rating_place': 5,
'education_resource': {'request_state': 'approved'},
'cert_photos': [],
'legal_entity_resource': {
'id': 1,
'type': 'individualPerson',
'inn': '123456789012',
'snils': '123-456-789 00',
'state': 'created',
'alfa_scoring_status': 'pending',
'alfa_scoring_request_id': 'abc',
'passport_series': '1234',
'passport_number': '567890',
'passport_issue_date': '2020-01-15T00:00:00.000000Z',
'passport_issuer': 'ОВД',
'passport_issuer_code': '772-053',
'birth_date': '1990-05-20',
'birth_place': 'Москва',
'registration_address': 'Адрес 1',
'residence_address': 'Адрес 2',
},
};
final model = ConsultationRequestModel.fromJson(json);
expect(model.legalEntity, isNotNull);
expect(model.legalEntity!.type, 'individualPerson');
expect(model.legalEntity!.inn, '123456789012');
expect(model.legalEntity!.passportSeries, '1234');
expect(model.legalEntity!.normalizedPassportIssueDate, '2020-01-15');
expect(model.legalEntity!.alfaScoringStatus, 'pending');
});
test('normalizeApiDate strips time from DateTime.toString format', () {
expect(LegalEntityModel.normalizeApiDate('2023-09-22 00:00:00.000'), '2023-09-22');
expect(LegalEntityModel.normalizeApiDate('2023-09-22'), '2023-09-22');
expect(LegalEntityModel.normalizeApiDate(null), isNull);
});
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')];

View File

@@ -1,6 +1,7 @@
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/models/consultation_request_model.dart';
import 'package:eatvio_app/features/consultant/become_consultant/models/sbp_bank_model.dart';
import 'package:eatvio_app/features/consultant/become_consultant/presentation/bloc/register_consultant_cubit/register_consultant_cubit.dart';
import 'package:eatvio_app/features/consultant/become_consultant/repositories/consultant_repository.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -23,6 +24,7 @@ void main() {
late RegisterConsultantCubit cubit;
late ConsultationRequestModel requestModel;
late List<ConsultantCertPhotoModel> certPhotosFromFixture;
late List<SbpBankModel> sbpBanksFromFixture;
late ConsultantProfileModel consultantProfile;
setUp(() {
@@ -32,7 +34,11 @@ void main() {
certPhotosFromFixture = FixtureReader.readAsList(
'consultant/consultant_cert_photos.json',
).map((item) => ConsultantCertPhotoModel.fromJson(item as Map<String, dynamic>)).toList();
sbpBanksFromFixture = FixtureReader.readAsList(
'consultant/sbp_banks.json',
).map((item) => SbpBankModel.fromJson(item as Map<String, dynamic>)).toList();
consultantProfile = ConsultantProfileModel.fromJson(FixtureReader.readAsMap('consultant/consultant_profile_request.json'));
when(() => repository.getSbpBanks()).thenAnswer((_) async => sbpBanksFromFixture);
});
tearDown(() async {
@@ -61,11 +67,19 @@ void main() {
expect(state.consultant.certificates!.first.title, 'Нутрициология PRO');
expect(state.consultant.socialLinks?.instaLink, isNull, reason: 'empty links are sanitized');
expect(state.consultant.socialLinks?.vkLink, 'https://vk.com/consultant');
expect(state.consultant.legalType, 'individualPerson');
expect(state.consultant.inn, '123456789012');
expect(state.consultant.passportSeries, '1234');
expect(state.consultant.passportIssueDate, '2020-01-15');
expect(state.consultant.birthPlace, 'г. Москва');
// All cert photos from backend are kept in state (visible + hidden).
expect(state.certPhotos, hasLength(3));
expect(state.certPhotos.map((e) => e.id), containsAll(<int>[101, 102, 103]));
expect(state.sbpBanks, hasLength(2));
expect(state.sbpBanks.first.bankName, 'Сбербанк');
verify(() => repository.getMyRequestStatus('my-consultant-slug')).called(1);
verify(() => repository.getConsultantCertPhotos()).called(1);
verify(() => repository.getSbpBanks()).called(1);
});
test('disableLoading stops spinner and loads cert photos', () async {
@@ -76,7 +90,28 @@ void main() {
expect(cubit.state.loading, isFalse);
// disableLoading now keeps all photos from repository.
expect(cubit.state.certPhotos, hasLength(3));
expect(cubit.state.sbpBanks, hasLength(2));
verify(() => repository.getConsultantCertPhotos()).called(1);
verify(() => repository.getSbpBanks()).called(1);
});
test('searchSbpBanks filters banks by name', () async {
when(() => repository.getConsultantCertPhotos()).thenAnswer((_) async => certPhotosFromFixture);
await cubit.disableLoading();
final results = cubit.searchSbpBanks('сбер');
expect(results, hasLength(1));
expect(results.first.bankMemberId, '100000000111');
});
test('findSbpBankById returns matching bank', () async {
when(() => repository.getConsultantCertPhotos()).thenAnswer((_) async => certPhotosFromFixture);
await cubit.disableLoading();
final bank = cubit.findSbpBankById('100000000004');
expect(bank?.bankName, 'Т-Банк');
});
test('updateConsultantProfileModel replaces consultant data and offer flag', () {
@@ -95,12 +130,24 @@ void main() {
),
).thenAnswer((_) async {});
cubit.updateConsultantProfileModel(consultantProfile);
cubit.updateAgreements(acceptOffer: true, acceptFrdoAgreement: true);
await cubit.registerConsultant();
verify(() => repository.registerConsultant(consultant: cubit.state.consultant, update: false)).called(1);
final captured = verify(
() => repository.registerConsultant(
consultant: captureAny<ConsultantProfileModel>(named: 'consultant'),
update: false,
),
).captured.single as ConsultantProfileModel;
expect(captured.legalType, 'individualPerson');
expect(captured.agreementAccepted, isTrue);
expect(captured.frdoAgreementAccepted, isTrue);
expect(captured.inn, isNotNull);
});
test('registerConsultant sends update=true after getMyRequestStatus call', () async {
test('registerConsultant sends legal payload with update=true', () async {
when(() => repository.getMyRequestStatus(any<String>())).thenAnswer((_) async => requestModel);
when(() => repository.getConsultantCertPhotos()).thenAnswer((_) async => certPhotosFromFixture);
when(
@@ -113,7 +160,38 @@ void main() {
await cubit.getMyRequestStatus('my-consultant-slug');
await cubit.registerConsultant();
verify(() => repository.registerConsultant(consultant: cubit.state.consultant, update: true)).called(1);
final captured = verify(
() => repository.registerConsultant(
consultant: captureAny<ConsultantProfileModel>(named: 'consultant'),
update: true,
),
).captured.single as ConsultantProfileModel;
final json = captured.toJson();
expect(json['legal_type'], 'individualPerson');
expect(json['inn'], '123456789012');
expect(json['passport_series'], '1234');
expect(json.containsKey('agreement_accepted'), isFalse);
expect(json.containsKey('frdo_agreement_accepted'), isFalse);
});
test('registerConsultant blocks submit without passport data', () async {
when(
() => repository.registerConsultant(
consultant: any<ConsultantProfileModel>(named: 'consultant'),
update: any<bool>(named: 'update'),
),
).thenAnswer((_) async {});
await cubit.registerConsultant();
expect(cubit.state.error, 'Заполните паспортные данные');
verifyNever(
() => repository.registerConsultant(
consultant: any<ConsultantProfileModel>(named: 'consultant'),
update: any<bool>(named: 'update'),
),
);
});
test('removeCertPhoto marks cert as deleted locally', () async {

View File

@@ -36,7 +36,7 @@ void main() {
);
}
testWidgets('renders last step screen', (tester) async {
testWidgets('renders last step screen with both agreements for new registration', (tester) async {
final cubit = MockRegisterConsultantCubit();
const consultant = ConsultantProfileModel(
hasMedicalEducation: null,
@@ -49,13 +49,30 @@ void main() {
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
when(cubit.updateConsultantProfileModel(any, any)).thenReturn(null);
await tester.pumpWidget(wrap(const LastStepScreen(), cubit));
await tester.pump();
expect(find.byType(LastStepScreen), findsOneWidget);
expect(find.text('Последний шаг'), findsOneWidget);
expect(find.byType(CheckboxListTile), findsNWidgets(2));
expect(find.textContaining('ФРДО'), findsOneWidget);
});
testWidgets('hides FRDO checkbox in update mode', (tester) async {
final cubit = MockRegisterConsultantCubit();
const consultant = ConsultantProfileModel();
const state = RegisterConsultantState(consultant: consultant, acceptOffer: false, loading: false, isUpdating: true);
when(cubit.state).thenReturn(state);
when(cubit.stream).thenAnswer((_) => Stream.value(state));
when(cubit.close()).thenAnswer((_) async => Future<void>.value());
await tester.pumpWidget(wrap(const LastStepScreen(), cubit));
await tester.pump();
expect(find.byType(CheckboxListTile), findsOneWidget);
expect(find.textContaining('ФРДО'), findsNothing);
});
});
}

View File

@@ -0,0 +1,59 @@
import 'package:eatvio_app/core/theme/theme_helper.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_cubit.dart';
import 'package:eatvio_app/features/consultant/become_consultant/presentation/bloc/register_consultant_cubit/register_consultant_state.dart';
import 'package:eatvio_app/features/consultant/become_consultant/presentation/pages/passport_data_screen.dart';
import 'package:eatvio_app/features/consultant/become_consultant/repositories/consultant_repository.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
class MockConsultantRepository extends Mock implements ConsultantRepository {}
void main() {
group('PassportDataScreen smoke', () {
late RegisterConsultantCubit cubit;
setUp(() {
cubit = RegisterConsultantCubit(consultantRepository: MockConsultantRepository());
cubit.emit(
const RegisterConsultantState(
consultant: ConsultantProfileModel(socialLinks: SocialLinksModel()),
acceptOffer: false,
loading: false,
isUpdating: false,
),
);
});
tearDown(() async {
await cubit.close();
});
Widget wrap(Widget child) {
return MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(
body: BlocProvider<RegisterConsultantCubit>.value(value: cubit, child: child),
),
);
}
testWidgets('renders passport data fields', (tester) async {
await tester.pumpWidget(wrap(const PassportDataScreen()));
await tester.pump();
expect(find.byType(PassportDataScreen), findsOneWidget);
expect(find.text('Паспортные данные'), findsOneWidget);
expect(find.text('Фамилия'), findsOneWidget);
expect(find.text('Имя'), findsOneWidget);
expect(find.text('ИНН (12 цифр)'), findsOneWidget);
expect(find.text('СНИЛС'), findsOneWidget);
expect(find.text('Гражданство (ISO, например RU)'), findsOneWidget);
expect(find.text('Телефон для выплат через СБП'), findsOneWidget);
expect(find.text('Банк получатель (поиск)'), findsOneWidget);
expect(find.text('Я являюсь налоговым резидентом США'), findsOneWidget);
});
});
}

View File

@@ -1,24 +1,54 @@
import 'package:eatvio_app/core/theme/theme_helper.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_cubit.dart';
import 'package:eatvio_app/features/consultant/become_consultant/presentation/bloc/register_consultant_cubit/register_consultant_state.dart';
import 'package:eatvio_app/features/consultant/become_consultant/presentation/pages/registration_as_screen.dart';
import 'package:eatvio_app/features/consultant/become_consultant/repositories/consultant_repository.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
class MockConsultantRepository extends Mock implements ConsultantRepository {}
void main() {
group('RegistrationAsScreen smoke', () {
late RegisterConsultantCubit cubit;
setUp(() {
cubit = RegisterConsultantCubit(consultantRepository: MockConsultantRepository());
cubit.emit(
const RegisterConsultantState(
consultant: ConsultantProfileModel(socialLinks: SocialLinksModel()),
acceptOffer: false,
loading: false,
isUpdating: false,
),
);
});
tearDown(() async {
await cubit.close();
});
Widget wrap(Widget child) {
return MaterialApp(
theme: ThemeHelper().themeData(),
home: Scaffold(body: child),
home: Scaffold(
body: BlocProvider<RegisterConsultantCubit>.value(value: cubit, child: child),
),
);
}
testWidgets('renders registration as screen', (tester) async {
await tester.pumpWidget(wrap(const RegistrationAsScreen()));
await tester.pump();
await tester.pump();
expect(find.byType(RegistrationAsScreen), findsOneWidget);
expect(find.text('Регистрация в качестве'), findsOneWidget);
expect(find.text('Физического лица'), findsOneWidget);
expect(cubit.state.consultant.legalType, 'individualPerson');
});
});
}

View File

@@ -86,7 +86,7 @@ void main() {
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
expect(find.text('шаг 1 из 6'), findsOneWidget);
expect(find.text('шаг 1 из 7'), findsOneWidget);
});
testWidgets('displays progress bar', (tester) async {

View File

@@ -5,6 +5,7 @@ import 'package:dio/dio.dart';
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/models/consultation_request_model.dart';
import 'package:eatvio_app/features/consultant/become_consultant/models/sbp_bank_model.dart';
import 'package:eatvio_app/features/consultant/become_consultant/repositories/consultant_repository.dart';
import 'package:eatvio_app/features/consultant/become_consultant/services/consultant_service.dart';
import 'package:flutter_test/flutter_test.dart';
@@ -88,6 +89,18 @@ void main() {
verify(() => mockService.getConsultantCertPhotos()).called(1);
});
test('getSbpBanks returns banks from service', () async {
final banks = FixtureReader.readAsList('consultant/sbp_banks.json')
.map((item) => SbpBankModel.fromJson(item as Map<String, dynamic>))
.toList();
when(() => mockService.getSbpBanks()).thenAnswer((_) async => banks);
final result = await repository.getSbpBanks();
expect(result, banks);
verify(() => mockService.getSbpBanks()).called(1);
});
test('storeConsultantCertPhotos returns empty list when no files provided', () async {
final result = await repository.storeConsultantCertPhotos(files: []);

View File

@@ -20,6 +20,26 @@
"title": "Психология питания",
"date": "2023-06-05"
}
]
],
"legal_type": "individualPerson",
"last_name": "Иванов",
"first_name": "Иван",
"middle_name": "Иванович",
"inn": "123456789012",
"snils": "123-456-789 00",
"passport_series": "1234",
"passport_number": "567890",
"passport_issue_date": "2020-01-15",
"passport_issuer": "ОВД Пресненского района г. Москвы",
"passport_issuer_code": "772-053",
"birth_date": "1990-05-20",
"birth_place": "г. Москва",
"registration_address": "г. Москва, ул. Тверская, д. 1, кв. 1",
"residence_address": "г. Москва, ул. Тверская, д. 1, кв. 1",
"citizenship": "RU",
"tax_resident_us": false,
"foreign_tax_resident": false,
"sbp_phone": "+79991234567",
"agreement_accepted": true,
"frdo_agreement_accepted": true
}

View File

@@ -23,6 +23,31 @@
"personal_site_link": "https://consultant.eatvio.app",
"request_state": "approved"
},
"legal_entity_resource": {
"id": 1,
"type": "individualPerson",
"last_name": "Иванов",
"first_name": "Иван",
"middle_name": "Иванович",
"inn": "123456789012",
"snils": "123-456-789 00",
"state": "created",
"alfa_scoring_status": "pending",
"alfa_scoring_request_id": "abc-123",
"passport_series": "1234",
"passport_number": "567890",
"passport_issue_date": "2020-01-15",
"passport_issuer": "ОВД Пресненского района г. Москвы",
"passport_issuer_code": "772-053",
"birth_date": "1990-05-20",
"birth_place": "г. Москва",
"registration_address": "г. Москва, ул. Тверская, д. 1, кв. 1",
"residence_address": "г. Москва, ул. Тверская, д. 1, кв. 1",
"citizenship": "RU",
"tax_resident_us": false,
"foreign_tax_resident": false,
"sbp_phone": "+79991234567"
},
"cert_photos": [
{
"url": "https://cdn.eatvio.app/certificates/visible.jpg"
@@ -40,4 +65,3 @@
]
}
}

16
test/fixtures/consultant/sbp_banks.json vendored Normal file
View File

@@ -0,0 +1,16 @@
[
{
"bank_member_id": "100000000111",
"bank_name": "Сбербанк",
"short_name": "Сбер",
"logo_url": "https://example.com/sber.png",
"bic": "044525225"
},
{
"bank_member_id": "100000000004",
"bank_name": "Т-Банк",
"short_name": "ТБанк",
"logo_url": "https://example.com/tbank.png",
"bic": "044525974"
}
]