Browse Source

fixed test errors

Jan Remes 5 years ago
parent
commit
55f010cb5d

+ 0 - 1
SwiftyStoreKit/PaymentQueueController.swift

@@ -124,7 +124,6 @@ class PaymentQueueController: NSObject, SKPaymentTransactionObserver {
         skPayment.quantity = payment.quantity
         
         if #available(iOS 12.2, tvOS 12.2, OSX 10.14.4, *) {
-            
             if let discount = payment.paymentDiscount?.discount as? SKPaymentDiscount {
                 skPayment.paymentDiscount = discount
             }

+ 5 - 1
SwiftyStoreKit/PaymentsController.swift

@@ -49,12 +49,16 @@ struct Payment: Hashable {
 }
 
 public struct PaymentDiscount {
-    let discount: AnyObject
+    let discount: AnyObject?
     
     @available(iOS 12.2, tvOS 12.2, OSX 10.14.4, *)
     public init(discount: SKPaymentDiscount) {
         self.discount = discount
     }
+    
+    private init() {
+        self.discount = nil
+    }
 }
 
 class PaymentsController: TransactionController {

+ 3 - 2
SwiftyStoreKitTests/PaymentQueueControllerTests.swift

@@ -29,7 +29,8 @@ import StoreKit
 @testable import SwiftyStoreKit
 
 extension Payment {
-    init(product: SKProduct, quantity: Int, atomically: Bool, applicationUsername: String, simulatesAskToBuyInSandbox: Bool, callback: @escaping (TransactionResult) -> Void) {
+    init(product: SKProduct, paymentDiscount: PaymentDiscount, quantity: Int, atomically: Bool, applicationUsername: String, simulatesAskToBuyInSandbox: Bool, callback: @escaping (TransactionResult) -> Void) {
+        self.paymentDiscount = paymentDiscount
         self.product = product
         self.quantity = quantity
         self.atomically = atomically
@@ -301,6 +302,6 @@ class PaymentQueueControllerTests: XCTestCase {
     func makeTestPayment(productIdentifier: String, quantity: Int = 1, atomically: Bool = true, callback: @escaping (TransactionResult) -> Void) -> Payment {
 
         let testProduct = TestProduct(productIdentifier: productIdentifier)
-        return Payment(product: testProduct, quantity: quantity, atomically: atomically, applicationUsername: "", simulatesAskToBuyInSandbox: false, callback: callback)
+        return Payment(product: testProduct, paymentDiscount: nil, quantity: quantity, atomically: atomically, applicationUsername: "", simulatesAskToBuyInSandbox: false, callback: callback)
     }
 }

+ 1 - 1
SwiftyStoreKitTests/PaymentsControllerTests.swift

@@ -240,7 +240,7 @@ class PaymentsControllerTests: XCTestCase {
 
     func makeTestPayment(product: SKProduct, atomically: Bool = true, callback: @escaping (TransactionResult) -> Void) -> Payment {
 
-        return Payment(product: product, quantity: 1, atomically: atomically, applicationUsername: "", simulatesAskToBuyInSandbox: false, callback: callback)
+        return Payment(product: product, paymentDiscount: nil, quantity: 1, atomically: atomically, applicationUsername: "", simulatesAskToBuyInSandbox: false, callback: callback)
     }
 
     func makeTestPayment(productIdentifier: String, atomically: Bool = true, callback: @escaping (TransactionResult) -> Void) -> Payment {