-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MOB-9446] Enhance push notification state tracking in SDKs (#881)
Co-authored-by: Megha Pithadiya <[email protected]> Co-authored-by: Joao Dordio <[email protected]> Co-authored-by: Evan Greer <[email protected]> Co-authored-by: Sumeru Chatterjee <[email protected]>
- Loading branch information
1 parent
75193e8
commit 6f00e45
Showing
10 changed files
with
159 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ class AutoRegistrationTests: XCTestCase { | |
|
||
func testCallDisableAndEnable() { | ||
let expectation1 = expectation(description: "call register device API") | ||
expectation1.expectedFulfillmentCount = 2 | ||
let expectation2 = expectation(description: "call registerForRemoteNotifications twice") | ||
expectation2.expectedFulfillmentCount = 2 | ||
let expectation3 = expectation(description: "call disable on [email protected]") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import XCTest | ||
@testable import IterableSDK | ||
|
||
class NotificationObserverTests: XCTestCase { | ||
private var internalAPI: InternalIterableAPI! | ||
private var mockNotificationStateProvider: MockNotificationStateProvider! | ||
private var mockLocalStorage: MockLocalStorage! | ||
private var mockNotificationCenter: MockNotificationCenter! | ||
|
||
override func setUp() { | ||
super.setUp() | ||
|
||
mockNotificationStateProvider = MockNotificationStateProvider(enabled: false) | ||
mockLocalStorage = MockLocalStorage() | ||
mockNotificationCenter = MockNotificationCenter() | ||
|
||
let config = IterableConfig() | ||
internalAPI = InternalIterableAPI.initializeForTesting( | ||
config: config, | ||
notificationStateProvider: mockNotificationStateProvider, | ||
localStorage: mockLocalStorage, | ||
notificationCenter: mockNotificationCenter | ||
) | ||
} | ||
|
||
func testNotificationStateChangeUpdatesStorage() { | ||
// Arrange | ||
internalAPI.email = "[email protected]" | ||
|
||
mockLocalStorage.isNotificationsEnabled = false | ||
mockNotificationStateProvider.enabled = true | ||
|
||
// Act | ||
mockNotificationCenter.post(name: UIApplication.didBecomeActiveNotification, object: nil, userInfo: nil) | ||
|
||
// Small delay to allow async operation to complete | ||
let expectation = XCTestExpectation(description: "Wait for state update") | ||
DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { | ||
expectation.fulfill() | ||
} | ||
wait(for: [expectation], timeout: 1.0) | ||
|
||
// Assert | ||
XCTAssertTrue(mockLocalStorage.isNotificationsEnabled) | ||
} | ||
} |