forked from eatvio/eatvio_app
refactor(tests): update model instantiation to use const for improved performance
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import 'package:eatvio_app/features/registration_v2/models/registration_model.dart';
|
||||
import 'package:eatvio_app/features/registration_v2/repositories/registration_repository_v2.dart';
|
||||
import 'package:eatvio_app/features/registration_v2/services/registration_service_v2.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
|
||||
import 'registration_repository_v2_test.mocks.dart';
|
||||
|
||||
@GenerateMocks([RegistrationServiceV2])
|
||||
void main() {
|
||||
group('RegistrationRepositoryV2', () {
|
||||
late RegistrationRepositoryV2 repository;
|
||||
late MockRegistrationServiceV2 mockService;
|
||||
|
||||
setUp(() {
|
||||
mockService = MockRegistrationServiceV2();
|
||||
repository = RegistrationRepositoryV2(registrationService: mockService);
|
||||
});
|
||||
|
||||
test('register - успешная регистрация', () async {
|
||||
final registrationModel = RegistrationModel(
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
email: 'test@example.com',
|
||||
phone: '+1234567890',
|
||||
gender: 'male',
|
||||
password: 'password123',
|
||||
confirmPassword: 'password123',
|
||||
weight: 70,
|
||||
height: 175,
|
||||
activityCoefficient: 1.5,
|
||||
birthday: '1990-01-01',
|
||||
);
|
||||
|
||||
const token = 'test-token';
|
||||
when(mockService.register(model: anyNamed('model')))
|
||||
.thenAnswer((_) async => {'token': token});
|
||||
|
||||
final result = await repository.register(registrationModel: registrationModel);
|
||||
|
||||
expect(result, equals(token));
|
||||
verify(mockService.register(model: anyNamed('model'))).called(1);
|
||||
});
|
||||
|
||||
test('register - проброс ошибки', () async {
|
||||
final registrationModel = RegistrationModel(
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
email: 'test@example.com',
|
||||
phone: '+1234567890',
|
||||
gender: 'male',
|
||||
password: 'password123',
|
||||
confirmPassword: 'password123',
|
||||
weight: 70,
|
||||
height: 175,
|
||||
activityCoefficient: 1.5,
|
||||
birthday: '1990-01-01',
|
||||
);
|
||||
|
||||
final error = Exception('Ошибка регистрации');
|
||||
when(mockService.register(model: anyNamed('model')))
|
||||
.thenThrow(error);
|
||||
|
||||
expect(
|
||||
() => repository.register(registrationModel: registrationModel),
|
||||
throwsA(error),
|
||||
);
|
||||
verify(mockService.register(model: anyNamed('model'))).called(1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user