Skip to content

Commit 67df2ad

Browse files
committed
Add PN re-registration on store change tests
1 parent 681c149 commit 67df2ad

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

WooCommerce/WooCommerceTests/Mocks/MockPushNotificationsManager.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ final class MockPushNotificationsManager: PushNotesManager {
5757
private(set) var canceledLocalNotificationScenarios: [[LocalNotification.Scenario]] = []
5858
private(set) var resetBadgeCountKinds: [Note.Kind] = []
5959
var onRequestLocalNotificationCalled: (() -> Void)?
60+
private(set) var registerForRemoteNotificationsCallCount = 0
61+
var onRegisterForRemoteNotifications: (() -> Void)?
62+
private(set) var ensureAuthorizationIsRequestedCallCount = 0
63+
var onEnsureAuthorizationIsRequested: (() -> Void)?
6064

6165
init(mockedDeviceID: String? = nil) {
6266
self.mockedDeviceID = mockedDeviceID
@@ -75,15 +79,18 @@ final class MockPushNotificationsManager: PushNotesManager {
7579
}
7680

7781
func registerForRemoteNotifications() {
78-
82+
registerForRemoteNotificationsCallCount += 1
83+
onRegisterForRemoteNotifications?()
7984
}
8085

8186
func unregisterForRemoteNotifications() {
8287

8388
}
8489

8590
func ensureAuthorizationIsRequested(includesProvisionalAuth: Bool, onCompletion: ((Bool) -> ())?) {
86-
91+
ensureAuthorizationIsRequestedCallCount += 1
92+
onEnsureAuthorizationIsRequested?()
93+
onCompletion?(true)
8794
}
8895

8996
func registrationDidFail(with error: Error) {

WooCommerce/WooCommerceTests/Yosemite/StoresManagerTests.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,28 @@ final class StoresManagerTests: XCTestCase {
246246
XCTAssertEqual(siteIDValues, [nil, siteID, nil])
247247
}
248248

249+
func test_updateDefaultStore_registersForRemoteNotifications() {
250+
// Arrange
251+
let pushNotificationsManager = MockPushNotificationsManager()
252+
ServiceLocator.setPushNotesManager(pushNotificationsManager)
253+
defer {
254+
ServiceLocator.setPushNotesManager(PushNotificationsManager())
255+
}
256+
let manager = DefaultStoresManager.testingInstance
257+
let expectation = expectation(description: "register called")
258+
pushNotificationsManager.onRegisterForRemoteNotifications = {
259+
expectation.fulfill()
260+
}
261+
262+
// Action
263+
manager.updateDefaultStore(storeID: 1_234)
264+
265+
// Assert
266+
wait(for: [expectation], timeout: 1.0)
267+
XCTAssertEqual(pushNotificationsManager.registerForRemoteNotificationsCallCount, 1)
268+
XCTAssertEqual(pushNotificationsManager.ensureAuthorizationIsRequestedCallCount, 1)
269+
}
270+
249271
// MARK: `updateDefaultStore(_ site: Site)`
250272

251273
func test_updateDefaultStore_with_the_same_siteID_updates_site_but_does_not_emit_siteID() {

0 commit comments

Comments
 (0)