forked from eatvio/eatvio_app
100 lines
3.7 KiB
Dart
100 lines
3.7 KiB
Dart
import 'package:eatvio_app/core/app_config.dart';
|
||
import 'package:eatvio_app/core/app_initializer.dart';
|
||
import 'package:eatvio_app/core/app_router.dart';
|
||
import 'package:eatvio_app/core/locator_service.dart';
|
||
import 'package:eatvio_app/features/auth/sdk/social_auth_facade.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||
import 'package:flutter_test/flutter_test.dart';
|
||
|
||
void main() {
|
||
group('SocialAuthFacade', () {
|
||
setUpAll(() async {
|
||
dotenv.loadFromString(
|
||
envString:
|
||
'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost\nVK_CLIENT_ID_IOS=\nVK_CLIENT_ID_ANDROID=\nYANDEX_CLIENT_ID=\nYANDEX_REDIRECT_URI=',
|
||
);
|
||
});
|
||
|
||
setUp(() async {
|
||
await sl.reset();
|
||
sl.registerLazySingleton<AppConfig>(() => AppConfig(buildType: AppBuildType.tests)..setBaseUrl('http://localhost'));
|
||
});
|
||
|
||
test('signInWithVk returns null when context is null', () async {
|
||
// Устанавливаем navigatorKey.currentContext в null
|
||
AppRouter.navigatorKey = GlobalKey<NavigatorState>();
|
||
|
||
final result = await SocialAuthFacade.signInWithVk();
|
||
|
||
expect(result, isNull);
|
||
});
|
||
|
||
testWidgets('signInWithVkAndFetchProfile returns null when clientId is empty', (tester) async {
|
||
// Загружаем dotenv с пустыми значениями для VK
|
||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost\nVK_CLIENT_ID_IOS=\nVK_CLIENT_ID_ANDROID=');
|
||
|
||
// Создаем простой MaterialApp для получения BuildContext
|
||
await tester.pumpWidget(
|
||
MaterialApp(
|
||
home: Builder(
|
||
builder: (context) {
|
||
// Вызываем метод асинхронно и проверяем результат
|
||
SocialAuthFacade.signInWithVkAndFetchProfile(context: context).then((result) {
|
||
expect(result, isNull);
|
||
});
|
||
return const Scaffold(body: SizedBox());
|
||
},
|
||
),
|
||
),
|
||
);
|
||
|
||
await tester.pumpAndSettle();
|
||
});
|
||
|
||
test('signInWithOkAndFetchProfile returns null when context is null', () async {
|
||
AppRouter.navigatorKey = GlobalKey<NavigatorState>();
|
||
|
||
final result = await SocialAuthFacade.signInWithOkAndFetchProfile();
|
||
|
||
expect(result, isNull);
|
||
});
|
||
|
||
test('signInWithMailRuAndFetchProfile returns null when context is null', () async {
|
||
AppRouter.navigatorKey = GlobalKey<NavigatorState>();
|
||
|
||
final result = await SocialAuthFacade.signInWithMailRuAndFetchProfile();
|
||
|
||
expect(result, isNull);
|
||
});
|
||
|
||
test('signInWithYandex returns null when clientId is empty', () async {
|
||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost\nYANDEX_CLIENT_ID=\nYANDEX_REDIRECT_URI=test-redirect');
|
||
|
||
final result = await SocialAuthFacade.signInWithYandex();
|
||
|
||
expect(result, isNull);
|
||
});
|
||
|
||
test('signInWithYandex returns null when redirectUri is empty', () async {
|
||
dotenv.loadFromString(envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost\nYANDEX_CLIENT_ID=test-client-id\nYANDEX_REDIRECT_URI=');
|
||
|
||
final result = await SocialAuthFacade.signInWithYandex();
|
||
|
||
expect(result, isNull);
|
||
});
|
||
|
||
test('signInWithYandex returns null when context is null', () async {
|
||
dotenv.loadFromString(
|
||
envString: 'DEV_BASE_URL=http://localhost\nBASE_URL=http://localhost\nYANDEX_CLIENT_ID=test-client-id\nYANDEX_REDIRECT_URI=test-redirect-uri',
|
||
);
|
||
|
||
AppRouter.navigatorKey = GlobalKey<NavigatorState>();
|
||
|
||
final result = await SocialAuthFacade.signInWithYandex();
|
||
|
||
expect(result, isNull);
|
||
});
|
||
});
|
||
}
|