                                isTrialPeriod: isTrialPeriod)
 
         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,
                                     purchaseDate: newerPurchaseDate,
                                     subscriptionExpirationDate: newerExpirationDate,

                                    isTrialPeriod: isTrialPeriod)
        
        let newerPurchaseDate = makeDateAtMidnight(year: 2017, month: 5, day: 13)
        let newerExpirationDate = olderPurchaseDate.addingTimeInterval(60 * 60)
        let newerItem = ReceiptItem(productId: productId,
                                    purchaseDate: newerPurchaseDate,
                                    subscriptionExpirationDate: newerExpirationDate,

        let verifySubscriptionResult = SwiftyStoreKit.verifySubscription(ofType: .autoRenewable, productId: productId, inReceipt: receipt)
        
        let expectedSubscriptionResult = VerifySubscriptionResult.expired(expiryDate: newerExpirationDate, items: [newerItem, olderItem])
        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)
    }

