forked from eatvio/eatvio_app
feat(video_calls): video calls tokens registration fix
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/core/firebase_api.dart';
|
||||
import 'package:eatvio_app/core/prefs.dart';
|
||||
import 'package:eatvio_app/core/token_storage.dart';
|
||||
import 'package:eatvio_app/features/auth/models/oauth_verification_confirm_response.dart';
|
||||
@@ -16,6 +17,17 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
import '../../../../../fixtures/fixture_reader.dart';
|
||||
import 'oauth_cubit_test.mocks.dart';
|
||||
|
||||
class _RecordingFirebaseApi extends Fake implements FirebaseApi {
|
||||
int registerPushTokenCalls = 0;
|
||||
bool hadAuthToken = false;
|
||||
|
||||
@override
|
||||
Future<void> registerPushToken() async {
|
||||
registerPushTokenCalls++;
|
||||
hadAuthToken = await TokenStorage.haveTokenInStorage();
|
||||
}
|
||||
}
|
||||
|
||||
@GenerateNiceMocks([MockSpec<AuthRepository>(), MockSpec<Prefs>()])
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
@@ -24,26 +36,36 @@ void main() {
|
||||
OAuthCubit? oauthCubit;
|
||||
late MockAuthRepository mockAuthRepository;
|
||||
late MockPrefs mockPrefs;
|
||||
late _RecordingFirebaseApi firebaseApi;
|
||||
late TokenModel tokenFixture;
|
||||
late Map<String, dynamic> signInRequestFixture;
|
||||
late Map<String, dynamic> signUpRequestFixture;
|
||||
|
||||
setUp(() async {
|
||||
tokenFixture = TokenModel.fromJson(FixtureReader.readAsMap('auth/token_response.json'));
|
||||
signInRequestFixture = FixtureReader.readAsMap('auth/oauth_signin_request.json');
|
||||
signUpRequestFixture = FixtureReader.readAsMap('auth/oauth_signup_request.json');
|
||||
tokenFixture = TokenModel.fromJson(
|
||||
FixtureReader.readAsMap('auth/token_response.json'),
|
||||
);
|
||||
signInRequestFixture = FixtureReader.readAsMap(
|
||||
'auth/oauth_signin_request.json',
|
||||
);
|
||||
signUpRequestFixture = FixtureReader.readAsMap(
|
||||
'auth/oauth_signup_request.json',
|
||||
);
|
||||
|
||||
mockAuthRepository = MockAuthRepository();
|
||||
mockPrefs = MockPrefs();
|
||||
firebaseApi = _RecordingFirebaseApi();
|
||||
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
|
||||
// Mock Fluttertoast plugin
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(const MethodChannel('PonnamKarthik/fluttertoast'), (
|
||||
MethodCall methodCall,
|
||||
) async {
|
||||
return null;
|
||||
});
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(
|
||||
const MethodChannel('PonnamKarthik/fluttertoast'),
|
||||
(MethodCall methodCall) async {
|
||||
return null;
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
@@ -52,18 +74,31 @@ void main() {
|
||||
oauthCubit!.close();
|
||||
oauthCubit = null;
|
||||
}
|
||||
TokenStorage.clearCache();
|
||||
|
||||
// Clear mock handlers
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(const MethodChannel('PonnamKarthik/fluttertoast'), null);
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(
|
||||
const MethodChannel('PonnamKarthik/fluttertoast'),
|
||||
null,
|
||||
);
|
||||
});
|
||||
|
||||
test('начальное состояние - OAuthState', () {
|
||||
oauthCubit = OAuthCubit(authRepository: mockAuthRepository, prefs: mockPrefs);
|
||||
oauthCubit = OAuthCubit(
|
||||
authRepository: mockAuthRepository,
|
||||
firebaseApi: firebaseApi,
|
||||
prefs: mockPrefs,
|
||||
);
|
||||
expect(oauthCubit!.state, const OAuthState());
|
||||
});
|
||||
|
||||
test('signInViaSocialMedia - успешный вход через соцсеть', () async {
|
||||
oauthCubit = OAuthCubit(authRepository: mockAuthRepository, prefs: mockPrefs);
|
||||
oauthCubit = OAuthCubit(
|
||||
authRepository: mockAuthRepository,
|
||||
firebaseApi: firebaseApi,
|
||||
prefs: mockPrefs,
|
||||
);
|
||||
|
||||
when(
|
||||
mockAuthRepository.signInViaSocialMedia(
|
||||
@@ -92,7 +127,11 @@ void main() {
|
||||
});
|
||||
|
||||
test('signInViaSocialMedia - переход в состояние loading', () async {
|
||||
oauthCubit = OAuthCubit(authRepository: mockAuthRepository, prefs: mockPrefs);
|
||||
oauthCubit = OAuthCubit(
|
||||
authRepository: mockAuthRepository,
|
||||
firebaseApi: firebaseApi,
|
||||
prefs: mockPrefs,
|
||||
);
|
||||
|
||||
when(
|
||||
mockAuthRepository.signInViaSocialMedia(
|
||||
@@ -119,7 +158,11 @@ void main() {
|
||||
});
|
||||
|
||||
test('signInViaSocialMedia - обработка ошибки', () async {
|
||||
oauthCubit = OAuthCubit(authRepository: mockAuthRepository, prefs: mockPrefs);
|
||||
oauthCubit = OAuthCubit(
|
||||
authRepository: mockAuthRepository,
|
||||
firebaseApi: firebaseApi,
|
||||
prefs: mockPrefs,
|
||||
);
|
||||
|
||||
when(
|
||||
mockAuthRepository.signInViaSocialMedia(
|
||||
@@ -144,7 +187,11 @@ void main() {
|
||||
});
|
||||
|
||||
test('signUpViaSocialMedia - успешная регистрация через соцсеть', () async {
|
||||
oauthCubit = OAuthCubit(authRepository: mockAuthRepository, prefs: mockPrefs);
|
||||
oauthCubit = OAuthCubit(
|
||||
authRepository: mockAuthRepository,
|
||||
firebaseApi: firebaseApi,
|
||||
prefs: mockPrefs,
|
||||
);
|
||||
|
||||
when(
|
||||
mockAuthRepository.signUpViaSocialMedia(
|
||||
@@ -164,7 +211,9 @@ void main() {
|
||||
),
|
||||
).thenAnswer((_) async => tokenFixture.token);
|
||||
|
||||
when(mockPrefs.setString(any, any)).thenAnswer((_) async => Future.value());
|
||||
when(
|
||||
mockPrefs.setString(any, any),
|
||||
).thenAnswer((_) async => Future.value());
|
||||
|
||||
final result = await oauthCubit!.signUpViaSocialMedia(
|
||||
provider: signUpRequestFixture['provider'] as String,
|
||||
@@ -187,48 +236,62 @@ void main() {
|
||||
expect(oauthCubit!.state, isA<OAuthStateLoaded>());
|
||||
final loadedState = oauthCubit!.state as OAuthStateLoaded;
|
||||
expect(loadedState.token, tokenFixture.token);
|
||||
expect(await TokenStorage.getTokenFromStorage(), tokenFixture.token);
|
||||
expect(firebaseApi.registerPushTokenCalls, 1);
|
||||
expect(firebaseApi.hadAuthToken, isTrue);
|
||||
});
|
||||
|
||||
test('signInViaSocialMedia - обработка ошибки валидации email/phone', () async {
|
||||
oauthCubit = OAuthCubit(authRepository: mockAuthRepository, prefs: mockPrefs);
|
||||
test(
|
||||
'signInViaSocialMedia - обработка ошибки валидации email/phone',
|
||||
() async {
|
||||
oauthCubit = OAuthCubit(
|
||||
authRepository: mockAuthRepository,
|
||||
firebaseApi: firebaseApi,
|
||||
prefs: mockPrefs,
|
||||
);
|
||||
|
||||
final dioException = DioException(
|
||||
requestOptions: RequestOptions(path: '/api/auth/oauth/signin'),
|
||||
response: Response(
|
||||
statusCode: 422,
|
||||
data: {
|
||||
'errors': {
|
||||
'email': ['Некорректный формат email'],
|
||||
},
|
||||
},
|
||||
final dioException = DioException(
|
||||
requestOptions: RequestOptions(path: '/api/auth/oauth/signin'),
|
||||
),
|
||||
);
|
||||
response: Response(
|
||||
statusCode: 422,
|
||||
data: {
|
||||
'errors': {
|
||||
'email': ['Некорректный формат email'],
|
||||
},
|
||||
},
|
||||
requestOptions: RequestOptions(path: '/api/auth/oauth/signin'),
|
||||
),
|
||||
);
|
||||
|
||||
when(
|
||||
mockAuthRepository.signInViaSocialMedia(
|
||||
provider: anyNamed('provider'),
|
||||
accessToken: anyNamed('accessToken'),
|
||||
refreshToken: anyNamed('refreshToken'),
|
||||
clientId: anyNamed('clientId'),
|
||||
),
|
||||
).thenThrow(dioException);
|
||||
when(
|
||||
mockAuthRepository.signInViaSocialMedia(
|
||||
provider: anyNamed('provider'),
|
||||
accessToken: anyNamed('accessToken'),
|
||||
refreshToken: anyNamed('refreshToken'),
|
||||
clientId: anyNamed('clientId'),
|
||||
),
|
||||
).thenThrow(dioException);
|
||||
|
||||
await oauthCubit!.signInViaSocialMedia(
|
||||
provider: signInRequestFixture['provider'] as String,
|
||||
accessToken: signInRequestFixture['access_token'] as String,
|
||||
refreshToken: signInRequestFixture['refresh_token'] as String,
|
||||
clientId: signInRequestFixture['client_id'] as String,
|
||||
);
|
||||
await oauthCubit!.signInViaSocialMedia(
|
||||
provider: signInRequestFixture['provider'] as String,
|
||||
accessToken: signInRequestFixture['access_token'] as String,
|
||||
refreshToken: signInRequestFixture['refresh_token'] as String,
|
||||
clientId: signInRequestFixture['client_id'] as String,
|
||||
);
|
||||
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
expect(oauthCubit!.state, isA<OAuthStateError>());
|
||||
final errorState = oauthCubit!.state as OAuthStateError;
|
||||
expect(errorState.errorMessage, 'validation_error');
|
||||
});
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
expect(oauthCubit!.state, isA<OAuthStateError>());
|
||||
final errorState = oauthCubit!.state as OAuthStateError;
|
||||
expect(errorState.errorMessage, 'validation_error');
|
||||
},
|
||||
);
|
||||
|
||||
test('signUpViaSocialMedia - обработка ошибки валидации email', () async {
|
||||
oauthCubit = OAuthCubit(authRepository: mockAuthRepository, prefs: mockPrefs);
|
||||
oauthCubit = OAuthCubit(
|
||||
authRepository: mockAuthRepository,
|
||||
firebaseApi: firebaseApi,
|
||||
prefs: mockPrefs,
|
||||
);
|
||||
|
||||
final dioException = DioException(
|
||||
requestOptions: RequestOptions(path: '/api/auth/oauth/signup'),
|
||||
@@ -282,82 +345,130 @@ void main() {
|
||||
expect(result[0], RegistrationValidationErrors.incorrectEmailFormat);
|
||||
});
|
||||
|
||||
test('requestOAuthVerification - успешный запрос кода верификации', () async {
|
||||
oauthCubit = OAuthCubit(authRepository: mockAuthRepository, prefs: mockPrefs);
|
||||
test(
|
||||
'requestOAuthVerification - успешный запрос кода верификации',
|
||||
() async {
|
||||
oauthCubit = OAuthCubit(
|
||||
authRepository: mockAuthRepository,
|
||||
firebaseApi: firebaseApi,
|
||||
prefs: mockPrefs,
|
||||
);
|
||||
|
||||
const verificationResponse = OAuthVerificationRequestResponse(email: 't***@example.com', status: 'sent');
|
||||
const verificationResponse = OAuthVerificationRequestResponse(
|
||||
email: 't***@example.com',
|
||||
status: 'sent',
|
||||
);
|
||||
|
||||
when(mockAuthRepository.requestOAuthVerification(email: anyNamed('email'), phone: anyNamed('phone'))).thenAnswer((_) async => verificationResponse);
|
||||
when(
|
||||
mockAuthRepository.requestOAuthVerification(
|
||||
email: anyNamed('email'),
|
||||
phone: anyNamed('phone'),
|
||||
),
|
||||
).thenAnswer((_) async => verificationResponse);
|
||||
|
||||
final result = await oauthCubit!.requestOAuthVerification(email: 'test@example.com');
|
||||
final result = await oauthCubit!.requestOAuthVerification(
|
||||
email: 'test@example.com',
|
||||
);
|
||||
|
||||
expect(result, isNotNull);
|
||||
expect(result!.email, 't***@example.com');
|
||||
expect(oauthCubit!.state, isA<OAuthState>());
|
||||
});
|
||||
expect(result, isNotNull);
|
||||
expect(result!.email, 't***@example.com');
|
||||
expect(oauthCubit!.state, isA<OAuthState>());
|
||||
},
|
||||
);
|
||||
|
||||
test('requestOAuthVerification - обработка ошибки', () async {
|
||||
oauthCubit = OAuthCubit(authRepository: mockAuthRepository, prefs: mockPrefs);
|
||||
oauthCubit = OAuthCubit(
|
||||
authRepository: mockAuthRepository,
|
||||
firebaseApi: firebaseApi,
|
||||
prefs: mockPrefs,
|
||||
);
|
||||
|
||||
when(mockAuthRepository.requestOAuthVerification(email: anyNamed('email'), phone: anyNamed('phone'))).thenThrow(Exception('Ошибка запроса'));
|
||||
when(
|
||||
mockAuthRepository.requestOAuthVerification(
|
||||
email: anyNamed('email'),
|
||||
phone: anyNamed('phone'),
|
||||
),
|
||||
).thenThrow(Exception('Ошибка запроса'));
|
||||
|
||||
final result = await oauthCubit!.requestOAuthVerification(email: 'test@example.com');
|
||||
final result = await oauthCubit!.requestOAuthVerification(
|
||||
email: 'test@example.com',
|
||||
);
|
||||
|
||||
expect(result, isNull);
|
||||
expect(oauthCubit!.state, isA<OAuthStateError>());
|
||||
});
|
||||
|
||||
test('confirmOAuthVerification - успешное подтверждение верификации', () async {
|
||||
oauthCubit = OAuthCubit(authRepository: mockAuthRepository, prefs: mockPrefs);
|
||||
test(
|
||||
'confirmOAuthVerification - успешное подтверждение верификации',
|
||||
() async {
|
||||
oauthCubit = OAuthCubit(
|
||||
authRepository: mockAuthRepository,
|
||||
firebaseApi: firebaseApi,
|
||||
prefs: mockPrefs,
|
||||
);
|
||||
|
||||
final verificationResponse = OAuthVerificationConfirmResponse(success: true, message: 'Success', token: tokenFixture.token, user: {}, isNewUser: false);
|
||||
final verificationResponse = OAuthVerificationConfirmResponse(
|
||||
success: true,
|
||||
message: 'Success',
|
||||
token: tokenFixture.token,
|
||||
user: {},
|
||||
isNewUser: false,
|
||||
);
|
||||
|
||||
when(
|
||||
mockAuthRepository.confirmOAuthVerification(
|
||||
provider: anyNamed('provider'),
|
||||
accessToken: anyNamed('accessToken'),
|
||||
refreshToken: anyNamed('refreshToken'),
|
||||
clientId: anyNamed('clientId'),
|
||||
id: anyNamed('id'),
|
||||
email: anyNamed('email'),
|
||||
phone: anyNamed('phone'),
|
||||
code: anyNamed('code'),
|
||||
verificationType: anyNamed('verificationType'),
|
||||
firstName: anyNamed('firstName'),
|
||||
lastName: anyNamed('lastName'),
|
||||
dateOfBirth: anyNamed('dateOfBirth'),
|
||||
gender: anyNamed('gender'),
|
||||
weight: anyNamed('weight'),
|
||||
height: anyNamed('height'),
|
||||
),
|
||||
).thenAnswer((_) async => verificationResponse);
|
||||
when(
|
||||
mockAuthRepository.confirmOAuthVerification(
|
||||
provider: anyNamed('provider'),
|
||||
accessToken: anyNamed('accessToken'),
|
||||
refreshToken: anyNamed('refreshToken'),
|
||||
clientId: anyNamed('clientId'),
|
||||
id: anyNamed('id'),
|
||||
email: anyNamed('email'),
|
||||
phone: anyNamed('phone'),
|
||||
code: anyNamed('code'),
|
||||
verificationType: anyNamed('verificationType'),
|
||||
firstName: anyNamed('firstName'),
|
||||
lastName: anyNamed('lastName'),
|
||||
dateOfBirth: anyNamed('dateOfBirth'),
|
||||
gender: anyNamed('gender'),
|
||||
weight: anyNamed('weight'),
|
||||
height: anyNamed('height'),
|
||||
),
|
||||
).thenAnswer((_) async => verificationResponse);
|
||||
|
||||
await oauthCubit!.confirmOAuthVerification(
|
||||
provider: 'google',
|
||||
accessToken: 'access_token',
|
||||
refreshToken: 'refresh_token',
|
||||
clientId: 'client_id',
|
||||
id: 'id',
|
||||
email: 'test@example.com',
|
||||
phone: null,
|
||||
code: '123456',
|
||||
verificationType: 'email',
|
||||
firstName: 'Test',
|
||||
lastName: 'User',
|
||||
dateOfBirth: '2000-01-01',
|
||||
gender: 'male',
|
||||
weight: 70,
|
||||
height: 175,
|
||||
);
|
||||
await oauthCubit!.confirmOAuthVerification(
|
||||
provider: 'google',
|
||||
accessToken: 'access_token',
|
||||
refreshToken: 'refresh_token',
|
||||
clientId: 'client_id',
|
||||
id: 'id',
|
||||
email: 'test@example.com',
|
||||
phone: null,
|
||||
code: '123456',
|
||||
verificationType: 'email',
|
||||
firstName: 'Test',
|
||||
lastName: 'User',
|
||||
dateOfBirth: '2000-01-01',
|
||||
gender: 'male',
|
||||
weight: 70,
|
||||
height: 175,
|
||||
);
|
||||
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
expect(oauthCubit!.state, isA<OAuthStateLoaded>());
|
||||
final loadedState = oauthCubit!.state as OAuthStateLoaded;
|
||||
expect(loadedState.token, tokenFixture.token);
|
||||
});
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
expect(oauthCubit!.state, isA<OAuthStateLoaded>());
|
||||
final loadedState = oauthCubit!.state as OAuthStateLoaded;
|
||||
expect(loadedState.token, tokenFixture.token);
|
||||
expect(await TokenStorage.getTokenFromStorage(), tokenFixture.token);
|
||||
expect(firebaseApi.registerPushTokenCalls, 1);
|
||||
expect(firebaseApi.hadAuthToken, isTrue);
|
||||
},
|
||||
);
|
||||
|
||||
test('confirmOAuthVerification - обработка ошибки', () async {
|
||||
oauthCubit = OAuthCubit(authRepository: mockAuthRepository, prefs: mockPrefs);
|
||||
oauthCubit = OAuthCubit(
|
||||
authRepository: mockAuthRepository,
|
||||
firebaseApi: firebaseApi,
|
||||
prefs: mockPrefs,
|
||||
);
|
||||
|
||||
when(
|
||||
mockAuthRepository.confirmOAuthVerification(
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/core/firebase_api.dart';
|
||||
import 'package:eatvio_app/core/token_storage.dart';
|
||||
import 'package:eatvio_app/features/registration_v2/cubit/registration_cubit.dart';
|
||||
import 'package:eatvio_app/features/registration_v2/repositories/registration_repository_v2.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@@ -9,43 +11,60 @@ import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'registration_cubit_v2_test.mocks.dart';
|
||||
|
||||
class _RecordingFirebaseApi extends Fake implements FirebaseApi {
|
||||
int registerPushTokenCalls = 0;
|
||||
bool hadAuthToken = false;
|
||||
|
||||
@override
|
||||
Future<void> registerPushToken() async {
|
||||
registerPushTokenCalls++;
|
||||
hadAuthToken = await TokenStorage.haveTokenInStorage();
|
||||
}
|
||||
}
|
||||
|
||||
@GenerateMocks([RegistrationRepositoryV2])
|
||||
void main() {
|
||||
TestWidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
|
||||
group('RegistrationCubitV2', () {
|
||||
late RegistrationCubitV2 cubit;
|
||||
late MockRegistrationRepositoryV2 mockRepository;
|
||||
const MethodChannel passwordGeneratorChannel = MethodChannel('flutter_password_generator');
|
||||
late _RecordingFirebaseApi firebaseApi;
|
||||
const MethodChannel passwordGeneratorChannel = MethodChannel(
|
||||
'flutter_password_generator',
|
||||
);
|
||||
|
||||
setUp(() {
|
||||
mockRepository = MockRegistrationRepositoryV2();
|
||||
cubit = RegistrationCubitV2(registrationRepository: mockRepository);
|
||||
|
||||
firebaseApi = _RecordingFirebaseApi();
|
||||
cubit = RegistrationCubitV2(
|
||||
registrationRepository: mockRepository,
|
||||
firebaseApi: firebaseApi,
|
||||
);
|
||||
|
||||
// Инициализируем SharedPreferences для тестов
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
|
||||
|
||||
// Мокируем MethodChannel для flutter_password_generator
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
passwordGeneratorChannel,
|
||||
(MethodCall methodCall) async {
|
||||
if (methodCall.method == 'generateSecureRandomData') {
|
||||
// Возвращаем Uint8List для генерации пароля
|
||||
// MethodChannel автоматически преобразует Uint8List в List<int>
|
||||
return Uint8List.fromList(List<int>.generate(32, (i) => i % 256));
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(passwordGeneratorChannel, (
|
||||
MethodCall methodCall,
|
||||
) async {
|
||||
if (methodCall.method == 'generateSecureRandomData') {
|
||||
// Возвращаем Uint8List для генерации пароля
|
||||
// MethodChannel автоматически преобразует Uint8List в List<int>
|
||||
return Uint8List.fromList(List<int>.generate(32, (i) => i % 256));
|
||||
}
|
||||
return null;
|
||||
});
|
||||
});
|
||||
|
||||
tearDown(() {
|
||||
TokenStorage.clearCache();
|
||||
cubit.close();
|
||||
// Очищаем моки
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger.setMockMethodCallHandler(
|
||||
passwordGeneratorChannel,
|
||||
null,
|
||||
);
|
||||
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
|
||||
.setMockMethodCallHandler(passwordGeneratorChannel, null);
|
||||
});
|
||||
|
||||
test('начальное состояние', () {
|
||||
@@ -182,14 +201,24 @@ void main() {
|
||||
cubit.setBirthday(DateTime(1990, 1, 1));
|
||||
|
||||
const token = 'test-token';
|
||||
when(mockRepository.register(registrationModel: anyNamed('registrationModel')))
|
||||
.thenAnswer((_) async => token);
|
||||
when(
|
||||
mockRepository.register(
|
||||
registrationModel: anyNamed('registrationModel'),
|
||||
),
|
||||
).thenAnswer((_) async => token);
|
||||
|
||||
final result = await cubit.register();
|
||||
|
||||
expect(result.$1, isTrue);
|
||||
expect(result.$2, isFalse);
|
||||
verify(mockRepository.register(registrationModel: anyNamed('registrationModel'))).called(1);
|
||||
expect(await TokenStorage.getTokenFromStorage(), token);
|
||||
expect(firebaseApi.registerPushTokenCalls, 1);
|
||||
expect(firebaseApi.hadAuthToken, isTrue);
|
||||
verify(
|
||||
mockRepository.register(
|
||||
registrationModel: anyNamed('registrationModel'),
|
||||
),
|
||||
).called(1);
|
||||
});
|
||||
|
||||
test('register - возвращает false при невалидных полях', () async {
|
||||
@@ -199,7 +228,11 @@ void main() {
|
||||
|
||||
expect(result.$1, isFalse);
|
||||
expect(result.$2, isTrue);
|
||||
verifyNever(mockRepository.register(registrationModel: anyNamed('registrationModel')));
|
||||
verifyNever(
|
||||
mockRepository.register(
|
||||
registrationModel: anyNamed('registrationModel'),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test('register - обработка ошибки валидации email', () async {
|
||||
@@ -226,16 +259,21 @@ void main() {
|
||||
),
|
||||
);
|
||||
|
||||
when(mockRepository.register(registrationModel: anyNamed('registrationModel')))
|
||||
.thenThrow(dioException);
|
||||
when(
|
||||
mockRepository.register(
|
||||
registrationModel: anyNamed('registrationModel'),
|
||||
),
|
||||
).thenThrow(dioException);
|
||||
|
||||
final result = await cubit.register();
|
||||
|
||||
expect(result.$1, isFalse);
|
||||
expect(result.$2, isTrue);
|
||||
expect(cubit.state.isEmailValid, isFalse);
|
||||
expect(cubit.state.emailDisplayError, equals('Некорректный формат email'));
|
||||
expect(
|
||||
cubit.state.emailDisplayError,
|
||||
equals('Некорректный формат email'),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user