From f6a69386f59670a392bd022b21cd04ec08f2803a Mon Sep 17 00:00:00 2001 From: Badr Kouki Date: Fri, 22 Nov 2024 12:02:51 +0100 Subject: [PATCH] chore: add mock attribute to bugsee manager initialization --- src/app/integration_test/bugsee_test.dart | 9 ++++++ .../integration_test/integration_test.dart | 7 +++++ .../lib/business/bugsee/bugsee_manager.dart | 31 ++++++++++++------- src/app/lib/main.dart | 8 +++-- 4 files changed, 41 insertions(+), 14 deletions(-) create mode 100644 src/app/integration_test/bugsee_test.dart diff --git a/src/app/integration_test/bugsee_test.dart b/src/app/integration_test/bugsee_test.dart new file mode 100644 index 0000000..bb2c4c2 --- /dev/null +++ b/src/app/integration_test/bugsee_test.dart @@ -0,0 +1,9 @@ +import 'package:flutter_test/flutter_test.dart'; + +/// Test all Bugsee setup features +Future bugseeSetupTest() async { + testWidgets( + 'Test Bugsee configuration', + (tester) async {}, + ); +} diff --git a/src/app/integration_test/integration_test.dart b/src/app/integration_test/integration_test.dart index 5e555c0..18187bc 100644 --- a/src/app/integration_test/integration_test.dart +++ b/src/app/integration_test/integration_test.dart @@ -4,6 +4,7 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:get_it/get_it.dart'; import 'package:integration_test/integration_test.dart'; +import 'bugsee_test.dart'; import 'dad_jokes_page_test.dart'; import 'forced_update_test.dart'; import 'kill_switch_test.dart'; @@ -12,6 +13,11 @@ import 'kill_switch_test.dart'; Future main() async { IntegrationTestWidgetsFlutterBinding.ensureInitialized(); await initializeComponents(isMocked: true); + await registerBugseeManager( + isMock: true, + //A mock hexadecimal-based Bugsee token + bugseeToken: '01234567-0123-0123-0123-0123456789AB', + ); tearDownAll( () async => await GetIt.I.get().setMocking(false), @@ -20,4 +26,5 @@ Future main() async { await dadJokeTest(); await killSwitchTest(); await forcedUpdateTest(); + await bugseeSetupTest(); } diff --git a/src/app/lib/business/bugsee/bugsee_manager.dart b/src/app/lib/business/bugsee/bugsee_manager.dart index 7393b6b..e9cd9e9 100644 --- a/src/app/lib/business/bugsee/bugsee_manager.dart +++ b/src/app/lib/business/bugsee/bugsee_manager.dart @@ -28,6 +28,7 @@ abstract interface class BugseeManager { /// [BUGSEE_TOKEN] in the env using `--dart-define` or `launch.json` on vscode Future initialize({ String? bugseeToken, + bool isMock, required Logger logger, required LoggerManager loggerManager, required BugseeRepository bugseeRepository, @@ -118,6 +119,7 @@ final class _BugseeManager implements BugseeManager { @override Future initialize({ String? bugseeToken, + bool isMock = false, required Logger logger, required LoggerManager loggerManager, required BugseeRepository bugseeRepository, @@ -145,6 +147,11 @@ final class _BugseeManager implements BugseeManager { launchOptions = _initializeLaunchOptions(); _isBugSeeInitialized = false; + if (isMock) { + _initializeBugsee(bugseeToken ?? ''); + return; + } + if (kDebugMode) { _currentState = _currentState.copyWith( isConfigurationValid: false, @@ -163,15 +170,12 @@ final class _BugseeManager implements BugseeManager { ); return; } + _initializeBugsee(bugseeToken); + } - _currentState = _currentState.copyWith( - isLogFilterEnabled: configurationData.isLogsFilterEnabled, - isLogCollectionEnabled: configurationData.isLogCollectionEnabled, - attachLogFile: configurationData.attachLogFileEnabled, - ); - + void _initializeBugsee(String bugseeToken) async { if (configurationData.isBugseeEnabled ?? true) { - await _launchBugseeLogger(bugseeToken); + _isBugSeeInitialized = await _launchBugseeLogger(bugseeToken); } _currentState = _currentState.copyWith( @@ -180,10 +184,14 @@ final class _BugseeManager implements BugseeManager { isVideoCaptureEnabled: _isBugSeeInitialized && (configurationData.isVideoCaptureEnabled ?? true), isDataObscured: configurationData.isDataObscured, + isLogFilterEnabled: configurationData.isLogsFilterEnabled, + isLogCollectionEnabled: configurationData.isLogCollectionEnabled, + attachLogFile: configurationData.attachLogFileEnabled, ); } - Future _launchBugseeLogger(String bugseeToken) async { + Future _launchBugseeLogger(String bugseeToken) async { + bool isInitialized = false; HttpOverrides.global = Bugsee.defaultHttpOverrides; await Bugsee.launch( bugseeToken, @@ -193,16 +201,17 @@ final class _BugseeManager implements BugseeManager { "BUGSEE: not initialized, verify bugsee token configuration", ); } - _isBugSeeInitialized = isBugseeLaunched; + isInitialized = isBugseeLaunched; }, launchOptions: launchOptions, ); - if (_currentState.isLogFilterEnabled) { + if (configurationData.isLogsFilterEnabled ?? false) { Bugsee.setLogFilter(_filterBugseeLogs); } - if (_currentState.attachLogFile) { + if (configurationData.attachLogFileEnabled ?? false) { Bugsee.setAttachmentsCallback(_attachLogFile); } + return isInitialized; } BugseeLaunchOptions? _initializeLaunchOptions() { diff --git a/src/app/lib/main.dart b/src/app/lib/main.dart index 27b064e..770a6cb 100644 --- a/src/app/lib/main.dart +++ b/src/app/lib/main.dart @@ -43,6 +43,7 @@ Future main() async { FlutterError.onError = GetIt.I.get().inteceptRenderExceptions; await initializeComponents(); + await registerBugseeManager(); runApp(const App()); }, GetIt.I.get().inteceptExceptions, @@ -53,7 +54,6 @@ Future initializeComponents({bool? isMocked}) async { WidgetsFlutterBinding.ensureInitialized(); await _registerAndLoadEnvironment(); await _registerAndLoadLoggers(); - await _registerBugseeManager(); _logger.d("Initialized environment and logger."); @@ -135,15 +135,17 @@ void _initializeBugseeManager() { ); } -Future _registerBugseeManager() async { +Future registerBugseeManager({bool? isMock, String? bugseeToken}) async { if (!GetIt.I.isRegistered()) { _initializeBugseeManager(); } GetIt.I.get().initialize( - bugseeToken: const String.fromEnvironment('BUGSEE_TOKEN'), + bugseeToken: + bugseeToken ?? const String.fromEnvironment('BUGSEE_TOKEN'), logger: GetIt.I.get(), loggerManager: GetIt.I.get(), bugseeRepository: GetIt.I.get(), + isMock: isMock ?? false, ); }