-
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 all commits
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 |
|---|---|---|
|
|
@@ -4,7 +4,6 @@ | |
| // | ||
|
|
||
| import XCTest | ||
| import OHHTTPStubs | ||
| import Nimble | ||
|
|
||
| import Purchases | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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" | ||
|
|
@@ -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,7 @@ class StoreKitWrapperTests: XCTestCase, StoreKitWrapperDelegate { | |
| expect(self.updatedTransactions).to(contain(transaction)) | ||
| } | ||
|
|
||
| @available(iOS 11.0, *) | ||
| @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) | ||
|
|
@@ -109,7 +108,7 @@ class StoreKitWrapperTests: XCTestCase, StoreKitWrapperDelegate { | |
| expect(self.promoProduct).to(be(product)) | ||
| } | ||
|
|
||
| @available(iOS 11.0, *) | ||
| @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) | ||
|
|
@@ -199,6 +198,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.
redundant availability information