@@ -18,19 +18,24 @@ void main() {
18
18
TestWidgetsFlutterBinding .ensureInitialized ();
19
19
20
20
final FakeIOSPlatform fakeIOSPlatform = FakeIOSPlatform ();
21
+ late InAppPurchaseIosPlatform iapIosPlatform;
21
22
22
23
setUpAll (() {
23
24
SystemChannels .platform
24
25
.setMockMethodCallHandler (fakeIOSPlatform.onMethodCall);
25
26
});
26
27
27
- setUp (() => fakeIOSPlatform.reset ());
28
+ setUp (() {
29
+ InAppPurchaseIosPlatform .registerPlatform ();
30
+ iapIosPlatform = InAppPurchasePlatform .instance as InAppPurchaseIosPlatform ;
31
+ fakeIOSPlatform.reset ();
32
+ });
28
33
29
34
tearDown (() => fakeIOSPlatform.reset ());
30
35
31
36
group ('isAvailable' , () {
32
37
test ('true' , () async {
33
- expect (await InAppPurchaseIosPlatform .instance .isAvailable (), isTrue);
38
+ expect (await iapIosPlatform .isAvailable (), isTrue);
34
39
});
35
40
});
36
41
@@ -69,8 +74,7 @@ void main() {
69
74
group ('restore purchases' , () {
70
75
test ('should emit restored transactions on purchase stream' , () async {
71
76
Completer completer = Completer ();
72
- Stream <List <PurchaseDetails >> stream =
73
- InAppPurchaseIosPlatform .instance.purchaseStream;
77
+ Stream <List <PurchaseDetails >> stream = iapIosPlatform.purchaseStream;
74
78
75
79
late StreamSubscription subscription;
76
80
subscription = stream.listen ((purchaseDetailsList) {
@@ -80,7 +84,7 @@ void main() {
80
84
}
81
85
});
82
86
83
- await InAppPurchaseIosPlatform .instance .restorePurchases ();
87
+ await iapIosPlatform .restorePurchases ();
84
88
List <PurchaseDetails > details = await completer.future;
85
89
86
90
expect (details.length, 2 );
@@ -103,8 +107,7 @@ void main() {
103
107
fakeIOSPlatform.transactions
104
108
.insert (0 , fakeIOSPlatform.createPurchasedTransaction ('foo' , 'bar' ));
105
109
Completer completer = Completer ();
106
- Stream <List <PurchaseDetails >> stream =
107
- InAppPurchaseIosPlatform .instance.purchaseStream;
110
+ Stream <List <PurchaseDetails >> stream = iapIosPlatform.purchaseStream;
108
111
109
112
late StreamSubscription subscription;
110
113
subscription = stream.listen ((purchaseDetailsList) {
@@ -113,7 +116,7 @@ void main() {
113
116
subscription.cancel ();
114
117
}
115
118
});
116
- await InAppPurchaseIosPlatform .instance .restorePurchases ();
119
+ await iapIosPlatform .restorePurchases ();
117
120
List <PurchaseDetails > details = await completer.future;
118
121
expect (details.length, 3 );
119
122
for (int i = 0 ; i < fakeIOSPlatform.transactions.length; i++ ) {
@@ -139,8 +142,7 @@ void main() {
139
142
() async {
140
143
fakeIOSPlatform.receiptData = null ;
141
144
Completer completer = Completer ();
142
- Stream <List <PurchaseDetails >> stream =
143
- InAppPurchaseIosPlatform .instance.purchaseStream;
145
+ Stream <List <PurchaseDetails >> stream = iapIosPlatform.purchaseStream;
144
146
145
147
late StreamSubscription subscription;
146
148
subscription = stream.listen ((purchaseDetailsList) {
@@ -150,7 +152,7 @@ void main() {
150
152
}
151
153
});
152
154
153
- await InAppPurchaseIosPlatform .instance .restorePurchases ();
155
+ await iapIosPlatform .restorePurchases ();
154
156
List <PurchaseDetails > details = await completer.future;
155
157
156
158
for (PurchaseDetails purchase in details) {
@@ -166,7 +168,7 @@ void main() {
166
168
userInfo: {'message' : 'errorMessage' });
167
169
168
170
expect (
169
- () => InAppPurchaseIosPlatform .instance .restorePurchases (),
171
+ () => iapIosPlatform .restorePurchases (),
170
172
throwsA (
171
173
isA <SKError >()
172
174
.having ((error) => error.code, 'code' , 123 )
@@ -183,8 +185,7 @@ void main() {
183
185
() async {
184
186
List <PurchaseDetails > details = [];
185
187
Completer completer = Completer ();
186
- Stream <List <PurchaseDetails >> stream =
187
- InAppPurchaseIosPlatform .instance.purchaseStream;
188
+ Stream <List <PurchaseDetails >> stream = iapIosPlatform.purchaseStream;
188
189
189
190
late StreamSubscription subscription;
190
191
subscription = stream.listen ((purchaseDetailsList) {
@@ -198,8 +199,7 @@ void main() {
198
199
productDetails:
199
200
AppStoreProductDetails .fromSKProduct (dummyProductWrapper),
200
201
applicationUserName: 'appName' );
201
- await InAppPurchaseIosPlatform .instance
202
- .buyNonConsumable (purchaseParam: purchaseParam);
202
+ await iapIosPlatform.buyNonConsumable (purchaseParam: purchaseParam);
203
203
204
204
List <PurchaseDetails > result = await completer.future;
205
205
expect (result.length, 2 );
@@ -211,8 +211,7 @@ void main() {
211
211
() async {
212
212
List <PurchaseDetails > details = [];
213
213
Completer completer = Completer ();
214
- Stream <List <PurchaseDetails >> stream =
215
- InAppPurchaseIosPlatform .instance.purchaseStream;
214
+ Stream <List <PurchaseDetails >> stream = iapIosPlatform.purchaseStream;
216
215
217
216
late StreamSubscription subscription;
218
217
subscription = stream.listen ((purchaseDetailsList) {
@@ -226,8 +225,7 @@ void main() {
226
225
productDetails:
227
226
AppStoreProductDetails .fromSKProduct (dummyProductWrapper),
228
227
applicationUserName: 'appName' );
229
- await InAppPurchaseIosPlatform .instance
230
- .buyConsumable (purchaseParam: purchaseParam);
228
+ await iapIosPlatform.buyConsumable (purchaseParam: purchaseParam);
231
229
232
230
List <PurchaseDetails > result = await completer.future;
233
231
expect (result.length, 2 );
@@ -240,8 +238,8 @@ void main() {
240
238
AppStoreProductDetails .fromSKProduct (dummyProductWrapper),
241
239
applicationUserName: 'appName' );
242
240
expect (
243
- () => InAppPurchaseIosPlatform .instance
244
- . buyConsumable ( purchaseParam: purchaseParam, autoConsume: false ),
241
+ () => iapIosPlatform. buyConsumable (
242
+ purchaseParam: purchaseParam, autoConsume: false ),
245
243
throwsA (isInstanceOf <AssertionError >()));
246
244
});
247
245
@@ -251,8 +249,7 @@ void main() {
251
249
Completer completer = Completer ();
252
250
late IAPError error;
253
251
254
- Stream <List <PurchaseDetails >> stream =
255
- InAppPurchaseIosPlatform .instance.purchaseStream;
252
+ Stream <List <PurchaseDetails >> stream = iapIosPlatform.purchaseStream;
256
253
late StreamSubscription subscription;
257
254
subscription = stream.listen ((purchaseDetailsList) {
258
255
details.addAll (purchaseDetailsList);
@@ -268,8 +265,7 @@ void main() {
268
265
productDetails:
269
266
AppStoreProductDetails .fromSKProduct (dummyProductWrapper),
270
267
applicationUserName: 'appName' );
271
- await InAppPurchaseIosPlatform .instance
272
- .buyNonConsumable (purchaseParam: purchaseParam);
268
+ await iapIosPlatform.buyNonConsumable (purchaseParam: purchaseParam);
273
269
274
270
IAPError completerError = await completer.future;
275
271
expect (completerError.code, 'purchase_error' );
@@ -283,14 +279,13 @@ void main() {
283
279
test ('should complete purchase' , () async {
284
280
List <PurchaseDetails > details = [];
285
281
Completer completer = Completer ();
286
- Stream <List <PurchaseDetails >> stream =
287
- InAppPurchaseIosPlatform .instance.purchaseStream;
282
+ Stream <List <PurchaseDetails >> stream = iapIosPlatform.purchaseStream;
288
283
late StreamSubscription subscription;
289
284
subscription = stream.listen ((purchaseDetailsList) {
290
285
details.addAll (purchaseDetailsList);
291
286
purchaseDetailsList.forEach ((purchaseDetails) {
292
287
if (purchaseDetails.pendingCompletePurchase) {
293
- InAppPurchaseIosPlatform .instance .completePurchase (purchaseDetails);
288
+ iapIosPlatform .completePurchase (purchaseDetails);
294
289
completer.complete (details);
295
290
subscription.cancel ();
296
291
}
@@ -300,8 +295,7 @@ void main() {
300
295
productDetails:
301
296
AppStoreProductDetails .fromSKProduct (dummyProductWrapper),
302
297
applicationUserName: 'appName' );
303
- await InAppPurchaseIosPlatform .instance
304
- .buyNonConsumable (purchaseParam: purchaseParam);
298
+ await iapIosPlatform.buyNonConsumable (purchaseParam: purchaseParam);
305
299
List <PurchaseDetails > result = await completer.future;
306
300
expect (result.length, 2 );
307
301
expect (result.first.productID, dummyProductWrapper.productIdentifier);
0 commit comments