|
@@ -26,6 +26,7 @@
|
|
import XCTest
|
|
import XCTest
|
|
import SwiftyStoreKit
|
|
import SwiftyStoreKit
|
|
|
|
|
|
|
|
+// swiftlint:disable file_length
|
|
private extension TimeInterval {
|
|
private extension TimeInterval {
|
|
var millisecondsNSString: NSString {
|
|
var millisecondsNSString: NSString {
|
|
return String(format: "%.0f", self * 1000) as NSString
|
|
return String(format: "%.0f", self * 1000) as NSString
|
|
@@ -277,7 +278,7 @@ class InAppReceiptTests: XCTestCase {
|
|
}
|
|
}
|
|
|
|
|
|
// MARK: Verify Subscription, multiple receipt item tests
|
|
// MARK: Verify Subscription, multiple receipt item tests
|
|
- func verifyAutoRenewableSubscription_when_twoSubscriptions_sameProductId_mostRecentNonExpired_then_resultIsPurchased_itemsSorted() {
|
|
|
|
|
|
+ func testVerifyAutoRenewableSubscription_when_twoSubscriptions_sameProductId_mostRecentNonExpired_then_resultIsPurchased_itemsSorted() {
|
|
|
|
|
|
let receiptRequestDate = makeDateAtMidnight(year: 2017, month: 5, day: 14)
|
|
let receiptRequestDate = makeDateAtMidnight(year: 2017, month: 5, day: 14)
|
|
|
|
|
|
@@ -293,7 +294,7 @@ class InAppReceiptTests: XCTestCase {
|
|
isTrialPeriod: isTrialPeriod)
|
|
isTrialPeriod: isTrialPeriod)
|
|
|
|
|
|
let newerPurchaseDate = makeDateAtMidnight(year: 2017, month: 5, day: 14)
|
|
let newerPurchaseDate = makeDateAtMidnight(year: 2017, month: 5, day: 14)
|
|
- let newerExpirationDate = olderPurchaseDate.addingTimeInterval(60 * 60)
|
|
|
|
|
|
+ let newerExpirationDate = newerPurchaseDate.addingTimeInterval(60 * 60)
|
|
let newerItem = ReceiptItem(productId: productId,
|
|
let newerItem = ReceiptItem(productId: productId,
|
|
purchaseDate: newerPurchaseDate,
|
|
purchaseDate: newerPurchaseDate,
|
|
subscriptionExpirationDate: newerExpirationDate,
|
|
subscriptionExpirationDate: newerExpirationDate,
|
|
@@ -308,7 +309,7 @@ class InAppReceiptTests: XCTestCase {
|
|
XCTAssertEqual(verifySubscriptionResult, expectedSubscriptionResult)
|
|
XCTAssertEqual(verifySubscriptionResult, expectedSubscriptionResult)
|
|
}
|
|
}
|
|
|
|
|
|
- func verifyAutoRenewableSubscription_when_twoSubscriptions_sameProductId_bothExpired_then_resultIsExpired_itemsSorted() {
|
|
|
|
|
|
+ func testVerifyAutoRenewableSubscription_when_twoSubscriptions_sameProductId_bothExpired_then_resultIsExpired_itemsSorted() {
|
|
|
|
|
|
let receiptRequestDate = makeDateAtMidnight(year: 2017, month: 5, day: 14)
|
|
let receiptRequestDate = makeDateAtMidnight(year: 2017, month: 5, day: 14)
|
|
|
|
|
|
@@ -324,7 +325,7 @@ class InAppReceiptTests: XCTestCase {
|
|
isTrialPeriod: isTrialPeriod)
|
|
isTrialPeriod: isTrialPeriod)
|
|
|
|
|
|
let newerPurchaseDate = makeDateAtMidnight(year: 2017, month: 5, day: 13)
|
|
let newerPurchaseDate = makeDateAtMidnight(year: 2017, month: 5, day: 13)
|
|
- let newerExpirationDate = olderPurchaseDate.addingTimeInterval(60 * 60)
|
|
|
|
|
|
+ let newerExpirationDate = newerPurchaseDate.addingTimeInterval(60 * 60)
|
|
let newerItem = ReceiptItem(productId: productId,
|
|
let newerItem = ReceiptItem(productId: productId,
|
|
purchaseDate: newerPurchaseDate,
|
|
purchaseDate: newerPurchaseDate,
|
|
subscriptionExpirationDate: newerExpirationDate,
|
|
subscriptionExpirationDate: newerExpirationDate,
|
|
@@ -338,6 +339,48 @@ class InAppReceiptTests: XCTestCase {
|
|
let expectedSubscriptionResult = VerifySubscriptionResult.expired(expiryDate: newerExpirationDate, items: [newerItem, olderItem])
|
|
let expectedSubscriptionResult = VerifySubscriptionResult.expired(expiryDate: newerExpirationDate, items: [newerItem, olderItem])
|
|
XCTAssertEqual(verifySubscriptionResult, expectedSubscriptionResult)
|
|
XCTAssertEqual(verifySubscriptionResult, expectedSubscriptionResult)
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ // MARK: Verify Subscriptions, multiple receipt item tests
|
|
|
|
+ func testVerifyAutoRenewableSubscriptions_when_threeSubscriptions_twoMatchingProductIds_mostRecentNonExpired_then_resultIsPurchased_itemsSorted() {
|
|
|
|
+
|
|
|
|
+ let receiptRequestDate = makeDateAtMidnight(year: 2017, month: 5, day: 14)
|
|
|
|
+
|
|
|
|
+ let productId1 = "product1"
|
|
|
|
+ let productId2 = "product2"
|
|
|
|
+ let productIds = Set([ productId1, productId2 ])
|
|
|
|
+ let isTrialPeriod = false
|
|
|
|
+
|
|
|
|
+ let olderPurchaseDate = makeDateAtMidnight(year: 2017, month: 5, day: 12)
|
|
|
|
+ let olderExpirationDate = olderPurchaseDate.addingTimeInterval(60 * 60)
|
|
|
|
+ let olderItem = ReceiptItem(productId: productId1,
|
|
|
|
+ purchaseDate: olderPurchaseDate,
|
|
|
|
+ subscriptionExpirationDate: olderExpirationDate,
|
|
|
|
+ cancellationDate: nil,
|
|
|
|
+ isTrialPeriod: isTrialPeriod)
|
|
|
|
+
|
|
|
|
+ let newerPurchaseDate = makeDateAtMidnight(year: 2017, month: 5, day: 14)
|
|
|
|
+ let newerExpirationDate = newerPurchaseDate.addingTimeInterval(60 * 60)
|
|
|
|
+ let newerItem = ReceiptItem(productId: productId2,
|
|
|
|
+ purchaseDate: newerPurchaseDate,
|
|
|
|
+ subscriptionExpirationDate: newerExpirationDate,
|
|
|
|
+ cancellationDate: nil,
|
|
|
|
+ isTrialPeriod: isTrialPeriod)
|
|
|
|
+
|
|
|
|
+ let otherPurchaseDate = makeDateAtMidnight(year: 2017, month: 5, day: 15)
|
|
|
|
+ let otherExpirationDate = otherPurchaseDate.addingTimeInterval(60 * 60)
|
|
|
|
+ let otherItem = ReceiptItem(productId: "otherProduct",
|
|
|
|
+ purchaseDate: otherPurchaseDate,
|
|
|
|
+ subscriptionExpirationDate: otherExpirationDate,
|
|
|
|
+ cancellationDate: nil,
|
|
|
|
+ isTrialPeriod: isTrialPeriod)
|
|
|
|
+
|
|
|
|
+ let receipt = makeReceipt(items: [olderItem, newerItem, otherItem], requestDate: receiptRequestDate)
|
|
|
|
+
|
|
|
|
+ let verifySubscriptionResult = SwiftyStoreKit.verifySubscriptions(ofType: .autoRenewable, productIds: productIds, inReceipt: receipt)
|
|
|
|
+
|
|
|
|
+ let expectedSubscriptionResult = VerifySubscriptionResult.purchased(expiryDate: newerExpirationDate, items: [newerItem, olderItem])
|
|
|
|
+ XCTAssertEqual(verifySubscriptionResult, expectedSubscriptionResult)
|
|
|
|
+ }
|
|
|
|
|
|
// MARK: Helper methods
|
|
// MARK: Helper methods
|
|
func makeReceipt(items: [ReceiptItem], requestDate: Date) -> [String: AnyObject] {
|
|
func makeReceipt(items: [ReceiptItem], requestDate: Date) -> [String: AnyObject] {
|