@@ -60,6 +60,35 @@ final class InAppPurchase2PluginTests: XCTestCase {
6060 XCTAssertEqual ( testProductMsg, fetchedProductMsg)
6161 }
6262
63+ func testGetTransactions( ) async throws {
64+ let purchaseExpectation = self . expectation ( description: " Purchase should succeed " )
65+ let transactionExpectation = self . expectation (
66+ description: " Getting transactions should succeed " )
67+
68+ plugin. purchase ( id: " consumable " , options: nil ) { result in
69+ switch result {
70+ case . success:
71+ purchaseExpectation. fulfill ( )
72+ case . failure( let error) :
73+ XCTFail ( " Purchase should NOT fail. Failed with \( error) " )
74+ }
75+ }
76+
77+ await fulfillment ( of: [ purchaseExpectation] , timeout: 5 )
78+
79+ plugin. transactions {
80+ result in
81+ switch result {
82+ case . success( let transactions) :
83+ XCTAssert ( transactions. count == 1 )
84+ transactionExpectation. fulfill ( )
85+ case . failure( let error) :
86+ XCTFail ( " Getting transactions should NOT fail. Failed with \( error) " )
87+ }
88+ }
89+ await fulfillment ( of: [ transactionExpectation] , timeout: 5 )
90+ }
91+
6392 func testGetDiscountedProducts( ) async throws {
6493 let expectation = self . expectation ( description: " products successfully fetched " )
6594
@@ -91,7 +120,7 @@ final class InAppPurchase2PluginTests: XCTestCase {
91120 case . success( let productMessages) :
92121 fetchedProductMsg = productMessages
93122 expectation. fulfill ( )
94- case . failure( _ ) :
123+ case . failure:
95124 XCTFail ( " Products should be successfully fetched " )
96125 }
97126 }
@@ -110,7 +139,7 @@ final class InAppPurchase2PluginTests: XCTestCase {
110139
111140 plugin. products ( identifiers: [ " subscription_silver " ] ) { result in
112141 switch result {
113- case . success( _ ) :
142+ case . success:
114143 XCTFail ( " This `products` call should not succeed " )
115144 case . failure( let error) :
116145 expectation. fulfill ( )
@@ -127,7 +156,7 @@ final class InAppPurchase2PluginTests: XCTestCase {
127156 let expectation = self . expectation ( description: " Purchase request should succeed " )
128157 plugin. purchase ( id: " consumable " , options: nil ) { result in
129158 switch result {
130- case . success( let purchaseResult ) :
159+ case . success:
131160 expectation. fulfill ( )
132161 case . failure( let error) :
133162 XCTFail ( " Purchase should NOT fail. Failed with \( error) " )
@@ -143,7 +172,7 @@ final class InAppPurchase2PluginTests: XCTestCase {
143172 let expectation = self . expectation ( description: " products request should fail " )
144173 plugin. purchase ( id: " consumable " , options: nil ) { result in
145174 switch result {
146- case . success( _ ) :
175+ case . success:
147176 XCTFail ( " Purchase should NOT suceed. " )
148177 case . failure( let error) :
149178 XCTAssertEqual (
@@ -162,7 +191,7 @@ final class InAppPurchase2PluginTests: XCTestCase {
162191 let expectation = self . expectation ( description: " Purchase request should succeed " )
163192 plugin. purchase ( id: " consumable " , options: nil ) { result in
164193 switch result {
165- case . success( _ ) :
194+ case . success:
166195 XCTFail ( " Purchase should NOT suceed. " )
167196 case . failure( let error) :
168197 XCTAssertEqual ( error. localizedDescription, " Item Unavailable " )
@@ -176,7 +205,7 @@ final class InAppPurchase2PluginTests: XCTestCase {
176205 let expectation = self . expectation ( description: " products request should fail " )
177206 plugin. purchase ( id: " invalid_product " , options: nil ) { result in
178207 switch result {
179- case . success( _ ) :
208+ case . success:
180209 XCTFail ( " Purchase should NOT suceed. " )
181210 case . failure( let error) :
182211 let pigeonError = error as! PigeonError
@@ -192,7 +221,7 @@ final class InAppPurchase2PluginTests: XCTestCase {
192221 let expectation = self . expectation ( description: " Purchase request should succeed " )
193222 plugin. purchase ( id: " subscription_discounted " , options: nil ) { result in
194223 switch result {
195- case . success( let purchaseResult ) :
224+ case . success:
196225 expectation. fulfill ( )
197226 case . failure( let error) :
198227 XCTFail ( " Purchase should NOT fail. Failed with \( error) " )
@@ -205,7 +234,7 @@ final class InAppPurchase2PluginTests: XCTestCase {
205234 let expectation = self . expectation ( description: " Purchase request should succeed " )
206235 plugin. purchase ( id: " subscription_discounted " , options: nil ) { result in
207236 switch result {
208- case . success( let purchaseResult ) :
237+ case . success:
209238 expectation. fulfill ( )
210239 case . failure( let error) :
211240 XCTFail ( " Purchase should NOT fail. Failed with \( error) " )
@@ -218,7 +247,7 @@ final class InAppPurchase2PluginTests: XCTestCase {
218247 let expectation = self . expectation ( description: " Purchase request should succeed " )
219248 plugin. purchase ( id: " consumable_discounted " , options: nil ) { result in
220249 switch result {
221- case . success( let purchaseResult ) :
250+ case . success:
222251 expectation. fulfill ( )
223252 case . failure( let error) :
224253 XCTFail ( " Purchase should NOT fail. Failed with \( error) " )
@@ -233,7 +262,7 @@ final class InAppPurchase2PluginTests: XCTestCase {
233262
234263 plugin. purchase ( id: " subscription_silver " , options: nil ) { result in
235264 switch result {
236- case . success( _ ) :
265+ case . success:
237266 purchaseExpectation. fulfill ( )
238267 case . failure( let error) :
239268 XCTFail ( " Purchase should NOT fail. Failed with \( error) " )
@@ -250,4 +279,32 @@ final class InAppPurchase2PluginTests: XCTestCase {
250279
251280 await fulfillment( of: [ restoreExpectation, purchaseExpectation] , timeout: 5 )
252281 }
282+
283+ func testFinishTransaction ( ) async throws {
284+ let purchaseExpectation = self . expectation ( description: " Purchase should succeed " )
285+ let finishExpectation = self . expectation ( description: " Finishing purchase should succeed " )
286+
287+ plugin. purchase ( id: " consumable " , options: nil ) { result in
288+ switch result {
289+ case . success( let purchase) :
290+ purchaseExpectation. fulfill ( )
291+ case . failure( let error) :
292+ XCTFail ( " Purchase should NOT fail. Failed with \( error) " )
293+ }
294+ }
295+
296+ await fulfillment ( of: [ purchaseExpectation] , timeout: 5 )
297+
298+ // id should always be 0 as it is the first purchase
299+ plugin. finish ( id: 0 ) { result in
300+ switch result {
301+ case . success ( ) :
302+ finishExpectation. fulfill ( )
303+ case . failure ( let error) :
304+ XCTFail ( " Finish purchases should NOT fail. Failed with \( error) " )
305+ }
306+ }
307+
308+ await fulfillment( of: [ finishExpectation] , timeout: 5 )
309+ }
253310}
0 commit comments