Skip to content

Commit

Permalink
SystemInfo: fix flaky Storefront test (#3411)
Browse files Browse the repository at this point in the history
Follow up to #3405.

`SystemInfo.storefront` relies on `SKPaymentQueue`, which requires an
`SKTestSession`.
This is why this new test was being flaky. This new implementation
explicitly sets the storefront to fix that.
  • Loading branch information
NachoSoto authored Nov 14, 2023
1 parent 7d78633 commit 3442a83
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 10 additions & 0 deletions Tests/StoreKitUnitTests/StorefrontTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,14 @@ class StorefrontTests: StoreKitConfigTestCase {
}
}

func testSystemInfoStorefront() async throws {
let expected = "ESP"
try await self.changeStorefront(expected)

let systemInfo = SystemInfo(platformInfo: nil, finishTransactions: false)
let storefront = try XCTUnwrap(systemInfo.storefront)

expect(storefront.countryCode) == expected
}

}
10 changes: 4 additions & 6 deletions Tests/UnitTests/Misc/SystemInfoTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,12 @@ class SystemInfoTests: TestCase {
expect(SystemInfo.withReceiptResult(.receiptWithData, sandboxDetector).isSandbox) == false
}

func testStorefront() {
let storefront = SystemInfo(platformInfo: nil, finishTransactions: false).storefront

func testStorefrontForUnsupportedPlatforms() throws {
if #available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.2, macCatalyst 13.1, *) {
expect(storefront?.countryCode) == "USA"
} else {
expect(storefront).to(beNil())
throw XCTSkip("Test only for older platforms")
}

expect(SystemInfo.default.storefront).to(beNil())
}

func testIsAppleSubscriptionURLWithAnotherURL() {
Expand Down

0 comments on commit 3442a83

Please sign in to comment.