-
Notifications
You must be signed in to change notification settings - Fork 16
/
ably_flutter_plugin_test.dart
84 lines (70 loc) · 2.33 KB
/
ably_flutter_plugin_test.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import 'package:ably_flutter/ably_flutter.dart';
import 'package:ably_flutter/src/platform/platform_internal.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
final channel =
MethodChannel('io.ably.flutter.plugin', StandardMethodCodec(Codec()));
TestWidgetsFlutterBinding.ensureInitialized();
var counter = 0;
//test constants
const _platformVersion = '42';
const _nativeLibraryVersion = '1.1.0';
setUp(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, (methodCall) async {
switch (methodCall.method) {
case PlatformMethod.resetAblyClients:
return true;
case PlatformMethod.getPlatformVersion:
return _platformVersion;
case PlatformMethod.getVersion:
return _nativeLibraryVersion;
case PlatformMethod.createRest:
case PlatformMethod.createRealtime:
return ++counter;
case PlatformMethod.publish:
case PlatformMethod.connectRealtime:
default:
return null;
}
});
Platform(methodChannel: channel);
});
tearDown(() {
TestDefaultBinaryMessengerBinding.instance.defaultBinaryMessenger
.setMockMethodCallHandler(channel, null);
});
test(PlatformMethod.getPlatformVersion, () async {
expect(await platformVersion(), _platformVersion);
});
test(PlatformMethod.getVersion, () async {
expect(await version(), _nativeLibraryVersion);
});
test(PlatformMethod.createRest, () async {
const host = 'http://rest.ably.io/';
final o = ClientOptions(
restHost: host,
);
final rest = Rest(options: o);
expect(await rest.handle, counter);
expect(rest.options.restHost, host);
});
test('createRestWithToken', () async {
const key = 'TEST-KEY';
final rest = Rest.fromKey(key);
expect(await rest.handle, counter);
expect(rest.options.tokenDetails!.token, key);
});
test('createRestWithKey', () async {
const key = 'TEST:KEY';
final rest = Rest.fromKey(key);
expect(await rest.handle, counter);
expect(rest.options.key, key);
});
test('publishMessage', () async {
final rest = Rest.fromKey('TEST-KEY');
await rest.channels.get('test').publish(name: 'name', data: 'data');
expect(1, 1);
});
}