Skip to content

Commit

Permalink
BasePurchasesTests: changed default back to SK1 (#1935)
Browse files Browse the repository at this point in the history
Follow up to #1922. Most of the tests from the subclasses assume SK2 is
disabled. This changes the default for those back to SK1.
The tests that do require SK2, define so explicitly.

I also replaced a bunch of force-unwraps with `XCTUnwrap` so tests don't
crash (which is what was happening when running these tests with SK2
enabled).
  • Loading branch information
NachoSoto authored Sep 23, 2022
1 parent 4fffe83 commit 06b8009
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 48 deletions.
12 changes: 10 additions & 2 deletions Tests/UnitTests/Purchasing/Purchases/BasePurchasesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class BasePurchasesTests: TestCase {
try super.setUpWithError()

self.userDefaults = UserDefaults(suiteName: Self.userDefaultsSuiteName)
self.systemInfo = MockSystemInfo(finishTransactions: true)
self.systemInfo = MockSystemInfo(finishTransactions: true, storeKit2Setting: self.storeKit2Setting)
self.deviceCache = MockDeviceCache(sandboxEnvironmentDetector: self.systemInfo,
userDefaults: self.userDefaults)
self.requestFetcher = MockRequestFetcher()
Expand Down Expand Up @@ -146,7 +146,9 @@ class BasePurchasesTests: TestCase {
}

func setupPurchasesObserverModeOn() throws {
self.systemInfo = try MockSystemInfo(platformInfo: nil, finishTransactions: false)
self.systemInfo = try MockSystemInfo(platformInfo: nil,
finishTransactions: false,
storeKit2Setting: self.storeKit2Setting)
self.initializePurchasesInstance(appUserId: nil)
}

Expand Down Expand Up @@ -225,6 +227,12 @@ class BasePurchasesTests: TestCase {
self.storeKit1Wrapper.delegate?.storeKit1Wrapper(self.storeKit1Wrapper, updatedTransaction: transaction)
}

var storeKit2Setting: StoreKit2Setting {
// Even though the new default is StoreKit 2, most of the tests from this parent class
// were written for SK1. Therefore we want to default to it being disabled.
return .enabledOnlyForOptimizations
}

}

extension BasePurchasesTests {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,15 @@ class PurchaseDeferredPurchasesSK2Tests: BasePurchasesTests {
private var paymentQueueWrapperDelegate: PaymentQueueWrapperDelegate!
private var product: MockSK1Product!

override var storeKit2Setting: StoreKit2Setting {
return .enabledForCompatibleDevices
}

override func setUpWithError() throws {
try super.setUpWithError()

try AvailabilityChecks.iOS15APIAvailableOrSkipTest()

self.systemInfo = MockSystemInfo(finishTransactions: false, storeKit2Setting: .enabledForCompatibleDevices)

self.setupPurchases()

self.product = MockSK1Product(mockProductIdentifier: "mock_product")
Expand Down
Loading

0 comments on commit 06b8009

Please sign in to comment.