forked from eatvio/eatvio_app
71 lines
3.1 KiB
Dart
71 lines
3.1 KiB
Dart
import 'package:eatvio_app/features/auth/models/credentials_model.dart';
|
|
import 'package:eatvio_app/features/auth/models/oauth_login_request.dart';
|
|
import 'package:eatvio_app/features/auth/models/oauth_model.dart';
|
|
import 'package:eatvio_app/features/auth/models/token_model.dart';
|
|
import 'package:eatvio_app/features/auth/services/auth_service.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:mockito/annotations.dart';
|
|
import 'package:mockito/mockito.dart';
|
|
|
|
import '../../../fixtures/fixture_reader.dart';
|
|
import 'auth_service_test.mocks.dart';
|
|
|
|
@GenerateNiceMocks([MockSpec<AuthService>()])
|
|
void main() {
|
|
group('AuthService', () {
|
|
late MockAuthService mockAuthService;
|
|
|
|
setUp(() {
|
|
mockAuthService = MockAuthService();
|
|
});
|
|
|
|
test('getTokenByCredentials - возвращает токен по учетным данным', () async {
|
|
final tokenJson = FixtureReader.readAsMap('auth/token_response.json');
|
|
final expectedToken = TokenModel.fromJson(tokenJson);
|
|
final credentialsJson = FixtureReader.readAsMap('auth/login_credentials.json');
|
|
final credentials = CredentialsModel.fromJson(credentialsJson);
|
|
|
|
when(mockAuthService.getTokenByCredentials(credentials: credentials))
|
|
.thenAnswer((_) async => expectedToken);
|
|
|
|
final result = await mockAuthService.getTokenByCredentials(credentials: credentials);
|
|
|
|
expect(result, isA<TokenModel>());
|
|
expect(result.token, 'test_token_12345');
|
|
verify(mockAuthService.getTokenByCredentials(credentials: credentials)).called(1);
|
|
});
|
|
|
|
test('signInViaSocialMedia - возвращает токен при входе через соцсети', () async {
|
|
final tokenJson = FixtureReader.readAsMap('auth/token_response.json');
|
|
final expectedToken = TokenModel.fromJson(tokenJson);
|
|
final oauthJson = FixtureReader.readAsMap('auth/oauth_signin_request.json');
|
|
final oauthRequest = OAuthLoginRequest.fromJson(oauthJson);
|
|
|
|
when(mockAuthService.signInViaSocialMedia(body: oauthRequest))
|
|
.thenAnswer((_) async => expectedToken);
|
|
|
|
final result = await mockAuthService.signInViaSocialMedia(body: oauthRequest);
|
|
|
|
expect(result, isA<TokenModel>());
|
|
expect(result.token, 'test_token_12345');
|
|
verify(mockAuthService.signInViaSocialMedia(body: oauthRequest)).called(1);
|
|
});
|
|
|
|
test('signUpViaSocialMedia - возвращает данные при регистрации через соцсети', () async {
|
|
final expectedResponse = {'success': true, 'message': 'User registered'};
|
|
final oauthJson = FixtureReader.readAsMap('auth/oauth_signup_request.json');
|
|
final oauthModel = OAuthModel.fromJson(oauthJson);
|
|
|
|
when(mockAuthService.signUpViaSocialMedia(body: oauthModel))
|
|
.thenAnswer((_) async => expectedResponse);
|
|
|
|
final result = await mockAuthService.signUpViaSocialMedia(body: oauthModel);
|
|
|
|
expect(result, isA<Map<String, Object?>>());
|
|
expect(result['success'], true);
|
|
verify(mockAuthService.signUpViaSocialMedia(body: oauthModel)).called(1);
|
|
});
|
|
});
|
|
}
|
|
|