Skip to content

Commit

Permalink
test: migrate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hyochan committed Oct 31, 2023
1 parent 475e88d commit 47320ee
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

- run: flutter pub get

- run: flutter format --set-exit-if-changed .
- run: dart format --set-exit-if-changed .

# - run: flutter analyze .

Expand Down
12 changes: 6 additions & 6 deletions lib/flutter_inapp_purchase.dart
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,14 @@ class FlutterInappPurchase {
final dynamic getInappPurchaseHistory = await _channel.invokeMethod(
'getPurchaseHistoryByType',
<String, dynamic>{
'type': describeEnum(_TypeInApp.inapp),
'type': _TypeInApp.inapp.name, // describeEnum 대신 name 속성 사용
},
);

final dynamic getSubsPurchaseHistory = await _channel.invokeMethod(
'getPurchaseHistoryByType',
<String, dynamic>{
'type': describeEnum(_TypeInApp.subs),
'type': _TypeInApp.subs.name, // describeEnum 대신 name 속성 사용
},
);

Expand Down Expand Up @@ -242,14 +242,14 @@ class FlutterInappPurchase {
dynamic result1 = await _channel.invokeMethod(
'getAvailableItemsByType',
<String, dynamic>{
'type': describeEnum(_TypeInApp.inapp),
'type': _TypeInApp.inapp.name,
},
);

dynamic result2 = await _channel.invokeMethod(
'getAvailableItemsByType',
<String, dynamic>{
'type': describeEnum(_TypeInApp.subs),
'type': _TypeInApp.subs.name,
},
);
return extractPurchased(result1)! + extractPurchased(result2)!;
Expand All @@ -276,7 +276,7 @@ class FlutterInappPurchase {
int? offerTokenIndex}) async {
if (_platform.isAndroid) {
return await _channel.invokeMethod('buyItemByType', <String, dynamic>{
'type': describeEnum(_TypeInApp.inapp),
'type': _TypeInApp.inapp.name,
'productId': productId,
'prorationMode': -1,
'obfuscatedAccountId': obfuscatedAccountId,
Expand Down Expand Up @@ -313,7 +313,7 @@ class FlutterInappPurchase {
}) async {
if (_platform.isAndroid) {
return await _channel.invokeMethod('buyItemByType', <String, dynamic>{
'type': describeEnum(_TypeInApp.subs),
'type': _TypeInApp.subs.name,
'productId': productId,
'prorationMode': prorationModeAndroid ?? -1,
'obfuscatedAccountId': obfuscatedAccountIdAndroid,
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description: In App Purchase plugin for flutter. This project has been forked by
version: 5.5.0
homepage: https://github.com/dooboolab/flutter_inapp_purchase/blob/main/pubspec.yaml
environment:
sdk: ">=2.12.0 <4.0.0"
sdk: ">=2.15.0 <4.0.0"
flutter: ">=2.0.0"

dependencies:
Expand Down
88 changes: 46 additions & 42 deletions test/flutter_inapp_purchase_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:platform/platform.dart';

void main() {
TestWidgetsFlutterBinding.ensureInitialized();
final MethodChannel channel = FlutterInappPurchase.channel;

group('FlutterInappPurchase', () {
group('showInAppMessageAndroid', () {
Expand All @@ -16,8 +17,8 @@ void main() {
FlutterInappPurchase(FlutterInappPurchase.private(
FakePlatform(operatingSystem: "android")));

FlutterInappPurchase.channel
.setMockMethodCallHandler((MethodCall methodCall) async {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
log.add(methodCall);
return "ready";
});
Expand Down Expand Up @@ -47,8 +48,8 @@ void main() {
FlutterInappPurchase(FlutterInappPurchase.private(
FakePlatform(operatingSystem: "android")));

FlutterInappPurchase.channel
.setMockMethodCallHandler((MethodCall methodCall) async {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
log.add(methodCall);
return "All items have been consumed";
});
Expand Down Expand Up @@ -95,8 +96,8 @@ void main() {
FlutterInappPurchase(FlutterInappPurchase.private(
FakePlatform(operatingSystem: "android")));

FlutterInappPurchase.channel
.setMockMethodCallHandler((MethodCall methodCall) async {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
log.add(methodCall);
return "Billing client ready";
});
Expand Down Expand Up @@ -125,8 +126,8 @@ void main() {
FlutterInappPurchase(FlutterInappPurchase.private(
FakePlatform(operatingSystem: "ios")));

FlutterInappPurchase.channel
.setMockMethodCallHandler((MethodCall methodCall) async {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
log.add(methodCall);
return "true";
});
Expand Down Expand Up @@ -196,8 +197,8 @@ void main() {
FlutterInappPurchase(FlutterInappPurchase.private(
FakePlatform(operatingSystem: "android")));

FlutterInappPurchase.channel
.setMockMethodCallHandler((MethodCall methodCall) async {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
log.add(methodCall);
return result;
});
Expand Down Expand Up @@ -292,8 +293,8 @@ void main() {
FlutterInappPurchase(FlutterInappPurchase.private(
FakePlatform(operatingSystem: "ios")));

FlutterInappPurchase.channel
.setMockMethodCallHandler((MethodCall methodCall) async {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
log.add(methodCall);
return result;
});
Expand Down Expand Up @@ -385,8 +386,8 @@ void main() {
FlutterInappPurchase(FlutterInappPurchase.private(
FakePlatform(operatingSystem: "android")));

FlutterInappPurchase.channel
.setMockMethodCallHandler((MethodCall methodCall) async {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
log.add(methodCall);
return result;
});
Expand Down Expand Up @@ -475,8 +476,8 @@ void main() {
FlutterInappPurchase(FlutterInappPurchase.private(
FakePlatform(operatingSystem: "ios")));

FlutterInappPurchase.channel
.setMockMethodCallHandler((MethodCall methodCall) async {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
log.add(methodCall);
return result;
});
Expand Down Expand Up @@ -571,15 +572,17 @@ void main() {
FlutterInappPurchase(FlutterInappPurchase.private(
FakePlatform(operatingSystem: "android")));

FlutterInappPurchase.channel
.setMockMethodCallHandler((MethodCall methodCall) async {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
log.add(methodCall);
var m = methodCall.arguments as Map<dynamic, dynamic>;

if (m['type'] == 'inapp') {
return resultInapp;
} else if (m['type'] == 'subs') {
return resultSubs;
}

return null;
});
});
Expand Down Expand Up @@ -670,8 +673,8 @@ void main() {
FlutterInappPurchase(FlutterInappPurchase.private(
FakePlatform(operatingSystem: "ios")));

FlutterInappPurchase.channel
.setMockMethodCallHandler((MethodCall methodCall) async {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
log.add(methodCall);
return result;
});
Expand Down Expand Up @@ -752,9 +755,10 @@ void main() {
FlutterInappPurchase(FlutterInappPurchase.private(
FakePlatform(operatingSystem: "android")));

FlutterInappPurchase.channel
.setMockMethodCallHandler((MethodCall methodCall) async {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
log.add(methodCall);

var m = methodCall.arguments as Map<dynamic, dynamic>;
if (m['type'] == 'inapp') {
return resultInapp;
Expand Down Expand Up @@ -852,8 +856,8 @@ void main() {
FlutterInappPurchase(FlutterInappPurchase.private(
FakePlatform(operatingSystem: "ios")));

FlutterInappPurchase.channel
.setMockMethodCallHandler((MethodCall methodCall) async {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
log.add(methodCall);
return result;
});
Expand Down Expand Up @@ -929,8 +933,8 @@ void main() {
FlutterInappPurchase(FlutterInappPurchase.private(
FakePlatform(operatingSystem: "ios")));

FlutterInappPurchase.channel
.setMockMethodCallHandler((MethodCall methodCall) async {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
log.add(methodCall);
return null;
});
Expand Down Expand Up @@ -985,8 +989,8 @@ void main() {
FlutterInappPurchase(FlutterInappPurchase.private(
FakePlatform(operatingSystem: "android")));

FlutterInappPurchase.channel
.setMockMethodCallHandler((MethodCall methodCall) async {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
log.add(methodCall);
return null;
});
Expand Down Expand Up @@ -1045,8 +1049,8 @@ void main() {
FlutterInappPurchase(FlutterInappPurchase.private(
FakePlatform(operatingSystem: "android")));

FlutterInappPurchase.channel
.setMockMethodCallHandler((MethodCall methodCall) async {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
log.add(methodCall);
return null;
});
Expand Down Expand Up @@ -1106,8 +1110,8 @@ void main() {
FlutterInappPurchase(FlutterInappPurchase.private(
FakePlatform(operatingSystem: "ios")));

FlutterInappPurchase.channel
.setMockMethodCallHandler((MethodCall methodCall) async {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
log.add(methodCall);
return null;
});
Expand Down Expand Up @@ -1149,8 +1153,8 @@ void main() {
FlutterInappPurchase(FlutterInappPurchase.private(
FakePlatform(operatingSystem: "android")));

FlutterInappPurchase.channel
.setMockMethodCallHandler((MethodCall methodCall) async {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
log.add(methodCall);
return null;
});
Expand Down Expand Up @@ -1190,8 +1194,8 @@ void main() {
FlutterInappPurchase(FlutterInappPurchase.private(
FakePlatform(operatingSystem: "android")));

FlutterInappPurchase.channel
.setMockMethodCallHandler((MethodCall methodCall) async {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
log.add(methodCall);
return null;
});
Expand Down Expand Up @@ -1225,8 +1229,8 @@ void main() {
FlutterInappPurchase(FlutterInappPurchase.private(
FakePlatform(operatingSystem: "android")));

FlutterInappPurchase.channel
.setMockMethodCallHandler((MethodCall methodCall) async {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
log.add(methodCall);
return "Billing client has ended.";
});
Expand Down Expand Up @@ -1273,8 +1277,8 @@ void main() {
FlutterInappPurchase(FlutterInappPurchase.private(
FakePlatform(operatingSystem: "ios")));

FlutterInappPurchase.channel
.setMockMethodCallHandler((MethodCall methodCall) async {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
log.add(methodCall);
return null;
});
Expand Down Expand Up @@ -1349,8 +1353,8 @@ void main() {
FlutterInappPurchase(FlutterInappPurchase.private(
FakePlatform(operatingSystem: "ios")));

FlutterInappPurchase.channel
.setMockMethodCallHandler((MethodCall methodCall) async {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (MethodCall methodCall) async {
log.add(methodCall);
return result;
});
Expand Down
3 changes: 1 addition & 2 deletions test/utils_test.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';

enum _TestEnum { Hoge }

void main() {
group('utils', () {
test('EnumUtil.getValueString', () async {
String value = describeEnum(_TestEnum.Hoge);
String value = _TestEnum.Hoge.name;
expect(value, "Hoge");
});
});
Expand Down

0 comments on commit 47320ee

Please sign in to comment.