Skip to content

Commit

Permalink
Revert "Skip failing tests"
Browse files Browse the repository at this point in the history
This reverts commit 44ed38e.
  • Loading branch information
NachoSoto committed Sep 5, 2023
1 parent 4d842b1 commit 509e414
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ extension OfferingsManagerStoreKitTests {
var receivedProduct = try XCTUnwrap(receivedOfferings.current?.availablePackages.first?.storeProduct)
expect(receivedProduct.currencyCode) == "USD"

try self.changeLocale(identifier: "es_ES")
testSession.locale = Locale(identifier: "es_ES")
try await changeStorefront("ESP")

fetchedStoreProduct = try await fetchSk2StoreProduct()
Expand Down
8 changes: 4 additions & 4 deletions Tests/StoreKitUnitTests/PriceFormatterProviderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class PriceFormatterProviderTests: StoreKitConfigTestCase {
}

func testSk1PriceFormatterUsesCurrentStorefront() async throws {
try self.changeLocale(identifier: "es_ES")
self.testSession.locale = Locale(identifier: "es_ES")
try await self.changeStorefront("ESP")

let sk1Fetcher = ProductsFetcherSK1(requestTimeout: Configuration.storeKitRequestTimeoutDefault)
Expand All @@ -57,7 +57,7 @@ class PriceFormatterProviderTests: StoreKitConfigTestCase {
var priceFormatter = try XCTUnwrap(storeProduct.priceFormatter)
expect(priceFormatter.currencyCode) == "EUR"

try self.changeLocale(identifier: "en_EN")
self.testSession.locale = Locale(identifier: "en_EN")
try await self.changeStorefront("USA")

// Note: this test passes only because the cache is manually
Expand All @@ -76,7 +76,7 @@ class PriceFormatterProviderTests: StoreKitConfigTestCase {
func testSk2PriceFormatterUsesCurrentStorefront() async throws {
try AvailabilityChecks.iOS15APIAvailableOrSkipTest()

try self.changeLocale(identifier: "es_ES")
self.testSession.locale = Locale(identifier: "es_ES")
try await self.changeStorefront("ESP")

let sk2Fetcher = ProductsFetcherSK2()
Expand All @@ -86,7 +86,7 @@ class PriceFormatterProviderTests: StoreKitConfigTestCase {
var priceFormatter = try XCTUnwrap(storeProduct.priceFormatter)
expect(priceFormatter.currencyCode) == "EUR"

try self.changeLocale(identifier: "en_EN")
self.testSession.locale = Locale(identifier: "en_EN")
try await self.changeStorefront("USA")

storeProduct = try await sk2Fetcher.product(withIdentifier: Self.productID)
Expand Down
4 changes: 2 additions & 2 deletions Tests/StoreKitUnitTests/ProductsManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ProductsManagerTests: StoreKitConfigTestCase {
var unwrappedFirstProduct = try XCTUnwrap(receivedProducts?.first)
expect(unwrappedFirstProduct.currencyCode) == "USD"

try self.changeLocale(identifier: "es_ES")
testSession.locale = Locale(identifier: "es_ES")
try await changeStorefront("ESP")

// Note: this test passes only because the method `clearCache`
Expand Down Expand Up @@ -97,7 +97,7 @@ class ProductsManagerTests: StoreKitConfigTestCase {
var unwrappedFirstProduct = try XCTUnwrap(receivedProducts?.first)
expect(unwrappedFirstProduct.currencyCode) == "USD"

try self.changeLocale(identifier: "es_ES")
testSession.locale = Locale(identifier: "es_ES")
try await changeStorefront("ESP")

// Note: this test passes only because the method `clearCache`
Expand Down
34 changes: 0 additions & 34 deletions Tests/StoreKitUnitTests/StoreKitConfigTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,40 +100,6 @@ class StoreKitConfigTestCase: TestCase {

}

// MARK: - Locale

@available(iOS 14.0, tvOS 14.0, macOS 11.0, watchOS 7.0, *)
extension StoreKitConfigTestCase {

func changeLocale(identifier: String) throws {
try self.changeLocale(locale: .init(identifier: identifier))
}

func changeLocale(locale: Locale) throws {
try XCTSkipIf(
!Self.supportsChangingLocale,
"SKTestSession.locale is broken on this iOS version"
)

self.testSession.locale = locale
}

private static let supportsChangingLocale: Bool = {
// See:
// - https://github.com/XcodesOrg/xcodes/issues/295
// - https://github.com/RevenueCat/purchases-ios/pull/2421
// - FB12223404

let version = ProcessInfo.processInfo
.operatingSystemVersion
.majorVersion

return version == 12 || version >= 15
}()
}

// MARK: - Private

@available(iOS 14.0, tvOS 14.0, macOS 11.0, watchOS 7.0, *)
private extension StoreKitConfigTestCase {

Expand Down
8 changes: 4 additions & 4 deletions Tests/StoreKitUnitTests/StoreProductTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ class StoreProductTests: StoreKitConfigTestCase {
}

func testSk1PriceFormatterUsesCurrentStorefront() async throws {
try self.changeLocale(identifier: "es_ES")
testSession.locale = Locale(identifier: "es_ES")
try await self.changeStorefront("ESP")

let sk1Fetcher = ProductsFetcherSK1(requestTimeout: Configuration.storeKitRequestTimeoutDefault)
Expand All @@ -244,7 +244,7 @@ class StoreProductTests: StoreKitConfigTestCase {
expect(priceFormatter.string(from: productPrice)) == "4,99 €"
expect(storeProduct.currencyCode) == "EUR"

try self.changeLocale(identifier: "en_EN")
testSession.locale = Locale(identifier: "en_EN")
try await self.changeStorefront("USA")

// Note: this test passes only because the cache is manually
Expand All @@ -268,7 +268,7 @@ class StoreProductTests: StoreKitConfigTestCase {
func testSk2PriceFormatterReactsToStorefrontChanges() async throws {
try AvailabilityChecks.iOS15APIAvailableOrSkipTest()

try self.changeLocale(identifier: "es_ES")
testSession.locale = Locale(identifier: "es_ES")
try await self.changeStorefront("ESP")

let sk2Fetcher = ProductsFetcherSK2()
Expand All @@ -285,7 +285,7 @@ class StoreProductTests: StoreKitConfigTestCase {
expect(priceFormatter.string(from: productPrice)) == "4,99 €"
expect(storeProduct.currencyCode) == "EUR"

try self.changeLocale(identifier: "en_EN")
testSession.locale = Locale(identifier: "en_EN")
try await self.changeStorefront("USA")

storeProduct = try await sk2Fetcher.product(withIdentifier: Self.productID)
Expand Down

0 comments on commit 509e414

Please sign in to comment.