From 3442a836d18f2bb015c046e035440fd459dbf086 Mon Sep 17 00:00:00 2001 From: NachoSoto Date: Tue, 14 Nov 2023 15:03:15 -0800 Subject: [PATCH] `SystemInfo`: fix flaky `Storefront` test (#3411) 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. --- Tests/StoreKitUnitTests/StorefrontTests.swift | 10 ++++++++++ Tests/UnitTests/Misc/SystemInfoTests.swift | 10 ++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Tests/StoreKitUnitTests/StorefrontTests.swift b/Tests/StoreKitUnitTests/StorefrontTests.swift index 1c64ff8ccc..330724c01d 100644 --- a/Tests/StoreKitUnitTests/StorefrontTests.swift +++ b/Tests/StoreKitUnitTests/StorefrontTests.swift @@ -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 + } + } diff --git a/Tests/UnitTests/Misc/SystemInfoTests.swift b/Tests/UnitTests/Misc/SystemInfoTests.swift index 8e53969b99..762a1f850b 100644 --- a/Tests/UnitTests/Misc/SystemInfoTests.swift +++ b/Tests/UnitTests/Misc/SystemInfoTests.swift @@ -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() {