@@ -8,10 +8,14 @@ import XCTest
88@testable import in_app_purchase_storekit
99
1010final class FakeIAP2Callback : InAppPurchase2CallbackAPIProtocol {
11+
12+ public var lastUpdate : [ in_app_purchase_storekit . SK2TransactionMessage ] = [ ]
13+
1114 func onTransactionsUpdated(
1215 newTransactions newTransactionsArg: [ in_app_purchase_storekit . SK2TransactionMessage ] ,
1316 completion: @escaping ( Result < Void , in_app_purchase_storekit . PigeonError > ) -> Void
1417 ) {
18+ lastUpdate = newTransactionsArg
1519 // We should only write to a flutter channel from the main thread.
1620 XCTAssertTrue ( Thread . isMainThread)
1721 }
@@ -21,6 +25,7 @@ final class FakeIAP2Callback: InAppPurchase2CallbackAPIProtocol {
2125final class InAppPurchase2PluginTests: XCTestCase {
2226 private var session : SKTestSession !
2327 private var plugin : InAppPurchasePlugin !
28+ private var callback : FakeIAP2Callback = FakeIAP2Callback ( )
2429
2530 override func setUp( ) async throws {
2631 try await super. setUp ( )
@@ -33,7 +38,7 @@ final class InAppPurchase2PluginTests: XCTestCase {
3338 plugin = InAppPurchasePluginStub ( receiptManager: FIAPReceiptManagerStub ( ) ) { request in
3439 DefaultRequestHandler ( requestHandler: FIAPRequestHandler ( request: request) )
3540 }
36- plugin. transactionCallbackAPI = FakeIAP2Callback ( )
41+ plugin. transactionCallbackAPI = callback
3742 try plugin. startListeningToTransactions ( )
3843 }
3944
@@ -86,11 +91,17 @@ final class InAppPurchase2PluginTests: XCTestCase {
8691
8792 await fulfillment ( of: [ purchaseExpectation] , timeout: 5 )
8893
94+ XCTAssert ( callback. lastUpdate. count == 1 )
95+ XCTAssert (
96+ callback. lastUpdate. first? . restoring == false ,
97+ " Ordinary purchase updates should not be marked as restoring " )
98+
8999 plugin. transactions {
90100 result in
91101 switch result {
92102 case . success( let transactions) :
93103 XCTAssert ( transactions. count == 1 )
104+ XCTAssert ( transactions. first? . restoring == false )
94105 transactionExpectation. fulfill ( )
95106 case . failure( let error) :
96107 XCTFail ( " Getting transactions should NOT fail. Failed with \( error) " )
@@ -376,6 +387,9 @@ final class InAppPurchase2PluginTests: XCTestCase {
376387 }
377388 await fulfillment ( of: [ purchaseExpectation] , timeout: 5 )
378389
390+ XCTAssert ( callback. lastUpdate. count == 1 )
391+ XCTAssert ( callback. lastUpdate. first? . restoring == false )
392+
379393 plugin . restorePurchases { result in
380394 switch result {
381395 case . success ( ) :
@@ -385,6 +399,9 @@ final class InAppPurchase2PluginTests: XCTestCase {
385399 }
386400 }
387401 await fulfillment( of: [ restoreExpectation] , timeout: 5 )
402+
403+ XCTAssert( callback. lastUpdate. count == 1 )
404+ XCTAssert( callback. lastUpdate. first? . restoring == true )
388405 }
389406
390407 func testFinishTransaction ( ) async throws {
0 commit comments