Skip to content

Commit

Permalink
Merge pull request #198 from bizz84/feature/verify-purchase-subscript…
Browse files Browse the repository at this point in the history
…ion-unit-tests

Feature/verify purchase subscription unit tests
  • Loading branch information
bizz84 authored May 8, 2017
2 parents 378576e + 0b943ee commit 563d60f
Show file tree
Hide file tree
Showing 3 changed files with 380 additions and 1 deletion.
4 changes: 4 additions & 0 deletions SwiftyStoreKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
658A08431E2EC5120074A98F /* SwiftyStoreKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6502F62D1B985C40004E342D /* SwiftyStoreKit.framework */; };
658A084A1E2EC5350074A98F /* PaymentQueueControllerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 658A08491E2EC5350074A98F /* PaymentQueueControllerTests.swift */; };
658A084C1E2EC5960074A98F /* PaymentQueueSpy.swift in Sources */ = {isa = PBXBuildFile; fileRef = 658A084B1E2EC5960074A98F /* PaymentQueueSpy.swift */; };
65B8C9291EC0BE62009439D9 /* InAppReceiptTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65B8C9281EC0BE62009439D9 /* InAppReceiptTests.swift */; };
65BB6CE81DDB018900218A0B /* SwiftyStoreKit+Types.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BB6CE71DDB018900218A0B /* SwiftyStoreKit+Types.swift */; };
65BB6CE91DDB018900218A0B /* SwiftyStoreKit+Types.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BB6CE71DDB018900218A0B /* SwiftyStoreKit+Types.swift */; };
65BB6CEA1DDB018900218A0B /* SwiftyStoreKit+Types.swift in Sources */ = {isa = PBXBuildFile; fileRef = 65BB6CE71DDB018900218A0B /* SwiftyStoreKit+Types.swift */; };
Expand Down Expand Up @@ -176,6 +177,7 @@
658A08421E2EC5120074A98F /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
658A08491E2EC5350074A98F /* PaymentQueueControllerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PaymentQueueControllerTests.swift; sourceTree = "<group>"; };
658A084B1E2EC5960074A98F /* PaymentQueueSpy.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PaymentQueueSpy.swift; sourceTree = "<group>"; };
65B8C9281EC0BE62009439D9 /* InAppReceiptTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InAppReceiptTests.swift; sourceTree = "<group>"; };
65BB6CE71DDB018900218A0B /* SwiftyStoreKit+Types.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "SwiftyStoreKit+Types.swift"; sourceTree = "<group>"; };
65F70AC61E2ECBB300BF040D /* PaymentTransactionObserverFake.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PaymentTransactionObserverFake.swift; sourceTree = "<group>"; };
65F70AC81E2EDC3700BF040D /* PaymentsController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PaymentsController.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -330,6 +332,7 @@
C3099C061E2FCDAA00392A54 /* PaymentsControllerTests.swift */,
650307F11E3163AA001332A4 /* RestorePurchasesControllerTests.swift */,
C3099C181E3206C700392A54 /* CompleteTransactionsControllerTests.swift */,
65B8C9281EC0BE62009439D9 /* InAppReceiptTests.swift */,
658A084B1E2EC5960074A98F /* PaymentQueueSpy.swift */,
65F70AC61E2ECBB300BF040D /* PaymentTransactionObserverFake.swift */,
C3099C081E2FCE3A00392A54 /* TestProduct.swift */,
Expand Down Expand Up @@ -767,6 +770,7 @@
C3099C191E3206C700392A54 /* CompleteTransactionsControllerTests.swift in Sources */,
658A084C1E2EC5960074A98F /* PaymentQueueSpy.swift in Sources */,
C3099C091E2FCE3A00392A54 /* TestProduct.swift in Sources */,
65B8C9291EC0BE62009439D9 /* InAppReceiptTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
4 changes: 3 additions & 1 deletion SwiftyStoreKit/InAppReceipt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@ internal class InAppReceipt {
// Get receipts info for the product
let receipts = receipt["receipt"]?["in_app"] as? [ReceiptInfo]
let receiptsInfo = filterReceiptsInfo(receipts: receipts, withProductId: productId)
let nonCancelledReceiptsInfo = receiptsInfo.filter { receipt in receipt["cancellation_date"] == nil }

// Verify that at least one receipt has the right product id
return receiptsInfo.count >= 1 ? .purchased : .notPurchased
return nonCancelledReceiptsInfo.count >= 1 ? .purchased : .notPurchased
}

/**
Expand Down Expand Up @@ -115,6 +116,7 @@ internal class InAppReceipt {
// Return the expires dates sorted desc
let expiryDateValues = nonCancelledReceiptsInfo
.flatMap { (receipt) -> String? in

let key: String = duration != nil ? "original_purchase_date_ms" : "expires_date_ms"
return receipt[key] as? String
}
Expand Down
Loading

0 comments on commit 563d60f

Please sign in to comment.