Fix failing test.

pull/1/head
Matthew Chen 6 years ago
parent 8830f0a594
commit 48c4576c06

@ -159,7 +159,7 @@ static NSTimeInterval launchStartedAt;
[AppSetup [AppSetup
setupEnvironmentWithAppSpecificSingletonBlock:^{ setupEnvironmentWithAppSpecificSingletonBlock:^{
// Create AppEnvironment. // Create AppEnvironment.
[AppEnvironment shared]; [AppEnvironment.shared setup];
[SignalApp.sharedApp setup]; [SignalApp.sharedApp setup];
} }
migrationCompletion:^{ migrationCompletion:^{
@ -429,7 +429,7 @@ static NSTimeInterval launchStartedAt;
} }
OWSLogInfo(@"registered vanilla push token: %@", deviceToken); OWSLogInfo(@"registered vanilla push token: %@", deviceToken);
[PushRegistrationManager.sharedManager didReceiveVanillaPushToken:deviceToken]; [PushRegistrationManager.shared didReceiveVanillaPushToken:deviceToken];
} }
- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error - (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error
@ -444,7 +444,7 @@ static NSTimeInterval launchStartedAt;
OWSLogError(@"failed to register vanilla push token with error: %@", error); OWSLogError(@"failed to register vanilla push token with error: %@", error);
#ifdef DEBUG #ifdef DEBUG
OWSLogWarn(@"We're in debug mode. Faking success for remote registration with a fake push identifier"); OWSLogWarn(@"We're in debug mode. Faking success for remote registration with a fake push identifier");
[PushRegistrationManager.sharedManager didReceiveVanillaPushToken:[[NSMutableData dataWithLength:32] copy]]; [PushRegistrationManager.shared didReceiveVanillaPushToken:[[NSMutableData dataWithLength:32] copy]];
#else #else
OWSProdError([OWSAnalyticsEvents appDelegateErrorFailedToRegisterForRemoteNotifications]); OWSProdError([OWSAnalyticsEvents appDelegateErrorFailedToRegisterForRemoteNotifications]);
[PushRegistrationManager.sharedManager didFailToReceiveVanillaPushTokenWithError:error]; [PushRegistrationManager.sharedManager didFailToReceiveVanillaPushTokenWithError:error];
@ -462,7 +462,7 @@ static NSTimeInterval launchStartedAt;
} }
OWSLogInfo(@"registered user notification settings"); OWSLogInfo(@"registered user notification settings");
[PushRegistrationManager.sharedManager didRegisterUserNotificationSettings]; [PushRegistrationManager.shared didRegisterUserNotificationSettings];
} }
- (BOOL)application:(UIApplication *)application - (BOOL)application:(UIApplication *)application

@ -6,49 +6,58 @@ import Foundation
import SignalServiceKit import SignalServiceKit
import SignalMessaging import SignalMessaging
@objc public class AppEnvironment : NSObject { @objc public class AppEnvironment: NSObject {
private static var _shared : AppEnvironment = AppEnvironment() private static var _shared: AppEnvironment = AppEnvironment()
@objc @objc
public class var shared : AppEnvironment { public class var shared: AppEnvironment {
get { get {
return _shared return _shared
} }
set { set {
guard CurrentAppContext().isRunningTests else {
owsFailDebug("Can only switch environments in tests.")
return
}
_shared = newValue _shared = newValue
} }
} }
@objc @objc
public var callMessageHandler : WebRTCCallMessageHandler public var callMessageHandler: WebRTCCallMessageHandler
@objc @objc
public var callService : CallService public var callService: CallService
@objc @objc
public var outboundCallInitiator : OutboundCallInitiator public var outboundCallInitiator: OutboundCallInitiator
@objc @objc
public var messageFetcherJob : MessageFetcherJob public var messageFetcherJob: MessageFetcherJob
@objc @objc
public var notificationsManager : NotificationsManager public var notificationsManager: NotificationsManager
@objc
public var accountManager: AccountManager
@objc @objc
public var accountManager : AccountManager public var callNotificationsAdapter: CallNotificationsAdapter
@objc @objc
public var callNotificationsAdapter : CallNotificationsAdapter public var pushRegistrationManager: PushRegistrationManager
@objc @objc
public init(callMessageHandler : WebRTCCallMessageHandler, public init(callMessageHandler: WebRTCCallMessageHandler,
callService : CallService, callService: CallService,
outboundCallInitiator : OutboundCallInitiator, outboundCallInitiator: OutboundCallInitiator,
messageFetcherJob : MessageFetcherJob, messageFetcherJob: MessageFetcherJob,
notificationsManager : NotificationsManager, notificationsManager: NotificationsManager,
accountManager : AccountManager, accountManager: AccountManager,
callNotificationsAdapter : CallNotificationsAdapter) { callNotificationsAdapter: CallNotificationsAdapter,
pushRegistrationManager: PushRegistrationManager) {
self.callMessageHandler = callMessageHandler self.callMessageHandler = callMessageHandler
self.callService = callService self.callService = callService
self.outboundCallInitiator = outboundCallInitiator self.outboundCallInitiator = outboundCallInitiator
@ -56,15 +65,13 @@ import SignalMessaging
self.notificationsManager = notificationsManager self.notificationsManager = notificationsManager
self.accountManager = accountManager self.accountManager = accountManager
self.callNotificationsAdapter = callNotificationsAdapter self.callNotificationsAdapter = callNotificationsAdapter
self.pushRegistrationManager = pushRegistrationManager
super
.init() super.init()
SwiftSingletons.register(self) SwiftSingletons.register(self)
setup()
} }
private override init() { private override init() {
let accountManager = AccountManager() let accountManager = AccountManager()
let notificationsManager = NotificationsManager() let notificationsManager = NotificationsManager()
@ -73,7 +80,8 @@ import SignalMessaging
let callMessageHandler = WebRTCCallMessageHandler() let callMessageHandler = WebRTCCallMessageHandler()
let outboundCallInitiator = OutboundCallInitiator() let outboundCallInitiator = OutboundCallInitiator()
let messageFetcherJob = MessageFetcherJob() let messageFetcherJob = MessageFetcherJob()
let pushRegistrationManager = PushRegistrationManager()
self.callMessageHandler = callMessageHandler self.callMessageHandler = callMessageHandler
self.callService = callService self.callService = callService
self.outboundCallInitiator = outboundCallInitiator self.outboundCallInitiator = outboundCallInitiator
@ -81,15 +89,15 @@ import SignalMessaging
self.notificationsManager = notificationsManager self.notificationsManager = notificationsManager
self.accountManager = accountManager self.accountManager = accountManager
self.callNotificationsAdapter = callNotificationsAdapter self.callNotificationsAdapter = callNotificationsAdapter
self.pushRegistrationManager = pushRegistrationManager
super.init() super.init()
SwiftSingletons.register(self) SwiftSingletons.register(self)
setup()
} }
private func setup() { @objc
public func setup() {
callService.createCallUIAdapter() callService.createCallUIAdapter()
// Hang certain singletons on SSKEnvironment too. // Hang certain singletons on SSKEnvironment too.

@ -20,16 +20,21 @@ public enum PushRegistrationError: Error {
@objc public class PushRegistrationManager: NSObject, PKPushRegistryDelegate { @objc public class PushRegistrationManager: NSObject, PKPushRegistryDelegate {
// MARK: - Dependencies // MARK: - Dependencies
private var pushManager: PushManager { private var pushManager: PushManager {
return PushManager.shared() return PushManager.shared()
} }
// MARK: - Singleton class // MARK: - Singleton class
@objc(sharedManager) @objc
public static let shared = PushRegistrationManager() public static var shared: PushRegistrationManager {
get {
return AppEnvironment.shared.pushRegistrationManager
}
}
private override init() { override init() {
super.init() super.init()
SwiftSingletons.register(self) SwiftSingletons.register(self)

@ -52,6 +52,12 @@ class VerifyingTSAccountManager: FailingTSAccountManager {
class TokenObtainingTSAccountManager: VerifyingTSAccountManager { class TokenObtainingTSAccountManager: VerifyingTSAccountManager {
} }
class VerifyingPushRegistrationManager: PushRegistrationManager {
public override func requestPushTokens() -> Promise<(pushToken: String, voipToken: String)> {
return Promise.value(("a", "b"))
}
}
class AccountManagerTest: SignalBaseTest { class AccountManagerTest: SignalBaseTest {
override func setUp() { override func setUp() {
@ -112,6 +118,8 @@ class AccountManagerTest: SignalBaseTest {
let sskEnvironment = SSKEnvironment.shared as! MockSSKEnvironment let sskEnvironment = SSKEnvironment.shared as! MockSSKEnvironment
sskEnvironment.tsAccountManager = tsAccountManager sskEnvironment.tsAccountManager = tsAccountManager
AppEnvironment.shared.pushRegistrationManager = VerifyingPushRegistrationManager()
let accountManager = AccountManager() let accountManager = AccountManager()
let expectation = self.expectation(description: "should succeed") let expectation = self.expectation(description: "should succeed")

Loading…
Cancel
Save