From 3252a91811b590410e94c6296f8e00e3811a2fd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanpe=20Catala=CC=81n?= Date: Fri, 6 Aug 2021 17:22:52 +0200 Subject: [PATCH 1/3] enable all platforms in test targets --- Purchases.xcodeproj/project.pbxproj | 14 ++- Purchases/Attribution/RCAttributionFetcher.m | 4 +- PurchasesCoreSwift/Misc/SystemInfo.swift | 2 +- .../Mocks/MockProductsManager.swift | 2 +- .../Mocks/MockSKDiscount.swift | 4 +- .../Mocks/MockSKProduct.swift | 10 +- .../ProductInfoExtractorTests.swift | 14 +-- .../Purchasing/ProductInfoTests.swift | 109 +++++++++--------- .../Purchasing/StoreKitWrapperTests.swift | 10 +- .../SubscriberAttributeTests.swift | 1 - .../Attribution/AttributionFetcherTests.swift | 40 +++++-- .../NSError+RCExtensionsTests.swift | 1 - .../Mocks/MockAttributionTypeFactory.swift | 12 +- .../Mocks/MockProductDiscount.swift | 2 +- PurchasesTests/Mocks/MockSKDiscount.swift | 6 +- PurchasesTests/Mocks/MockSKProduct.swift | 10 +- PurchasesTests/Networking/BackendTests.swift | 1 - .../Networking/HTTPClientTests.swift | 61 +++++----- .../Purchasing/PurchasesTests.swift | 14 +-- .../StoreKitRequestFetcherTests.swift | 1 - .../BackendSubscriberAttributesTests.swift | 1 - .../PurchasesSubscriberAttributesTests.swift | 4 +- .../SubscriberAttributesManagerTests.swift | 1 - fastlane/Scanfile | 2 +- 24 files changed, 179 insertions(+), 147 deletions(-) diff --git a/Purchases.xcodeproj/project.pbxproj b/Purchases.xcodeproj/project.pbxproj index f94db58ca1..9acd631591 100644 --- a/Purchases.xcodeproj/project.pbxproj +++ b/Purchases.xcodeproj/project.pbxproj @@ -2114,10 +2114,11 @@ PRODUCT_BUNDLE_IDENTIFIER = com.revenuecat.PurchasesCoreSwiftTests; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; + SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx watchsimulator watchos appletvsimulator appletvos"; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; + TARGETED_DEVICE_FAMILY = "1,2,3,4,6"; TVOS_DEPLOYMENT_TARGET = 9.0; WATCHOS_DEPLOYMENT_TARGET = 6.2; }; @@ -2143,8 +2144,9 @@ PRODUCT_BUNDLE_IDENTIFIER = com.revenuecat.PurchasesCoreSwiftTests; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; + SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx watchsimulator watchos appletvsimulator appletvos"; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; + TARGETED_DEVICE_FAMILY = "1,2,3,4,6"; TVOS_DEPLOYMENT_TARGET = 9.0; WATCHOS_DEPLOYMENT_TARGET = 6.2; }; @@ -2456,13 +2458,13 @@ PRODUCT_BUNDLE_IDENTIFIER = com.purchases.PurchasesTests; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; - SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx"; + SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx watchsimulator watchos appletvsimulator appletvos"; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OBJC_BRIDGING_HEADER = "PurchasesTests/PurchasesTests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_PRECOMPILE_BRIDGING_HEADER = YES; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; + TARGETED_DEVICE_FAMILY = "1,2,3,4,6"; TVOS_DEPLOYMENT_TARGET = 9.0; WATCHOS_DEPLOYMENT_TARGET = 6.2; }; @@ -2486,13 +2488,13 @@ PRODUCT_BUNDLE_IDENTIFIER = com.purchases.PurchasesTests; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; - SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx"; + SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx watchsimulator watchos appletvsimulator appletvos"; SWIFT_COMPILATION_MODE = wholemodule; SWIFT_OBJC_BRIDGING_HEADER = "PurchasesTests/PurchasesTests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-O"; SWIFT_PRECOMPILE_BRIDGING_HEADER = YES; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2"; + TARGETED_DEVICE_FAMILY = "1,2,3,4,6"; TVOS_DEPLOYMENT_TARGET = 9.0; WATCHOS_DEPLOYMENT_TARGET = 6.2; }; diff --git a/Purchases/Attribution/RCAttributionFetcher.m b/Purchases/Attribution/RCAttributionFetcher.m index d484ce1b7f..1e2c2f654a 100644 --- a/Purchases/Attribution/RCAttributionFetcher.m +++ b/Purchases/Attribution/RCAttributionFetcher.m @@ -70,7 +70,7 @@ - (nullable NSString *)identifierForVendor { - (void)adClientAttributionDetailsWithCompletionBlock:(RCAttributionDetailsBlock)completionHandler { // Should match available platforms in // https://developer.apple.com/documentation/iad/adclient?language=objc - #if TARGET_OS_IOS + #if TARGET_OS_IOS || TARGET_OS_MACCATALYST RCAdClientProxy * _Nullable adClientProxy = [self.attributionFactory adClientProxy]; if (!adClientProxy) { [RCLog warn:[NSString stringWithFormat:@"%@", @@ -78,6 +78,8 @@ - (void)adClientAttributionDetailsWithCompletionBlock:(RCAttributionDetailsBlock return; } [adClientProxy requestAttributionDetailsWithBlock:completionHandler]; + #else + completionHandler([NSDictionary new], nil); #endif } diff --git a/PurchasesCoreSwift/Misc/SystemInfo.swift b/PurchasesCoreSwift/Misc/SystemInfo.swift index f2608045d1..96b484213c 100644 --- a/PurchasesCoreSwift/Misc/SystemInfo.swift +++ b/PurchasesCoreSwift/Misc/SystemInfo.swift @@ -155,7 +155,7 @@ private extension SystemInfo { #elseif os(macOS) return false #elseif os(watchOS) - return WKExtension.shared().applicationState == WKApplicationState.background + return WKExtension.shared().applicationState == WKApplicationState.background #endif } diff --git a/PurchasesCoreSwiftTests/Mocks/MockProductsManager.swift b/PurchasesCoreSwiftTests/Mocks/MockProductsManager.swift index 8d7717cbfb..8bc3a8a215 100644 --- a/PurchasesCoreSwiftTests/Mocks/MockProductsManager.swift +++ b/PurchasesCoreSwiftTests/Mocks/MockProductsManager.swift @@ -26,7 +26,7 @@ class MockProductsManager: ProductsManager { let products: [SKProduct] = identifiers.map { (identifier) -> MockSKProduct in let p = MockSKProduct(mockProductIdentifier: identifier) p.mockSubscriptionGroupIdentifier = "1234567" - if #available(iOS 12.2, *) { + if #available(iOS 12.2, tvOS 11.2, macOS 10.13.2, *) { let mockDiscount = MockDiscount() mockDiscount.mockIdentifier = "discount_id" p.mockDiscount = mockDiscount diff --git a/PurchasesCoreSwiftTests/Mocks/MockSKDiscount.swift b/PurchasesCoreSwiftTests/Mocks/MockSKDiscount.swift index db7340ee97..597c3534a4 100644 --- a/PurchasesCoreSwiftTests/Mocks/MockSKDiscount.swift +++ b/PurchasesCoreSwiftTests/Mocks/MockSKDiscount.swift @@ -6,7 +6,7 @@ import Foundation import StoreKit -@available(iOS 11.2, *) +@available(iOS 11.2, tvOS 11.2, macOS 10.13.2, *) class MockDiscount: SKProductDiscount { var mockPaymentMode: SKProductDiscount.PaymentMode? override var paymentMode: SKProductDiscount.PaymentMode { @@ -23,10 +23,8 @@ class MockDiscount: SKProductDiscount { return mockIdentifier ?? "identifier" } - @available(iOS 11.2, *) lazy var mockSubscriptionPeriod: SKProductSubscriptionPeriod? = nil - @available(iOS 11.2, *) override var subscriptionPeriod: SKProductSubscriptionPeriod { return mockSubscriptionPeriod ?? SKProductSubscriptionPeriod(numberOfUnits: 1, unit:.month) } diff --git a/PurchasesCoreSwiftTests/Mocks/MockSKProduct.swift b/PurchasesCoreSwiftTests/Mocks/MockSKProduct.swift index bd966b79b3..9203c22431 100644 --- a/PurchasesCoreSwiftTests/Mocks/MockSKProduct.swift +++ b/PurchasesCoreSwiftTests/Mocks/MockSKProduct.swift @@ -32,7 +32,7 @@ class MockSKProduct: SKProduct { return mockPrice ?? 2.99 as NSDecimalNumber } - @available(iOS 11.2, *) + @available(iOS 11.2, tvOS 11.2, macOS 10.13.2, *) override var introductoryPrice: SKProductDiscount? { if #available(iOS 12.2, *) { return mockDiscount ?? MockDiscount() @@ -41,18 +41,18 @@ class MockSKProduct: SKProduct { } } - @available(iOS 12.2, *) + @available(iOS 12.2, tvOS 11.2, macOS 10.13.2, *) lazy var mockDiscount: SKProductDiscount? = nil - @available(iOS 12.2, *) + @available(iOS 12.2, tvOS 11.2, macOS 10.13.2, *) override var discounts: [SKProductDiscount] { return (mockDiscount != nil) ? [mockDiscount!] : [] } - @available(iOS 11.2, *) + @available(iOS 11.2, tvOS 11.2, macOS 10.13.2, *) lazy var mockSubscriptionPeriod: SKProductSubscriptionPeriod? = nil - @available(iOS 11.2, *) + @available(iOS 11.2, tvOS 11.2, macOS 10.13.2, *) override var subscriptionPeriod: SKProductSubscriptionPeriod { return mockSubscriptionPeriod ?? SKProductSubscriptionPeriod(numberOfUnits: 1, unit:.month) } diff --git a/PurchasesCoreSwiftTests/Purchasing/ProductInfoExtractorTests.swift b/PurchasesCoreSwiftTests/Purchasing/ProductInfoExtractorTests.swift index 371110c8bd..fb33bed68c 100644 --- a/PurchasesCoreSwiftTests/Purchasing/ProductInfoExtractorTests.swift +++ b/PurchasesCoreSwiftTests/Purchasing/ProductInfoExtractorTests.swift @@ -43,7 +43,7 @@ class ProductInfoExtractorTests: XCTestCase { func testExtractInfoFromProductExtractsPaymentMode() { let product = MockSKProduct(mockProductIdentifier: "cool_product") - if #available(iOS 12.2, *) { + if #available(iOS 12.2, tvOS 11.2, macOS 10.13.2, *) { let mockDiscount = MockDiscount() mockDiscount.mockPaymentMode = .freeTrial @@ -65,7 +65,7 @@ class ProductInfoExtractorTests: XCTestCase { func testExtractInfoFromProductExtractsIntroPrice() { let product = MockSKProduct(mockProductIdentifier: "cool_product") - if #available(iOS 12.2, *) { + if #available(iOS 12.2, tvOS 11.2, macOS 10.13.2, *) { let mockDiscount = MockDiscount() mockDiscount.mockPrice = 10.99 @@ -87,7 +87,7 @@ class ProductInfoExtractorTests: XCTestCase { func testExtractInfoFromProductExtractsNormalDuration() { let product = MockSKProduct(mockProductIdentifier: "cool_product") - if #available(iOS 11.2, *) { + if #available(iOS 11.2, tvOS 11.2, macOS 10.13.2, *) { product.mockSubscriptionPeriod = SKProductSubscriptionPeriod(numberOfUnits: 2, unit: .month) let productInfoExtractor = ProductInfoExtractor() @@ -106,7 +106,7 @@ class ProductInfoExtractorTests: XCTestCase { func testExtractInfoFromProductDoesNotExtractNormalDurationIfSubscriptionPeriodIsZero() { let product = MockSKProduct(mockProductIdentifier: "cool_product") - if #available(iOS 11.2, *) { + if #available(iOS 11.2, tvOS 11.2, macOS 10.13.2, *) { product.mockSubscriptionPeriod = SKProductSubscriptionPeriod(numberOfUnits: 0, unit: .month) let productInfoExtractor = ProductInfoExtractor() @@ -125,7 +125,7 @@ class ProductInfoExtractorTests: XCTestCase { func testExtractInfoFromProductExtractsIntroDuration() { let product = MockSKProduct(mockProductIdentifier: "cool_product") - if #available(iOS 12.2, *) { + if #available(iOS 12.2, tvOS 11.2, macOS 10.13.2, *) { let mockDiscount = MockDiscount() mockDiscount.mockSubscriptionPeriod = SKProductSubscriptionPeriod(numberOfUnits: 3, unit: .year) @@ -147,7 +147,7 @@ class ProductInfoExtractorTests: XCTestCase { func testExtractInfoFromProductExtractsIntroDurationType() { let product = MockSKProduct(mockProductIdentifier: "cool_product") - if #available(iOS 12.2, macOS 10.14.4, *) { + if #available(iOS 12.2, macOS 10.14.4, tvOS 11.2, *) { let mockDiscount = MockDiscount() mockDiscount.mockPaymentMode = .freeTrial @@ -189,7 +189,7 @@ class ProductInfoExtractorTests: XCTestCase { func testExtractInfoFromProductExtractsDiscounts() { let product = MockSKProduct(mockProductIdentifier: "cool_product") - if #available(iOS 12.2, *) { + if #available(iOS 12.2, tvOS 11.2, macOS 10.13.2, *) { let mockDiscount = MockDiscount() let paymentMode: SKProductDiscount.PaymentMode = .freeTrial mockDiscount.mockPaymentMode = paymentMode diff --git a/PurchasesCoreSwiftTests/Purchasing/ProductInfoTests.swift b/PurchasesCoreSwiftTests/Purchasing/ProductInfoTests.swift index 1482a4a23d..2141c10730 100644 --- a/PurchasesCoreSwiftTests/Purchasing/ProductInfoTests.swift +++ b/PurchasesCoreSwiftTests/Purchasing/ProductInfoTests.swift @@ -88,63 +88,62 @@ class ProductInfoTests: XCTestCase { let productInfo: ProductInfo = .createMockProductInfo(subscriptionGroup: subscriptionGroup) expect(productInfo.asDictionary()["subscription_group_id"] as? String) == subscriptionGroup } - + func testAsDictionaryConvertsDiscountsCorrectly() { - if #available(macOS 10.14.4, *) { - - - let discount1 = PromotionalOffer(withProductDiscount: MockProductDiscount(identifier: "offerid1", - paymentMode: .payAsYouGo, - price: 11)) - let discount2 = PromotionalOffer(withProductDiscount: MockProductDiscount(identifier: "offerid2", - paymentMode: .payUpFront, - price: 12)) - let discount3 = PromotionalOffer(withProductDiscount: MockProductDiscount(identifier: "offerid3", - paymentMode: .freeTrial, - price: 13)) - - let productInfo: ProductInfo = .createMockProductInfo(discounts: [discount1, discount2, discount3]) - - expect(productInfo.asDictionary()["offers"] as? [[String: NSObject]]).toNot(beNil()) - guard let receivedOffers = productInfo.asDictionary()["offers"] as? [[String: NSObject]] else { fatalError() } - - expect(receivedOffers[0]["offer_identifier"] as? String) == discount1.offerIdentifier - expect(receivedOffers[0]["price"] as? NSDecimalNumber) == discount1.price - expect((receivedOffers[0]["payment_mode"] as? NSNumber)?.intValue) == discount1.paymentMode.rawValue - - expect(receivedOffers[1]["offer_identifier"] as? String) == discount2.offerIdentifier - expect(receivedOffers[1]["price"] as? NSDecimalNumber) == discount2.price - expect((receivedOffers[1]["payment_mode"] as? NSNumber)?.intValue) == discount2.paymentMode.rawValue - - expect(receivedOffers[2]["offer_identifier"] as? String) == discount3.offerIdentifier - expect(receivedOffers[2]["price"] as? NSDecimalNumber) == discount3.price - expect((receivedOffers[2]["payment_mode"] as? NSNumber)?.intValue) == discount3.paymentMode.rawValue - } + let discount1 = PromotionalOffer(offerIdentifier: "offerid1", + price: NSDecimalNumber(decimal: 11), + paymentMode: .payAsYouGo) + + let discount2 = PromotionalOffer(offerIdentifier: "offerid2", + price: NSDecimalNumber(decimal: 12), + paymentMode: .payUpFront) + + let discount3 = PromotionalOffer(offerIdentifier: "offerid3", + price: NSDecimalNumber(decimal: 13), + paymentMode: .freeTrial) + + let productInfo: ProductInfo = .createMockProductInfo(discounts: [discount1, discount2, discount3]) + + expect(productInfo.asDictionary()["offers"] as? [[String: NSObject]]).toNot(beNil()) + guard let receivedOffers = productInfo.asDictionary()["offers"] as? [[String: NSObject]] else { fatalError() } + + expect(receivedOffers[0]["offer_identifier"] as? String) == discount1.offerIdentifier + expect(receivedOffers[0]["price"] as? NSDecimalNumber) == discount1.price + expect((receivedOffers[0]["payment_mode"] as? NSNumber)?.intValue) == discount1.paymentMode.rawValue + + expect(receivedOffers[1]["offer_identifier"] as? String) == discount2.offerIdentifier + expect(receivedOffers[1]["price"] as? NSDecimalNumber) == discount2.price + expect((receivedOffers[1]["payment_mode"] as? NSNumber)?.intValue) == discount2.paymentMode.rawValue + + expect(receivedOffers[2]["offer_identifier"] as? String) == discount3.offerIdentifier + expect(receivedOffers[2]["price"] as? NSDecimalNumber) == discount3.price + expect((receivedOffers[2]["payment_mode"] as? NSNumber)?.intValue) == discount3.paymentMode.rawValue + } - + func testCacheKey() { - if #available(macOS 10.14.4, *) { - let discount1 = PromotionalOffer(withProductDiscount: MockProductDiscount(identifier: "offerid1", - paymentMode: .payAsYouGo, - price: 11)) - let discount2 = PromotionalOffer(withProductDiscount: MockProductDiscount(identifier: "offerid2", - paymentMode: .payUpFront, - price: 12)) - let discount3 = PromotionalOffer(withProductDiscount: MockProductDiscount(identifier: "offerid3", - paymentMode: .freeTrial, - price: 13)) - - let productInfo: ProductInfo = .createMockProductInfo(productIdentifier: "cool_product", - paymentMode: .payUpFront, - currencyCode: "UYU", - price: 49.99, - normalDuration: "P3Y", - introDuration: "P3W", - introDurationType: .freeTrial, - introPrice: 0, - subscriptionGroup: "cool_group", - discounts: [discount1, discount2, discount3]) - expect(productInfo.cacheKey) == "cool_product-49.99-UYU-1-0-cool_group-P3Y-P3W-0-offerid1-offerid2-offerid3" - } + let discount1 = PromotionalOffer(offerIdentifier: "offerid1", + price: NSDecimalNumber(decimal: 11), + paymentMode: .payAsYouGo) + + let discount2 = PromotionalOffer(offerIdentifier: "offerid2", + price: NSDecimalNumber(decimal: 12), + paymentMode: .payUpFront) + + let discount3 = PromotionalOffer(offerIdentifier: "offerid3", + price: NSDecimalNumber(decimal: 13), + paymentMode: .freeTrial) + + let productInfo: ProductInfo = .createMockProductInfo(productIdentifier: "cool_product", + paymentMode: .payUpFront, + currencyCode: "UYU", + price: 49.99, + normalDuration: "P3Y", + introDuration: "P3W", + introDurationType: .freeTrial, + introPrice: 0, + subscriptionGroup: "cool_group", + discounts: [discount1, discount2, discount3]) + expect(productInfo.cacheKey) == "cool_product-49.99-UYU-1-0-cool_group-P3Y-P3W-0-offerid1-offerid2-offerid3" } } diff --git a/PurchasesCoreSwiftTests/Purchasing/StoreKitWrapperTests.swift b/PurchasesCoreSwiftTests/Purchasing/StoreKitWrapperTests.swift index 9b58ec2c23..4312650156 100644 --- a/PurchasesCoreSwiftTests/Purchasing/StoreKitWrapperTests.swift +++ b/PurchasesCoreSwiftTests/Purchasing/StoreKitWrapperTests.swift @@ -8,7 +8,6 @@ import Foundation import XCTest -import OHHTTPStubs import Nimble @testable import PurchasesCoreSwift @@ -99,7 +98,8 @@ class StoreKitWrapperTests: XCTestCase, StoreKitWrapperDelegate { expect(self.updatedTransactions).to(contain(transaction)) } - @available(iOS 11.0, *) + #if !os(watchOS) + @available(iOS 11.0, tvOS 11.0, macOS 11.0, macCatalyst 14.0, *) func testCallsDelegateWhenPromoPurchaseIsAvailable() { let product = SKProduct.init(); let payment = SKPayment.init(product: product) @@ -108,8 +108,10 @@ class StoreKitWrapperTests: XCTestCase, StoreKitWrapperDelegate { expect(self.promoPayment).to(be(payment)); expect(self.promoProduct).to(be(product)) } + #endif - @available(iOS 11.0, *) + #if !os(watchOS) + @available(iOS 11.0, tvOS 11.0, macOS 11.0, macCatalyst 14.0, *) func testPromoDelegateMethodPassesBackReturnValueFromOwnDelegate() { let product = SKProduct.init(); let payment = SKPayment.init(product: product) @@ -120,6 +122,7 @@ class StoreKitWrapperTests: XCTestCase, StoreKitWrapperDelegate { expect(result).to(equal(self.shouldAddPromo)) } + #endif func testCallsDelegateOncePerTransaction() { let payment1 = SKPayment.init(product: SKProduct.init()) @@ -199,6 +202,7 @@ class StoreKitWrapperTests: XCTestCase, StoreKitWrapperDelegate { expect(payment.productIdentifier) == productId } + @available(macOS 10.14, *) func testPaymentWithProductSetsSimulatesAskToBuyInSandbox() { guard let wrapper = wrapper else { fatalError("wrapper is not initialized!") } diff --git a/PurchasesCoreSwiftTests/SubscriberAttributes/SubscriberAttributeTests.swift b/PurchasesCoreSwiftTests/SubscriberAttributes/SubscriberAttributeTests.swift index 60ea9ca535..b6ad78dfc5 100644 --- a/PurchasesCoreSwiftTests/SubscriberAttributes/SubscriberAttributeTests.swift +++ b/PurchasesCoreSwiftTests/SubscriberAttributes/SubscriberAttributeTests.swift @@ -4,7 +4,6 @@ // import XCTest -import OHHTTPStubs import Nimble @testable import PurchasesCoreSwift diff --git a/PurchasesTests/Attribution/AttributionFetcherTests.swift b/PurchasesTests/Attribution/AttributionFetcherTests.swift index d886ab2815..24ceadeff4 100644 --- a/PurchasesTests/Attribution/AttributionFetcherTests.swift +++ b/PurchasesTests/Attribution/AttributionFetcherTests.swift @@ -57,9 +57,12 @@ class AttributionFetcherTests: XCTestCase { } private func resetAttributionStaticProperties() { + #if !os(watchOS) if #available(iOS 14, macOS 11, tvOS 14, *) { MockTrackingManagerProxy.mockAuthorizationStatus = .authorized } + #endif + MockAttributionTypeFactory.shouldReturnAdClientProxy = true MockAttributionTypeFactory.shouldReturnTrackingManagerProxy = true MockAdClientProxy.requestAttributionDetailsCallCount = 0 @@ -161,7 +164,8 @@ class AttributionFetcherTests: XCTestCase { } func testPostAppleSearchAdsAttributionIfNeededSkipsIfATTFrameworkNotIncludedOnNewOS() { - if #available(iOS 14, macOS 11, tvOS 14, *) { + #if os(iOS) + if #available(iOS 14, *) { systemInfo.stubbedIsOperatingSystemAtLeastVersion = true MockAttributionTypeFactory.shouldReturnAdClientProxy = true MockAttributionTypeFactory.shouldReturnTrackingManagerProxy = false @@ -171,10 +175,12 @@ class AttributionFetcherTests: XCTestCase { expect(MockAdClientProxy.requestAttributionDetailsCallCount) == 0 expect(self.subscriberAttributesManager.invokedConvertAttributionDataAndSetCount) == 0 } + #endif } func testPostAppleSearchAdsAttributionIfNeededPostsIfATTFrameworkNotIncludedOnOldOS() { - if #available(iOS 14, macOS 11, tvOS 14, *) { + #if os(iOS) + if #available(iOS 14, *) { systemInfo.stubbedIsOperatingSystemAtLeastVersion = false MockAttributionTypeFactory.shouldReturnAdClientProxy = true MockAttributionTypeFactory.shouldReturnTrackingManagerProxy = false @@ -183,6 +189,7 @@ class AttributionFetcherTests: XCTestCase { expect(MockAdClientProxy.requestAttributionDetailsCallCount) == 1 } + #endif } func testPostAppleSearchAdsAttributionIfNeededSkipsIfIAdFrameworkNotIncluded() { @@ -195,8 +202,10 @@ class AttributionFetcherTests: XCTestCase { } func testPostAppleSearchAdsAttributionIfNeededPostsIfAuthorizedOnNewOS() { - if #available(iOS 14, macOS 11, tvOS 14, *) { + #if os(iOS) + if #available(iOS 14, *) { systemInfo.stubbedIsOperatingSystemAtLeastVersion = true + MockTrackingManagerProxy.mockAuthorizationStatus = .authorized MockAttributionTypeFactory.shouldReturnAdClientProxy = true MockAttributionTypeFactory.shouldReturnTrackingManagerProxy = true @@ -205,10 +214,12 @@ class AttributionFetcherTests: XCTestCase { expect(MockAdClientProxy.requestAttributionDetailsCallCount) == 1 } + #endif } func testPostAppleSearchAdsAttributionIfNeededPostsIfAuthorizedOnOldOS() { - if #available(iOS 14, macOS 11, tvOS 14, *) { + #if os(iOS) + if #available(iOS 14, *) { systemInfo.stubbedIsOperatingSystemAtLeastVersion = false MockTrackingManagerProxy.mockAuthorizationStatus = .authorized MockAttributionTypeFactory.shouldReturnAdClientProxy = true @@ -218,10 +229,12 @@ class AttributionFetcherTests: XCTestCase { expect(MockAdClientProxy.requestAttributionDetailsCallCount) == 1 } + #endif } func testPostAppleSearchAdsAttributionIfNeededPostsIfAuthNotDeterminedOnOldOS() { - if #available(iOS 14, macOS 11, tvOS 14, *) { + #if os(iOS) + if #available(iOS 14, *) { systemInfo.stubbedIsOperatingSystemAtLeastVersion = false MockTrackingManagerProxy.mockAuthorizationStatus = .notDetermined MockAttributionTypeFactory.shouldReturnAdClientProxy = true @@ -231,10 +244,12 @@ class AttributionFetcherTests: XCTestCase { expect(MockAdClientProxy.requestAttributionDetailsCallCount) == 1 } + #endif } func testPostAppleSearchAdsAttributionIfNeededSkipsIfAuthNotDeterminedOnNewOS() { - if #available(iOS 14, macOS 11, tvOS 14, *) { + #if os(iOS) + if #available(iOS 14, *) { systemInfo.stubbedIsOperatingSystemAtLeastVersion = true MockTrackingManagerProxy.mockAuthorizationStatus = .notDetermined @@ -245,11 +260,13 @@ class AttributionFetcherTests: XCTestCase { expect(MockAdClientProxy.requestAttributionDetailsCallCount) == 0 } + #endif } func testPostAppleSearchAdsAttributionIfNeededSkipsIfNotAuthorizedOnOldOS() { - if #available(iOS 14, macOS 11, tvOS 14, *) { + #if os(iOS) + if #available(iOS 14, *) { systemInfo.stubbedIsOperatingSystemAtLeastVersion = false MockTrackingManagerProxy.mockAuthorizationStatus = .denied MockAttributionTypeFactory.shouldReturnAdClientProxy = true @@ -259,10 +276,12 @@ class AttributionFetcherTests: XCTestCase { expect(MockAdClientProxy.requestAttributionDetailsCallCount) == 0 } + #endif } func testPostAppleSearchAdsAttributionIfNeededSkipsIfNotAuthorizedOnNewOS() { - if #available(iOS 14, macOS 11, tvOS 14, *) { + #if os(iOS) + if #available(iOS 14, *) { systemInfo.stubbedIsOperatingSystemAtLeastVersion = true MockTrackingManagerProxy.mockAuthorizationStatus = .denied MockAttributionTypeFactory.shouldReturnAdClientProxy = true @@ -272,10 +291,12 @@ class AttributionFetcherTests: XCTestCase { expect(MockAdClientProxy.requestAttributionDetailsCallCount) == 0 } + #endif } func testPostAppleSearchAdsAttributionIfNeededSkipsIfAlreadySent() { - if #available(iOS 14, macOS 11, tvOS 14, *) { + #if os(iOS) + if #available(iOS 14, *) { MockTrackingManagerProxy.mockAuthorizationStatus = .authorized MockAttributionTypeFactory.shouldReturnAdClientProxy = true MockAttributionTypeFactory.shouldReturnTrackingManagerProxy = true @@ -288,6 +309,7 @@ class AttributionFetcherTests: XCTestCase { expect(MockAdClientProxy.requestAttributionDetailsCallCount) == 1 } + #endif } } diff --git a/PurchasesTests/FoundationExtensions/NSError+RCExtensionsTests.swift b/PurchasesTests/FoundationExtensions/NSError+RCExtensionsTests.swift index 3e83cf6874..4c8fe46766 100644 --- a/PurchasesTests/FoundationExtensions/NSError+RCExtensionsTests.swift +++ b/PurchasesTests/FoundationExtensions/NSError+RCExtensionsTests.swift @@ -4,7 +4,6 @@ // import XCTest -import OHHTTPStubs import Nimble import Purchases diff --git a/PurchasesTests/Mocks/MockAttributionTypeFactory.swift b/PurchasesTests/Mocks/MockAttributionTypeFactory.swift index 29dff15af0..ea71e1dd21 100644 --- a/PurchasesTests/Mocks/MockAttributionTypeFactory.swift +++ b/PurchasesTests/Mocks/MockAttributionTypeFactory.swift @@ -11,7 +11,9 @@ // import Foundation -import AppTrackingTransparency +#if canImport(AppTrackingTransparency) + import AppTrackingTransparency +#endif @testable import PurchasesCoreSwift class MockAdClientProxy: AdClientProxy { @@ -35,11 +37,17 @@ class MockAdClientProxy: AdClientProxy { @available(iOS 14, macOS 11, tvOS 14, *) class MockTrackingManagerProxy: TrackingManagerProxy { - + + #if !os(watchOS) static var mockAuthorizationStatus: ATTrackingManager.AuthorizationStatus = .authorized + #endif override func trackingAuthorizationStatus() -> Int { + #if !os(watchOS) Int(Self.mockAuthorizationStatus.rawValue) + #else + -1 + #endif } } diff --git a/PurchasesTests/Mocks/MockProductDiscount.swift b/PurchasesTests/Mocks/MockProductDiscount.swift index 8b6a8bab75..9fe6725591 100644 --- a/PurchasesTests/Mocks/MockProductDiscount.swift +++ b/PurchasesTests/Mocks/MockProductDiscount.swift @@ -5,7 +5,7 @@ import StoreKit -@available(iOS 11.2, *) +@available(iOS 11.2, tvOS 11.2, macOS 10.13.2, *) class MockProductDiscount: SKProductDiscount { init(identifier: String? = "offerid", diff --git a/PurchasesTests/Mocks/MockSKDiscount.swift b/PurchasesTests/Mocks/MockSKDiscount.swift index bd34d0acba..55c7b63652 100644 --- a/PurchasesTests/Mocks/MockSKDiscount.swift +++ b/PurchasesTests/Mocks/MockSKDiscount.swift @@ -5,7 +5,7 @@ import Foundation -@available(iOS 11.2, *) +@available(iOS 11.2, tvOS 11.2, macOS 10.13.2, *) class MockDiscount: SKProductDiscount { var mockPaymentMode: SKProductDiscount.PaymentMode? override var paymentMode: SKProductDiscount.PaymentMode { @@ -22,11 +22,9 @@ class MockDiscount: SKProductDiscount { return mockIdentifier ?? "identifier" } - @available(iOS 11.2, *) lazy var mockSubscriptionPeriod: SKProductSubscriptionPeriod? = nil - @available(iOS 11.2, *) override var subscriptionPeriod: SKProductSubscriptionPeriod { return mockSubscriptionPeriod ?? SKProductSubscriptionPeriod(numberOfUnits: 1, unit:.month) } -} \ No newline at end of file +} diff --git a/PurchasesTests/Mocks/MockSKProduct.swift b/PurchasesTests/Mocks/MockSKProduct.swift index bd966b79b3..9203c22431 100644 --- a/PurchasesTests/Mocks/MockSKProduct.swift +++ b/PurchasesTests/Mocks/MockSKProduct.swift @@ -32,7 +32,7 @@ class MockSKProduct: SKProduct { return mockPrice ?? 2.99 as NSDecimalNumber } - @available(iOS 11.2, *) + @available(iOS 11.2, tvOS 11.2, macOS 10.13.2, *) override var introductoryPrice: SKProductDiscount? { if #available(iOS 12.2, *) { return mockDiscount ?? MockDiscount() @@ -41,18 +41,18 @@ class MockSKProduct: SKProduct { } } - @available(iOS 12.2, *) + @available(iOS 12.2, tvOS 11.2, macOS 10.13.2, *) lazy var mockDiscount: SKProductDiscount? = nil - @available(iOS 12.2, *) + @available(iOS 12.2, tvOS 11.2, macOS 10.13.2, *) override var discounts: [SKProductDiscount] { return (mockDiscount != nil) ? [mockDiscount!] : [] } - @available(iOS 11.2, *) + @available(iOS 11.2, tvOS 11.2, macOS 10.13.2, *) lazy var mockSubscriptionPeriod: SKProductSubscriptionPeriod? = nil - @available(iOS 11.2, *) + @available(iOS 11.2, tvOS 11.2, macOS 10.13.2, *) override var subscriptionPeriod: SKProductSubscriptionPeriod { return mockSubscriptionPeriod ?? SKProductSubscriptionPeriod(numberOfUnits: 1, unit:.month) } diff --git a/PurchasesTests/Networking/BackendTests.swift b/PurchasesTests/Networking/BackendTests.swift index 4c725a6f4a..6528801e16 100644 --- a/PurchasesTests/Networking/BackendTests.swift +++ b/PurchasesTests/Networking/BackendTests.swift @@ -8,7 +8,6 @@ import Foundation import XCTest -import OHHTTPStubs import Nimble import Purchases diff --git a/PurchasesTests/Networking/HTTPClientTests.swift b/PurchasesTests/Networking/HTTPClientTests.swift index 3a31609366..d59671eda1 100644 --- a/PurchasesTests/Networking/HTTPClientTests.swift +++ b/PurchasesTests/Networking/HTTPClientTests.swift @@ -6,6 +6,8 @@ // Copyright © 2019 RevenueCat. All rights reserved. // +#if !os(watchOS) + import XCTest import OHHTTPStubs import OHHTTPStubsSwift @@ -41,7 +43,7 @@ class HTTPClientTests: XCTestCase { guard let host = SystemInfo.serverHostURL.host else { fatalError() } stub(condition: isHost(host)) { _ in hostCorrect = true - return HTTPStubsResponse(data: Data.init(), statusCode:200, headers: nil) + return HTTPStubsResponse(data: Data.init(), statusCode: 200, headers: nil) } self.client.performPOSTRequest(serially: true, @@ -59,7 +61,7 @@ class HTTPClientTests: XCTestCase { stub(condition: hasHeaderNamed("test_header")) { _ in headerPresent = true - return HTTPStubsResponse(data: Data.init(), statusCode:200, headers: nil) + return HTTPStubsResponse(data: Data.init(), statusCode: 200, headers: nil) } self.client.performPOSTRequest(serially: true, @@ -77,7 +79,7 @@ class HTTPClientTests: XCTestCase { stub(condition: hasHeaderNamed("content-type", value: "application/json")) { request in headerPresent = true - return HTTPStubsResponse(data: Data.init(), statusCode:200, headers: nil) + return HTTPStubsResponse(data: Data.init(), statusCode: 200, headers: nil) } self.client.performPOSTRequest(serially: true, @@ -93,9 +95,9 @@ class HTTPClientTests: XCTestCase { let path = "/a_random_path" var headerPresent = false - stub(condition: hasHeaderNamed("X-Platform", value: "iOS")) { request in + stub(condition: hasHeaderNamed("X-Platform", value: SystemInfo.platformHeader)) { request in headerPresent = true - return HTTPStubsResponse(data: Data.init(), statusCode:200, headers: nil) + return HTTPStubsResponse(data: Data.init(), statusCode: 200, headers: nil) } self.client.performPOSTRequest(serially: true, @@ -113,7 +115,7 @@ class HTTPClientTests: XCTestCase { stub(condition: hasHeaderNamed("X-Version", value: Purchases.frameworkVersion())) { request in headerPresent = true - return HTTPStubsResponse(data: Data.init(), statusCode:200, headers: nil) + return HTTPStubsResponse(data: Data.init(), statusCode: 200, headers: nil) } self.client.performPOSTRequest(serially: true, @@ -131,7 +133,7 @@ class HTTPClientTests: XCTestCase { stub(condition: hasHeaderNamed("X-Platform-Version", value: ProcessInfo().operatingSystemVersionString)) { request in headerPresent = true - return HTTPStubsResponse(data: Data.init(), statusCode:200, headers: nil) + return HTTPStubsResponse(data: Data.init(), statusCode: 200, headers: nil) } self.client.performPOSTRequest(serially: true, @@ -149,7 +151,7 @@ class HTTPClientTests: XCTestCase { stub(condition: isPath("/v1" + path)) { _ in pathHit = true - return HTTPStubsResponse(data: Data.init(), statusCode:200, headers: nil) + return HTTPStubsResponse(data: Data.init(), statusCode: 200, headers: nil) } self.client.performPOSTRequest(serially: true, @@ -170,7 +172,7 @@ class HTTPClientTests: XCTestCase { stub(condition: hasBody(bodyData)) { _ in pathHit = true - return HTTPStubsResponse(data: Data.init(), statusCode:200, headers: nil) + return HTTPStubsResponse(data: Data.init(), statusCode: 200, headers: nil) } self.client.performPOSTRequest(serially: true, @@ -187,7 +189,7 @@ class HTTPClientTests: XCTestCase { var completionCalled = false stub(condition: isPath("/v1" + path)) { _ in - return HTTPStubsResponse(data: Data.init(), statusCode:200, headers: nil) + return HTTPStubsResponse(data: Data.init(), statusCode: 200, headers: nil) } self.client.performGETRequest(serially: true, @@ -205,7 +207,7 @@ class HTTPClientTests: XCTestCase { let error = NSError(domain: NSURLErrorDomain, code: NSURLErrorUnknown, userInfo: nil) stub(condition: isPath("/v1" + path)) { request in - let response = HTTPStubsResponse(data: Data.init(), statusCode:200, headers: nil) + let response = HTTPStubsResponse(data: Data.init(), statusCode: 200, headers: nil) response.error = error return response } @@ -300,7 +302,7 @@ class HTTPClientTests: XCTestCase { stub(condition: isPath("/v1" + path)) { request in let json = "{\"message\": \"something is great up in the cloud\"}" - return HTTPStubsResponse(data: json.data(using: String.Encoding.utf8)!, statusCode:200, headers: nil) + return HTTPStubsResponse(data: json.data(using: String.Encoding.utf8)!, statusCode: 200, headers: nil) } self.client.performGETRequest(serially: true, @@ -324,7 +326,7 @@ class HTTPClientTests: XCTestCase { stub(condition: hasHeaderNamed("X-Client-Version", value: version )) { request in headerPresent = true - return HTTPStubsResponse(data: Data.init(), statusCode:200, headers: nil) + return HTTPStubsResponse(data: Data.init(), statusCode: 200, headers: nil) } self.client.performPOSTRequest(serially: true, @@ -344,7 +346,7 @@ class HTTPClientTests: XCTestCase { stub(condition: hasHeaderNamed("X-Client-Build-Version", value: version )) { request in headerPresent = true - return HTTPStubsResponse(data: Data.init(), statusCode:200, headers: nil) + return HTTPStubsResponse(data: Data.init(), statusCode: 200, headers: nil) } self.client.performPOSTRequest(serially: true, @@ -356,15 +358,16 @@ class HTTPClientTests: XCTestCase { expect(headerPresent).toEventually(equal(true)) } + #if !os(macOS) func testAlwaysPassesAppleDeviceIdentifier() { let path = "/a_random_path" var headerPresent = false - let idfv = UIDevice.current.identifierForVendor!.uuidString + let idfv = SystemInfo.identifierForVendor! stub(condition: hasHeaderNamed("X-Apple-Device-Identifier", value: idfv )) { request in headerPresent = true - return HTTPStubsResponse(data: Data.init(), statusCode:200, headers: nil) + return HTTPStubsResponse(data: Data.init(), statusCode: 200, headers: nil) } self.client.performPOSTRequest(serially: true, @@ -375,6 +378,7 @@ class HTTPClientTests: XCTestCase { expect(headerPresent).toEventually(equal(true)) } + #endif func testDefaultsPlatformFlavorToNative() { let path = "/a_random_path" @@ -382,7 +386,7 @@ class HTTPClientTests: XCTestCase { stub(condition: hasHeaderNamed("X-Platform-Flavor", value: "native")) { request in headerPresent = true - return HTTPStubsResponse(data: Data.init(), statusCode:200, headers: nil) + return HTTPStubsResponse(data: Data.init(), statusCode: 200, headers: nil) } self.client.performPOSTRequest(serially: true, @@ -400,7 +404,7 @@ class HTTPClientTests: XCTestCase { stub(condition: hasHeaderNamed("X-Platform-Flavor", value: "react-native")) { request in headerPresent = true - return HTTPStubsResponse(data: Data.init(), statusCode:200, headers: nil) + return HTTPStubsResponse(data: Data.init(), statusCode: 200, headers: nil) } let systemInfo = try! SystemInfo(platformFlavor: "react-native", platformFlavorVersion: "3.2.1", @@ -421,7 +425,7 @@ class HTTPClientTests: XCTestCase { stub(condition: hasHeaderNamed("X-Platform-Flavor-Version", value: "1.2.3")) { request in headerPresent = true - return HTTPStubsResponse(data: Data.init(), statusCode:200, headers: nil) + return HTTPStubsResponse(data: Data.init(), statusCode: 200, headers: nil) } let systemInfo = try! SystemInfo(platformFlavor: "react-native", platformFlavorVersion: "1.2.3", @@ -443,7 +447,7 @@ class HTTPClientTests: XCTestCase { stub(condition: hasHeaderNamed("X-Observer-Mode-Enabled", value: "false")) { request in headerPresent = true - return HTTPStubsResponse(data: Data.init(), statusCode:200, headers: nil) + return HTTPStubsResponse(data: Data.init(), statusCode: 200, headers: nil) } let systemInfo = try! SystemInfo(platformFlavor: nil, platformFlavorVersion: nil, finishTransactions: true) let client = HTTPClient(systemInfo: systemInfo, eTagManager: eTagManager, operationDispatcher: operationDispatcher) @@ -462,7 +466,7 @@ class HTTPClientTests: XCTestCase { stub(condition: hasHeaderNamed("X-Observer-Mode-Enabled", value: "true")) { request in headerPresent = true - return HTTPStubsResponse(data: Data.init(), statusCode:200, headers: nil) + return HTTPStubsResponse(data: Data.init(), statusCode: 200, headers: nil) } let systemInfo = try! SystemInfo(platformFlavor: nil, platformFlavorVersion: nil, finishTransactions: false) let client = HTTPClient(systemInfo: systemInfo, eTagManager: eTagManager, operationDispatcher: operationDispatcher) @@ -487,7 +491,7 @@ class HTTPClientTests: XCTestCase { expect(requestNumber) == completionCallCount let json = "{\"message\": \"something is great up in the cloud\"}" - return HTTPStubsResponse(data: json.data(using: String.Encoding.utf8)!, statusCode:200, headers: nil) + return HTTPStubsResponse(data: json.data(using: String.Encoding.utf8)!, statusCode: 200, headers: nil) .responseTime(0.003) } @@ -519,7 +523,7 @@ class HTTPClientTests: XCTestCase { } let json = "{\"message\": \"something is great up in the cloud\"}" - return HTTPStubsResponse(data: json.data(using: String.Encoding.utf8)!, statusCode:200, headers: nil) + return HTTPStubsResponse(data: json.data(using: String.Encoding.utf8)!, statusCode: 200, headers: nil) .responseTime(0.1) } @@ -556,7 +560,7 @@ class HTTPClientTests: XCTestCase { } let json = "{\"message\": \"something is great up in the cloud\"}" - return HTTPStubsResponse(data: json.data(using: String.Encoding.utf8)!, statusCode:200, headers: nil) + return HTTPStubsResponse(data: json.data(using: String.Encoding.utf8)!, statusCode: 200, headers: nil) .responseTime(0.1) } @@ -593,7 +597,7 @@ class HTTPClientTests: XCTestCase { } let json = "{\"message\": \"something is great up in the cloud\"}" - return HTTPStubsResponse(data: json.data(using: String.Encoding.utf8)!, statusCode:200, headers: nil) + return HTTPStubsResponse(data: json.data(using: String.Encoding.utf8)!, statusCode: 200, headers: nil) .responseTime(0.1) } @@ -630,7 +634,7 @@ class HTTPClientTests: XCTestCase { } let json = "{\"message\": \"something is great up in the cloud\"}" - return HTTPStubsResponse(data: json.data(using: String.Encoding.utf8)!, statusCode:200, headers: nil) + return HTTPStubsResponse(data: json.data(using: String.Encoding.utf8)!, statusCode: 200, headers: nil) .responseTime(0.1) } @@ -691,7 +695,7 @@ class HTTPClientTests: XCTestCase { stub(condition: isPath("/v1" + path)) { request in httpCallMade = true - return HTTPStubsResponse(data: Data(), statusCode:200, headers: nil) + return HTTPStubsResponse(data: Data(), statusCode: 200, headers: nil) } self.client.performPOSTRequest(serially: true, @@ -715,7 +719,7 @@ class HTTPClientTests: XCTestCase { self.eTagManager.shouldReturnResultFromBackend = true } firstTimeCalled = true - return HTTPStubsResponse(data: Data.init(), statusCode:200, headers: nil) + return HTTPStubsResponse(data: Data.init(), statusCode: 200, headers: nil) } self.eTagManager.shouldReturnResultFromBackend = false @@ -730,3 +734,4 @@ class HTTPClientTests: XCTestCase { } } +#endif diff --git a/PurchasesTests/Purchasing/PurchasesTests.swift b/PurchasesTests/Purchasing/PurchasesTests.swift index 9bca35f5a5..7d44739db4 100644 --- a/PurchasesTests/Purchasing/PurchasesTests.swift +++ b/PurchasesTests/Purchasing/PurchasesTests.swift @@ -744,7 +744,7 @@ class PurchasesTests: XCTestCase { expect(self.backend.postedProductID).to(equal(product.productIdentifier)) expect(self.backend.postedPrice).to(equal(product.price)) - if #available(iOS 11.2, *) { + if #available(iOS 11.2, tvOS 11.2, macOS 10.13.2, *) { expect(self.backend.postedPaymentMode).to(equal(ProductInfo.PaymentMode.payAsYouGo)) expect(self.backend.postedIntroPrice).to(equal(product.introductoryPrice?.price)) } else { @@ -752,7 +752,7 @@ class PurchasesTests: XCTestCase { expect(self.backend.postedIntroPrice).to(beNil()) } - if #available(iOS 12.0, *) { + if #available(iOS 12.0, tvOS 12.0, macOS 10.14, *) { expect(self.backend.postedSubscriptionGroup).to(equal(product.subscriptionGroupIdentifier)) } @@ -1030,7 +1030,7 @@ class PurchasesTests: XCTestCase { expect(self.notificationCenter.observers.count).to(equal(2)); if self.notificationCenter.observers.count > 0 { let (_, _, name, _) = self.notificationCenter.observers[0]; - expect(name).to(equal(UIApplication.didBecomeActiveNotification)) + expect(name).to(equal(SystemInfo.applicationDidBecomeActiveNotification)) } } @@ -2171,7 +2171,7 @@ class PurchasesTests: XCTestCase { } func testAddsDiscountToWrapper() { - if #available(iOS 12.2, *) { + if #available(iOS 12.2, tvOS 12.2, macOS 10.14.4, *) { setupPurchases() let product = MockSKProduct(mockProductIdentifier: "com.product.id1") let discount = SKPaymentDiscount.init(identifier: "discount", keyIdentifier: "TIKAMASALA1", nonce: UUID(), signature: "Base64 encoded signature", timestamp: NSNumber(value: Int64(123413232131))) @@ -2187,7 +2187,7 @@ class PurchasesTests: XCTestCase { } func testPaymentDiscountForProductDiscountCreatesDiscount() { - if #available(iOS 12.2, *) { + if #available(iOS 12.2, tvOS 12.2, macOS 10.14.4, *) { setupPurchases() let product = MockSKProduct(mockProductIdentifier: "com.product.id1") @@ -2222,7 +2222,7 @@ class PurchasesTests: XCTestCase { } func testPaymentDiscountForProductDiscountCallsCompletionWithErrorIfReceiptNil() { - if #available(iOS 12.2, *) { + if #available(iOS 12.2, tvOS 12.2, macOS 10.14.4, *) { setupPurchases() let product = MockSKProduct(mockProductIdentifier: "com.product.id1") @@ -2248,7 +2248,7 @@ class PurchasesTests: XCTestCase { } func testPaymentDiscountForProductDiscountCallsCompletionWithErrorIfReceiptEmpty() { - if #available(iOS 12.2, *) { + if #available(iOS 12.2, tvOS 12.2, macOS 10.14.4, *) { setupPurchases() let product = MockSKProduct(mockProductIdentifier: "com.product.id1") diff --git a/PurchasesTests/Purchasing/StoreKitRequestFetcherTests.swift b/PurchasesTests/Purchasing/StoreKitRequestFetcherTests.swift index 07073c424b..41816397f6 100644 --- a/PurchasesTests/Purchasing/StoreKitRequestFetcherTests.swift +++ b/PurchasesTests/Purchasing/StoreKitRequestFetcherTests.swift @@ -7,7 +7,6 @@ // import XCTest -import OHHTTPStubs import Nimble import StoreKit diff --git a/PurchasesTests/SubscriberAttributes/BackendSubscriberAttributesTests.swift b/PurchasesTests/SubscriberAttributes/BackendSubscriberAttributesTests.swift index 21f5564fb6..e61ce91eed 100644 --- a/PurchasesTests/SubscriberAttributes/BackendSubscriberAttributesTests.swift +++ b/PurchasesTests/SubscriberAttributes/BackendSubscriberAttributesTests.swift @@ -4,7 +4,6 @@ // import XCTest -import OHHTTPStubs import Nimble import Purchases diff --git a/PurchasesTests/SubscriberAttributes/PurchasesSubscriberAttributesTests.swift b/PurchasesTests/SubscriberAttributes/PurchasesSubscriberAttributesTests.swift index 69c15e5663..0c41d5f6e5 100644 --- a/PurchasesTests/SubscriberAttributes/PurchasesSubscriberAttributesTests.swift +++ b/PurchasesTests/SubscriberAttributes/PurchasesSubscriberAttributesTests.swift @@ -139,7 +139,7 @@ class PurchasesSubscriberAttributesTests: XCTestCase { var isObservingDidBecomeActive = false for (_, _, name, _) in self.mockNotificationCenter.observers { - if name == UIApplication.didBecomeActiveNotification { + if name == SystemInfo.applicationDidBecomeActiveNotification { isObservingDidBecomeActive = true break } @@ -158,7 +158,7 @@ class PurchasesSubscriberAttributesTests: XCTestCase { var isObservingDidBecomeActive = false for (_, _, name, _) in self.mockNotificationCenter.observers { - if name == UIApplication.willResignActiveNotification { + if name == SystemInfo.applicationWillResignActiveNotification { isObservingDidBecomeActive = true break } diff --git a/PurchasesTests/SubscriberAttributes/SubscriberAttributesManagerTests.swift b/PurchasesTests/SubscriberAttributes/SubscriberAttributesManagerTests.swift index e1f9d0d559..b9e96b055d 100644 --- a/PurchasesTests/SubscriberAttributes/SubscriberAttributesManagerTests.swift +++ b/PurchasesTests/SubscriberAttributes/SubscriberAttributesManagerTests.swift @@ -11,7 +11,6 @@ // import XCTest -import OHHTTPStubs import Nimble import Purchases diff --git a/fastlane/Scanfile b/fastlane/Scanfile index ccbecd1317..2b0fc06189 100644 --- a/fastlane/Scanfile +++ b/fastlane/Scanfile @@ -5,5 +5,5 @@ # fastlane scan --help scheme("Unit Tests") -devices(["iPhone 6", "iPhone 12"]) +devices(["iPhone 6", "iPhone 12", "Apple TV", "Apple Watch Series 6 - 44mm"]) From 9830d77c9932f9f6d1910410b9826b291104f95e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanpe=20Catala=CC=81n?= Date: Sat, 7 Aug 2021 00:16:32 +0200 Subject: [PATCH 2/3] update after comments --- .../Mocks/MockProductsManager.swift | 2 +- PurchasesCoreSwiftTests/Mocks/MockSKProduct.swift | 10 +++------- .../Purchasing/ProductInfoExtractorTests.swift | 13 ++++++------- .../Purchasing/ProductInfoTests.swift | 2 +- PurchasesTests/Mocks/MockSKProduct.swift | 10 +++------- PurchasesTests/Purchasing/PurchasesTests.swift | 4 ++-- 6 files changed, 16 insertions(+), 25 deletions(-) diff --git a/PurchasesCoreSwiftTests/Mocks/MockProductsManager.swift b/PurchasesCoreSwiftTests/Mocks/MockProductsManager.swift index 8bc3a8a215..404d5398b4 100644 --- a/PurchasesCoreSwiftTests/Mocks/MockProductsManager.swift +++ b/PurchasesCoreSwiftTests/Mocks/MockProductsManager.swift @@ -26,7 +26,7 @@ class MockProductsManager: ProductsManager { let products: [SKProduct] = identifiers.map { (identifier) -> MockSKProduct in let p = MockSKProduct(mockProductIdentifier: identifier) p.mockSubscriptionGroupIdentifier = "1234567" - if #available(iOS 12.2, tvOS 11.2, macOS 10.13.2, *) { + if #available(iOS 11.2, tvOS 11.2, macOS 10.13.2, *) { let mockDiscount = MockDiscount() mockDiscount.mockIdentifier = "discount_id" p.mockDiscount = mockDiscount diff --git a/PurchasesCoreSwiftTests/Mocks/MockSKProduct.swift b/PurchasesCoreSwiftTests/Mocks/MockSKProduct.swift index 9203c22431..00c9a0819f 100644 --- a/PurchasesCoreSwiftTests/Mocks/MockSKProduct.swift +++ b/PurchasesCoreSwiftTests/Mocks/MockSKProduct.swift @@ -34,17 +34,13 @@ class MockSKProduct: SKProduct { @available(iOS 11.2, tvOS 11.2, macOS 10.13.2, *) override var introductoryPrice: SKProductDiscount? { - if #available(iOS 12.2, *) { - return mockDiscount ?? MockDiscount() - } else { - return MockDiscount() - } + mockDiscount ?? MockDiscount() } - @available(iOS 12.2, tvOS 11.2, macOS 10.13.2, *) + @available(iOS 11.2, tvOS 11.2, macOS 10.13.2, *) lazy var mockDiscount: SKProductDiscount? = nil - @available(iOS 12.2, tvOS 11.2, macOS 10.13.2, *) + @available(iOS 11.2, tvOS 11.2, macOS 10.13.2, *) override var discounts: [SKProductDiscount] { return (mockDiscount != nil) ? [mockDiscount!] : [] } diff --git a/PurchasesCoreSwiftTests/Purchasing/ProductInfoExtractorTests.swift b/PurchasesCoreSwiftTests/Purchasing/ProductInfoExtractorTests.swift index fb33bed68c..700ff86a3d 100644 --- a/PurchasesCoreSwiftTests/Purchasing/ProductInfoExtractorTests.swift +++ b/PurchasesCoreSwiftTests/Purchasing/ProductInfoExtractorTests.swift @@ -43,7 +43,7 @@ class ProductInfoExtractorTests: XCTestCase { func testExtractInfoFromProductExtractsPaymentMode() { let product = MockSKProduct(mockProductIdentifier: "cool_product") - if #available(iOS 12.2, tvOS 11.2, macOS 10.13.2, *) { + if #available(iOS 11.2, tvOS 11.2, macOS 10.13.2, *) { let mockDiscount = MockDiscount() mockDiscount.mockPaymentMode = .freeTrial @@ -65,7 +65,7 @@ class ProductInfoExtractorTests: XCTestCase { func testExtractInfoFromProductExtractsIntroPrice() { let product = MockSKProduct(mockProductIdentifier: "cool_product") - if #available(iOS 12.2, tvOS 11.2, macOS 10.13.2, *) { + if #available(iOS 11.2, tvOS 11.2, macOS 10.13.2, *) { let mockDiscount = MockDiscount() mockDiscount.mockPrice = 10.99 @@ -125,7 +125,7 @@ class ProductInfoExtractorTests: XCTestCase { func testExtractInfoFromProductExtractsIntroDuration() { let product = MockSKProduct(mockProductIdentifier: "cool_product") - if #available(iOS 12.2, tvOS 11.2, macOS 10.13.2, *) { + if #available(iOS 11.2, tvOS 11.2, macOS 10.13.2, *) { let mockDiscount = MockDiscount() mockDiscount.mockSubscriptionPeriod = SKProductSubscriptionPeriod(numberOfUnits: 3, unit: .year) @@ -147,7 +147,7 @@ class ProductInfoExtractorTests: XCTestCase { func testExtractInfoFromProductExtractsIntroDurationType() { let product = MockSKProduct(mockProductIdentifier: "cool_product") - if #available(iOS 12.2, macOS 10.14.4, tvOS 11.2, *) { + if #available(iOS 11.2, macOS 10.14.4, tvOS 11.2, *) { let mockDiscount = MockDiscount() mockDiscount.mockPaymentMode = .freeTrial @@ -168,8 +168,7 @@ class ProductInfoExtractorTests: XCTestCase { func testExtractInfoFromProductExtractsSubscriptionGroup() { let product = MockSKProduct(mockProductIdentifier: "cool_product") - - if #available(iOS 12.0, *) { + if #available(iOS 11.2, *) { let group = "mock_group" product.mockSubscriptionGroupIdentifier = group let productInfoExtractor = ProductInfoExtractor() @@ -189,7 +188,7 @@ class ProductInfoExtractorTests: XCTestCase { func testExtractInfoFromProductExtractsDiscounts() { let product = MockSKProduct(mockProductIdentifier: "cool_product") - if #available(iOS 12.2, tvOS 11.2, macOS 10.13.2, *) { + if #available(iOS 11.2, tvOS 11.2, macOS 10.13.2, *) { let mockDiscount = MockDiscount() let paymentMode: SKProductDiscount.PaymentMode = .freeTrial mockDiscount.mockPaymentMode = paymentMode diff --git a/PurchasesCoreSwiftTests/Purchasing/ProductInfoTests.swift b/PurchasesCoreSwiftTests/Purchasing/ProductInfoTests.swift index 2141c10730..25ee3272dc 100644 --- a/PurchasesCoreSwiftTests/Purchasing/ProductInfoTests.swift +++ b/PurchasesCoreSwiftTests/Purchasing/ProductInfoTests.swift @@ -3,7 +3,7 @@ import Nimble import PurchasesCoreSwift -@available(iOS 12.2, *) +@available(iOS 11.2, *) class ProductInfoTests: XCTestCase { func testAsDictionaryConvertsProductIdentifierCorrectly() { let productIdentifier = "cool_product" diff --git a/PurchasesTests/Mocks/MockSKProduct.swift b/PurchasesTests/Mocks/MockSKProduct.swift index 9203c22431..00c9a0819f 100644 --- a/PurchasesTests/Mocks/MockSKProduct.swift +++ b/PurchasesTests/Mocks/MockSKProduct.swift @@ -34,17 +34,13 @@ class MockSKProduct: SKProduct { @available(iOS 11.2, tvOS 11.2, macOS 10.13.2, *) override var introductoryPrice: SKProductDiscount? { - if #available(iOS 12.2, *) { - return mockDiscount ?? MockDiscount() - } else { - return MockDiscount() - } + mockDiscount ?? MockDiscount() } - @available(iOS 12.2, tvOS 11.2, macOS 10.13.2, *) + @available(iOS 11.2, tvOS 11.2, macOS 10.13.2, *) lazy var mockDiscount: SKProductDiscount? = nil - @available(iOS 12.2, tvOS 11.2, macOS 10.13.2, *) + @available(iOS 11.2, tvOS 11.2, macOS 10.13.2, *) override var discounts: [SKProductDiscount] { return (mockDiscount != nil) ? [mockDiscount!] : [] } diff --git a/PurchasesTests/Purchasing/PurchasesTests.swift b/PurchasesTests/Purchasing/PurchasesTests.swift index 1db3c42ae2..142a56c187 100644 --- a/PurchasesTests/Purchasing/PurchasesTests.swift +++ b/PurchasesTests/Purchasing/PurchasesTests.swift @@ -753,7 +753,7 @@ class PurchasesTests: XCTestCase { expect(self.backend.postedSubscriptionGroup).to(equal(product.subscriptionGroupIdentifier)) } - if #available(iOS 12.2, *) { + if #available(iOS 11.2, *) { expect(self.backend.postedDiscounts?.count).to(equal(1)) let postedDiscount: PromotionalOffer = self.backend.postedDiscounts![0] expect(postedDiscount.offerIdentifier).to(equal("discount_id")) @@ -789,7 +789,7 @@ class PurchasesTests: XCTestCase { expect(self.backend.postedProductID).toNot(beNil()) expect(self.backend.postedPrice).toNot(beNil()) expect(self.backend.postedCurrencyCode).toNot(beNil()) - if #available(iOS 12.2, macOS 10.14.4, *) { + if #available(iOS 11.2, macOS 10.14.4, *) { expect(self.backend.postedIntroPrice).toNot(beNil()) } } From 6b48e14733c0f14bcae4530338a43875ac02b656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juanpe=20Catala=CC=81n?= Date: Tue, 10 Aug 2021 08:14:32 +0200 Subject: [PATCH 3/3] revert support watchOS in test targets --- Purchases.xcodeproj/project.pbxproj | 16 ++++++++-------- .../Purchasing/StoreKitWrapperTests.swift | 4 ---- .../Attribution/AttributionPosterTests.swift | 2 -- .../Mocks/MockAttributionTypeFactory.swift | 6 ------ PurchasesTests/Networking/HTTPClientTests.swift | 4 ---- fastlane/Scanfile | 2 +- 6 files changed, 9 insertions(+), 25 deletions(-) diff --git a/Purchases.xcodeproj/project.pbxproj b/Purchases.xcodeproj/project.pbxproj index 6159ad16e7..3ae608060a 100644 --- a/Purchases.xcodeproj/project.pbxproj +++ b/Purchases.xcodeproj/project.pbxproj @@ -2084,11 +2084,11 @@ PRODUCT_BUNDLE_IDENTIFIER = com.revenuecat.PurchasesCoreSwiftTests; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; - SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx watchsimulator watchos appletvsimulator appletvos"; + SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx appletvsimulator appletvos"; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2,3,4,6"; + TARGETED_DEVICE_FAMILY = "1,2,3,6"; TVOS_DEPLOYMENT_TARGET = 9.0; WATCHOS_DEPLOYMENT_TARGET = 6.2; }; @@ -2114,9 +2114,9 @@ PRODUCT_BUNDLE_IDENTIFIER = com.revenuecat.PurchasesCoreSwiftTests; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; - SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx watchsimulator watchos appletvsimulator appletvos"; + SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx appletvsimulator appletvos"; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2,3,4,6"; + TARGETED_DEVICE_FAMILY = "1,2,3,6"; TVOS_DEPLOYMENT_TARGET = 9.0; WATCHOS_DEPLOYMENT_TARGET = 6.2; }; @@ -2428,13 +2428,13 @@ PRODUCT_BUNDLE_IDENTIFIER = com.purchases.PurchasesTests; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; - SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx watchsimulator watchos appletvsimulator appletvos"; + SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx appletvsimulator appletvos"; SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_OBJC_BRIDGING_HEADER = "PurchasesTests/PurchasesTests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; SWIFT_PRECOMPILE_BRIDGING_HEADER = YES; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2,3,4,6"; + TARGETED_DEVICE_FAMILY = "1,2,3,6"; TVOS_DEPLOYMENT_TARGET = 9.0; WATCHOS_DEPLOYMENT_TARGET = 6.2; }; @@ -2458,13 +2458,13 @@ PRODUCT_BUNDLE_IDENTIFIER = com.purchases.PurchasesTests; PRODUCT_NAME = "$(TARGET_NAME)"; SDKROOT = iphoneos; - SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx watchsimulator watchos appletvsimulator appletvos"; + SUPPORTED_PLATFORMS = "iphonesimulator iphoneos macosx appletvsimulator appletvos"; SWIFT_COMPILATION_MODE = wholemodule; SWIFT_OBJC_BRIDGING_HEADER = "PurchasesTests/PurchasesTests-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-O"; SWIFT_PRECOMPILE_BRIDGING_HEADER = YES; SWIFT_VERSION = 5.0; - TARGETED_DEVICE_FAMILY = "1,2,3,4,6"; + TARGETED_DEVICE_FAMILY = "1,2,3,6"; TVOS_DEPLOYMENT_TARGET = 9.0; WATCHOS_DEPLOYMENT_TARGET = 6.2; }; diff --git a/PurchasesCoreSwiftTests/Purchasing/StoreKitWrapperTests.swift b/PurchasesCoreSwiftTests/Purchasing/StoreKitWrapperTests.swift index 4312650156..b839de9059 100644 --- a/PurchasesCoreSwiftTests/Purchasing/StoreKitWrapperTests.swift +++ b/PurchasesCoreSwiftTests/Purchasing/StoreKitWrapperTests.swift @@ -98,7 +98,6 @@ class StoreKitWrapperTests: XCTestCase, StoreKitWrapperDelegate { expect(self.updatedTransactions).to(contain(transaction)) } - #if !os(watchOS) @available(iOS 11.0, tvOS 11.0, macOS 11.0, macCatalyst 14.0, *) func testCallsDelegateWhenPromoPurchaseIsAvailable() { let product = SKProduct.init(); @@ -108,9 +107,7 @@ class StoreKitWrapperTests: XCTestCase, StoreKitWrapperDelegate { expect(self.promoPayment).to(be(payment)); expect(self.promoProduct).to(be(product)) } - #endif - #if !os(watchOS) @available(iOS 11.0, tvOS 11.0, macOS 11.0, macCatalyst 14.0, *) func testPromoDelegateMethodPassesBackReturnValueFromOwnDelegate() { let product = SKProduct.init(); @@ -122,7 +119,6 @@ class StoreKitWrapperTests: XCTestCase, StoreKitWrapperDelegate { expect(result).to(equal(self.shouldAddPromo)) } - #endif func testCallsDelegateOncePerTransaction() { let payment1 = SKPayment.init(product: SKProduct.init()) diff --git a/PurchasesTests/Attribution/AttributionPosterTests.swift b/PurchasesTests/Attribution/AttributionPosterTests.swift index be3f54b999..f9864065f1 100644 --- a/PurchasesTests/Attribution/AttributionPosterTests.swift +++ b/PurchasesTests/Attribution/AttributionPosterTests.swift @@ -53,11 +53,9 @@ class AttributionPosterTests: XCTestCase { } private func resetAttributionStaticProperties() { - #if !os(watchOS) if #available(iOS 14, macOS 11, tvOS 14, *) { MockTrackingManagerProxy.mockAuthorizationStatus = .authorized } - #endif MockAttributionTypeFactory.shouldReturnAdClientProxy = true MockAttributionTypeFactory.shouldReturnTrackingManagerProxy = true diff --git a/PurchasesTests/Mocks/MockAttributionTypeFactory.swift b/PurchasesTests/Mocks/MockAttributionTypeFactory.swift index ea71e1dd21..1fa4208cb9 100644 --- a/PurchasesTests/Mocks/MockAttributionTypeFactory.swift +++ b/PurchasesTests/Mocks/MockAttributionTypeFactory.swift @@ -38,16 +38,10 @@ class MockAdClientProxy: AdClientProxy { @available(iOS 14, macOS 11, tvOS 14, *) class MockTrackingManagerProxy: TrackingManagerProxy { - #if !os(watchOS) static var mockAuthorizationStatus: ATTrackingManager.AuthorizationStatus = .authorized - #endif override func trackingAuthorizationStatus() -> Int { - #if !os(watchOS) Int(Self.mockAuthorizationStatus.rawValue) - #else - -1 - #endif } } diff --git a/PurchasesTests/Networking/HTTPClientTests.swift b/PurchasesTests/Networking/HTTPClientTests.swift index 0f6fb35c1d..5ae5a300ec 100644 --- a/PurchasesTests/Networking/HTTPClientTests.swift +++ b/PurchasesTests/Networking/HTTPClientTests.swift @@ -6,8 +6,6 @@ // Copyright © 2019 RevenueCat. All rights reserved. // -#if !os(watchOS) - import XCTest import OHHTTPStubs import OHHTTPStubsSwift @@ -733,5 +731,3 @@ class HTTPClientTests: XCTestCase { expect(completionCalled).toEventually(equal(true), timeout: .seconds(1)) } } - -#endif diff --git a/fastlane/Scanfile b/fastlane/Scanfile index 2b0fc06189..85e70de898 100644 --- a/fastlane/Scanfile +++ b/fastlane/Scanfile @@ -5,5 +5,5 @@ # fastlane scan --help scheme("Unit Tests") -devices(["iPhone 6", "iPhone 12", "Apple TV", "Apple Watch Series 6 - 44mm"]) +devices(["iPhone 6", "iPhone 12", "Apple TV"])