diff --git a/WooCommerce/Classes/AppDelegate.swift b/WooCommerce/Classes/AppDelegate.swift index 59a20bfd8ee..8a92b388b55 100644 --- a/WooCommerce/Classes/AppDelegate.swift +++ b/WooCommerce/Classes/AppDelegate.swift @@ -57,9 +57,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate { let stores = ServiceLocator.stores let analytics = ServiceLocator.analytics let pushNotesManager = ServiceLocator.pushNotesManager + + /// This is important to initialize early as there are a few code points where the authenticator is used. + ServiceLocator.authenticationManager.initialize() stores.initializeAfterDependenciesAreInitialized() - setupAnalytics(analytics) + setupAnalytics(analytics) setupCocoaLumberjack() setupLibraryLogger() setupLogLevel(.verbose) @@ -224,7 +227,7 @@ extension AppDelegate { ZendeskProvider.shared.initialize() } - /// Sets up the WordPress Authenticator. + /// Sets up app analytics. /// func setupAnalytics(_ analytics: Analytics) { analytics.initialize() diff --git a/WooCommerce/Classes/ViewRelated/AppCoordinator.swift b/WooCommerce/Classes/ViewRelated/AppCoordinator.swift index d68eada9efb..61985aca72b 100644 --- a/WooCommerce/Classes/ViewRelated/AppCoordinator.swift +++ b/WooCommerce/Classes/ViewRelated/AppCoordinator.swift @@ -238,7 +238,11 @@ private extension AppCoordinator { /// Configures the WPAuthenticator for usage in both logged-in and logged-out states. func configureAuthenticator() { - authenticationManager.initialize() + if isRunningTests { + /// This is needed to fix crashes in unit tests. + /// The authenticator is initialized in AppDelegate when running the app. + authenticationManager.initialize() + } authenticationManager.setLoggedOutAppSettings(loggedOutAppSettings) authenticationManager.displayAuthenticatorIfLoggedOut = { [weak self] in guard let self, self.isLoggedIn == false else { return nil }