Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Momo Ozawa committed May 16, 2024
1 parent 30f0163 commit 26dc1da
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
44 changes: 44 additions & 0 deletions WordPress/WordPressTest/AppUpdate/AppUpdateCoordinatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ final class AppUpdateCoordinatorTests: XCTestCase {
private let service = MockAppStoreSearchService()
private let presenter = MockAppUpdatePresenter()
private let remoteConfigStore = RemoteConfigStoreMock()
private var store = UserDefaults(suiteName: "app-update-coordinator-tests")!

override func tearDown() {
super.tearDown()
store.removePersistentDomain(forName: "app-update-coordinator-tests")
}

func testInAppUpdatesDisabled() async {
// Given
Expand Down Expand Up @@ -58,6 +64,7 @@ final class AppUpdateCoordinatorTests: XCTestCase {
service: service,
presenter: presenter,
remoteConfigStore: remoteConfigStore,
store: store,
isLoggedIn: false,
isInAppUpdatesEnabled: true,
delayInDays: Int.max
Expand All @@ -80,6 +87,7 @@ final class AppUpdateCoordinatorTests: XCTestCase {
service: service,
presenter: presenter,
remoteConfigStore: remoteConfigStore,
store: store,
isJetpack: true,
isLoggedIn: true,
isInAppUpdatesEnabled: true
Expand All @@ -102,6 +110,7 @@ final class AppUpdateCoordinatorTests: XCTestCase {
service: service,
presenter: presenter,
remoteConfigStore: remoteConfigStore,
store: store,
isJetpack: true,
isLoggedIn: true,
isInAppUpdatesEnabled: true
Expand All @@ -125,10 +134,12 @@ final class AppUpdateCoordinatorTests: XCTestCase {
service: service,
presenter: presenter,
remoteConfigStore: remoteConfigStore,
store: store,
isJetpack: true,
isLoggedIn: true,
isInAppUpdatesEnabled: true
)
remoteConfigStore.inAppUpdateFlexibleIntervalInDays = 5

// When
await coordinator.checkForAppUpdates()
Expand All @@ -139,6 +150,39 @@ final class AppUpdateCoordinatorTests: XCTestCase {
XCTAssertFalse(presenter.didShowBlockingUpdate)
}

func testFlexibleUpdateAvailableShownOnceWithinInterval() async {
// Given
let coordinator = AppUpdateCoordinator(
currentVersion: "24.6",
currentOsVersion: "17.0",
service: service,
presenter: presenter,
remoteConfigStore: remoteConfigStore,
store: store,
isJetpack: true,
isLoggedIn: true,
isInAppUpdatesEnabled: true
)
remoteConfigStore.inAppUpdateFlexibleIntervalInDays = 5

// When
await coordinator.checkForAppUpdates()

// Then
XCTAssertTrue(service.didLookup)
XCTAssertTrue(presenter.didShowNotice)
XCTAssertFalse(presenter.didShowBlockingUpdate)

// When we check for updates again within the flexible interval
presenter.didShowNotice = false // Reset
await coordinator.checkForAppUpdates()

// Then the flexible notice isn't shown again
XCTAssertTrue(service.didLookup)
XCTAssertFalse(presenter.didShowNotice)
XCTAssertFalse(presenter.didShowBlockingUpdate)
}

func testBlockingUpdateAvailable() async {
// Given
let coordinator = AppUpdateCoordinator(
Expand Down
4 changes: 4 additions & 0 deletions WordPress/WordPressTest/RemoteConfigStoreMock.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class RemoteConfigStoreMock: RemoteConfigStore {
var blazeNonDismissibleStep: String?
var blazeFlowCompletedStep: String?
var jetpackInAppUpdateBlockingVersion: String?
var inAppUpdateFlexibleIntervalInDays: Int?

override func value(for key: String) -> Any? {
if key == "phase_three_blog_post" {
Expand All @@ -33,6 +34,9 @@ class RemoteConfigStoreMock: RemoteConfigStore {
if key == "jp_in_app_update_blocking_version_ios" {
return jetpackInAppUpdateBlockingVersion
}
if key == "in_app_update_flexible_interval_in_days_ios" {
return inAppUpdateFlexibleIntervalInDays
}
return super.value(for: key)
}
}

0 comments on commit 26dc1da

Please sign in to comment.