-
Notifications
You must be signed in to change notification settings - Fork 417
Support all platforms in the test targets #717
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
3252a91
203666e
9830d77
35f1534
0ea634f
6b48e14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,14 +70,16 @@ - (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:@"%@", | ||
| RCStrings.attribution.search_ads_attribution_cancelled_missing_iad_framework]]; | ||
| return; | ||
| } | ||
| [adClientProxy requestAttributionDetailsWithBlock:completionHandler]; | ||
| #else | ||
| completionHandler([NSDictionary new], nil); | ||
| #endif | ||
|
||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, *) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. redundant availability information |
||
| lazy var mockSubscriptionPeriod: SKProductSubscriptionPeriod? = nil | ||
|
|
||
| @available(iOS 11.2, *) | ||
| override var subscriptionPeriod: SKProductSubscriptionPeriod { | ||
| return mockSubscriptionPeriod ?? SKProductSubscriptionPeriod(numberOfUnits: 1, unit:.month) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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", | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the test is the same, I've only changed how the discounts are initialized. The constructor with a product discount as param is not available for all OS versions, but there is another compatible one. Since the objective of this test case is not to test if the constructor works fine, I think we can use the most compatible constructor. WDYT?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed, I think this was probably an oversight. |
||
| 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, *) { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here. ⬆️ |
||
| 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" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,7 +8,6 @@ | |
|
|
||
| import Foundation | ||
| import XCTest | ||
| import OHHTTPStubs | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. useless 🗑️ |
||
| 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!") } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,7 +4,6 @@ | |
| // | ||
|
|
||
| import XCTest | ||
| import OHHTTPStubs | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. useless 🗑️ |
||
| import Nimble | ||
|
|
||
| @testable import PurchasesCoreSwift | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added Mac Catalyst, but I didn't remove the comment. I think is useful until this class will be migrated to Swift in order to check again the available platforms.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I saw this after the class had already been merged in #711 😬
I think we had it like this originally because if
TARGET_OS_MACCATALYST, thenTARGET_OS_IOSalso evaluates to true? I'd have to double check.I think being explicit is probably a good idea in any case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hehe, no problem, I'll update my branch 👍🏼 Swift code is always welcome 🙂
Well, you're right, it's a double check. IMO, since Mac Catalyst is not so popular it wouldn't make sense to be explicit. So, it's ok for me to use only
iOS