11import 'dart:async' ;
22
3- import 'package:flutter/services.dart' ;
43import 'package:flutter_test/flutter_test.dart' ;
54import 'package:mindbox/mindbox.dart' ;
65import 'package:mindbox_ios/mindbox_ios.dart' ;
76import 'package:mindbox_platform_interface/mindbox_platform_interface.dart' ;
87
98void main () {
10- const MethodChannel channel = MethodChannel ('mindbox.cloud/flutter-sdk' );
11-
129 TestWidgetsFlutterBinding .ensureInitialized ();
1310
1411 setUp (() {
1512 MindboxIosPlatform .registerPlatform ();
16- channel.setMockMethodCallHandler ((MethodCall methodCall) async {
17- switch (methodCall.method) {
18- case 'init' :
19- final args = methodCall.arguments;
20- final String domain = args['domain' ];
21- final String endpointIos = args['endpointIos' ];
22- final String endpointAndroid = args['endpointAndroid' ];
23- if (domain.isEmpty ||
24- endpointIos.isEmpty ||
25- endpointAndroid.isEmpty) {
26- throw MindboxException (message: 'wrong configuration' );
27- }
28- return Future .value (true );
29- case 'getDeviceUUID' :
30- return Future .value ('dummy-device-uuid' );
31- case 'getToken' :
32- return Future .value ('dummy-token' );
33- default :
34- return '1.2.0' ;
35- }
36- });
13+ channel.setMockMethodCallHandler (mindboxMockMethodCallHandler);
3714 });
3815
3916 tearDown (() {
4017 channel.setMockMethodCallHandler (null );
4118 });
4219
4320 test ('getPlatformVersion' , () async {
44- expect (await Mindbox .instance.sdkVersion, '1.2.0 ' );
21+ expect (await Mindbox .instance.sdkVersion, 'dummy-sdk-version ' );
4522 });
4623
4724 test ('init()' , () async {
@@ -51,19 +28,7 @@ void main() {
5128 endpointAndroid: 'endpointAndroid' ,
5229 subscribeCustomerIfCreated: true );
5330
54- await Mindbox .instance.init (configuration: validConfig);
55- });
56-
57- test ('When config is invalid, init() calling should throws MindboxException' ,
58- () async {
59- final invalidConfig = Configuration (
60- domain: '' ,
61- endpointIos: '' ,
62- endpointAndroid: '' ,
63- subscribeCustomerIfCreated: true );
64-
65- expect (() async => Mindbox .instance.init (configuration: invalidConfig),
66- throwsA (isA <MindboxException >()));
31+ Mindbox .instance.init (configuration: validConfig);
6732 });
6833
6934 test ('When SDK was initialized, getDeviceUUID() should return device uuid' ,
@@ -78,9 +43,8 @@ void main() {
7843 endpointAndroid: 'endpointAndroid' ,
7944 subscribeCustomerIfCreated: true );
8045
81- await Mindbox .instance.init (configuration: validConfig);
46+ Mindbox .instance.init (configuration: validConfig);
8247
83- expect (completer.isCompleted, isTrue);
8448 expect (await completer.future, equals ('dummy-device-uuid' ));
8549 });
8650
@@ -105,9 +69,8 @@ void main() {
10569 endpointAndroid: 'endpointAndroid' ,
10670 subscribeCustomerIfCreated: true );
10771
108- await Mindbox .instance.init (configuration: validConfig);
72+ Mindbox .instance.init (configuration: validConfig);
10973
110- expect (completer.isCompleted, isTrue);
11174 expect (await completer.future, equals ('dummy-token' ));
11275 });
11376
@@ -126,7 +89,6 @@ void main() {
12689
12790 Mindbox .instance.onPushClickReceived ((url) => completer.complete (url));
12891
129- expect (completer.isCompleted, isTrue);
13092 expect (await completer.future, equals ('dummy-url' ));
13193 });
13294}
0 commit comments