Only register for notifications when the setting is enabled. (#2819)

This commit is contained in:
Doug
2024-05-08 16:10:35 +01:00
committed by GitHub
parent 636274df74
commit d97f912df7
3 changed files with 34 additions and 1 deletions
@@ -163,6 +163,38 @@ final class NotificationManagerTests: XCTestCase {
await fulfillment(of: [expectation])
XCTAssertTrue(authorizationStatusWasGranted)
}
func test_whenStartAndAuthorizedAndNotificationDisabled_registerForRemoteNotificationsNotCalled() async throws {
appSettings.enableNotifications = false
notificationCenter.authorizationStatusReturnValue = .authorized
notificationManager.delegate = self
notificationManager.setUserSession(MockUserSession(clientProxy: ClientProxyMock(),
mediaProvider: MockMediaProvider(),
voiceMessageMediaManager: VoiceMessageMediaManagerMock()))
try await Task.sleep(for: .seconds(1))
XCTAssertFalse(authorizationStatusWasGranted)
}
func test_whenStartAndAuthorized_registerForRemoteNotificationsCalled() async throws {
appSettings.enableNotifications = true
notificationCenter.authorizationStatusReturnValue = .authorized
notificationManager.delegate = self
let expectation: XCTestExpectation = expectation(description: "registerForRemoteNotifications delegate function should be called")
expectation.assertForOverFulfill = false
registerForRemoteNotificationsDelegateCalled = {
expectation.fulfill()
}
notificationManager.setUserSession(MockUserSession(clientProxy: ClientProxyMock(),
mediaProvider: MockMediaProvider(),
voiceMessageMediaManager: VoiceMessageMediaManagerMock()))
await fulfillment(of: [expectation])
XCTAssertTrue(authorizationStatusWasGranted)
}
func test_whenWillPresentNotificationsDelegateNotSet_CorrectPresentationOptionsReturned() async throws {
let archiver = MockCoder(requiringSecureCoding: false)