|
1 | | -import 'dart:math'; |
2 | | - |
3 | | -import 'package:courier_flutter/platform_interfaces/courier_flutter_events_platform_interface.dart'; |
4 | | -import 'package:courier_flutter/courier_provider.dart'; |
5 | | -import 'package:courier_flutter/ios_foreground_notification_presentation_options.dart'; |
6 | | -import 'package:courier_flutter/notification_permission_status.dart'; |
7 | | -import 'package:flutter_test/flutter_test.dart'; |
8 | | -import 'package:courier_flutter/courier_flutter.dart'; |
9 | | -import 'package:courier_flutter/platform_interfaces/courier_flutter_core_platform_interface.dart'; |
10 | | -import 'package:plugin_platform_interface/plugin_platform_interface.dart'; |
11 | | - |
12 | | -class MockCourierFlutterCorePlatform |
13 | | - with MockPlatformInterfaceMixin |
14 | | - implements CourierFlutterCorePlatform { |
15 | | - String? _userId; |
16 | | - String? _accessToken; |
17 | | - String? _apnsToken; |
18 | | - String? _fcmToken; |
19 | | - final bool _isDebugging = false; |
20 | | - |
21 | | - @override |
22 | | - Future<bool> isDebugging(bool isDebugging) { |
23 | | - return Future.value(_isDebugging); |
24 | | - } |
25 | | - |
26 | | - @override |
27 | | - Future<String?> userId() { |
28 | | - return Future.value(_userId); |
29 | | - } |
30 | | - |
31 | | - @override |
32 | | - Future signIn(String accessToken, String userId) { |
33 | | - _userId = userId; |
34 | | - _accessToken = accessToken; |
35 | | - return Future.value(); |
36 | | - } |
37 | | - |
38 | | - @override |
39 | | - Future signOut() { |
40 | | - _userId = null; |
41 | | - _accessToken = null; |
42 | | - return Future.value(); |
43 | | - } |
44 | | - |
45 | | - @override |
46 | | - Future<String?> apnsToken() { |
47 | | - return Future.value(_apnsToken); |
48 | | - } |
49 | | - |
50 | | - @override |
51 | | - Future<String?> fcmToken() { |
52 | | - return Future.value(_fcmToken); |
53 | | - } |
54 | | - |
55 | | - @override |
56 | | - Future setFcmToken(String token) { |
57 | | - if (_userId == null) { |
58 | | - print('No user set'); |
59 | | - return Future.value(); |
60 | | - } |
61 | | - |
62 | | - _fcmToken = token; |
63 | | - return Future.value(); |
64 | | - } |
65 | | - |
66 | | - @override |
67 | | - Future<String> sendPush(String authKey, String userId, String title, |
68 | | - String body, List<CourierPushProvider> providers) { |
69 | | - throw Future.value('asdf'); |
70 | | - } |
71 | | -} |
72 | | - |
73 | | -class MockCourierFlutterEventsPlatform |
74 | | - with MockPlatformInterfaceMixin |
75 | | - implements CourierFlutterEventsPlatform { |
76 | | - @override |
77 | | - Future iOSForegroundPresentationOptions( |
78 | | - List<iOSNotificationPresentationOption> options) { |
79 | | - return Future.value(); |
80 | | - } |
81 | | - |
82 | | - @override |
83 | | - registerMessagingListeners( |
84 | | - {required Function(dynamic message) onPushNotificationDelivered, |
85 | | - required Function(dynamic message) onPushNotificationClicked, |
86 | | - required Function(dynamic log) onLogPosted}) { |
87 | | - return; |
88 | | - } |
89 | | - |
90 | | - @override |
91 | | - Future<String> getNotificationPermissionStatus() { |
92 | | - const permissions = NotificationPermissionStatus.values; |
93 | | - final randomPermission = |
94 | | - permissions.elementAt(Random().nextInt(permissions.length)); |
95 | | - return Future.value(randomPermission.value); |
96 | | - } |
97 | | - |
98 | | - @override |
99 | | - Future<String> requestNotificationPermission() { |
100 | | - const permissions = NotificationPermissionStatus.values; |
101 | | - final randomPermission = |
102 | | - permissions.elementAt(Random().nextInt(permissions.length)); |
103 | | - return Future.value(randomPermission.value); |
104 | | - } |
105 | | - |
106 | | - @override |
107 | | - Future getClickedNotification() { |
108 | | - return Future.value(); |
109 | | - } |
110 | | -} |
111 | | - |
112 | | -void main() { |
113 | | - const exampleUserId = 'example_user_id'; |
114 | | - const exampleAccessToken = 'example_access_token'; |
115 | | - const exampleFcmToken = 'asdfasdf'; |
116 | | - |
117 | | - setUpAll(() { |
118 | | - CourierFlutterCorePlatform.instance = MockCourierFlutterCorePlatform(); |
119 | | - CourierFlutterEventsPlatform.instance = MockCourierFlutterEventsPlatform(); |
120 | | - }); |
121 | | - |
122 | | - test('setFcmToken Failure', () async { |
123 | | - await Courier.shared.setFcmToken(token: exampleFcmToken); |
124 | | - final token = await Courier.shared.fcmToken; |
125 | | - expect(token, null); |
126 | | - }); |
127 | | - |
128 | | - test('signIn', () async { |
129 | | - await Courier.shared.signIn( |
130 | | - accessToken: exampleAccessToken, |
131 | | - userId: exampleUserId, |
132 | | - ); |
133 | | - final userId = await Courier.shared.userId; |
134 | | - expect(userId, userId); |
135 | | - }); |
136 | | - |
137 | | - test('setFcmToken Success', () async { |
138 | | - await Courier.shared.setFcmToken(token: exampleFcmToken); |
139 | | - final storedToken = await Courier.shared.fcmToken; |
140 | | - expect(exampleFcmToken, storedToken); |
141 | | - }); |
142 | | - |
143 | | - test('getApnsToken', () async { |
144 | | - final token = await Courier.shared.apnsToken; |
145 | | - expect(token, null); |
146 | | - }); |
147 | | - |
148 | | - test('getFcmToken', () async { |
149 | | - final token = await Courier.shared.fcmToken; |
150 | | - expect(token, exampleFcmToken); |
151 | | - }); |
152 | | - |
153 | | - test('signOut', () async { |
154 | | - await Courier.shared.signOut(); |
155 | | - final userId = await Courier.shared.userId; |
156 | | - final fcmToken = await Courier.shared.fcmToken; |
157 | | - final apnsToken = await Courier.shared.apnsToken; |
158 | | - expect(userId, null); |
159 | | - expect(fcmToken, fcmToken); |
160 | | - expect(apnsToken, null); |
161 | | - }); |
162 | | -} |
| 1 | +// import 'dart:math'; |
| 2 | +// |
| 3 | +// import 'package:courier_flutter/platform_interfaces/courier_flutter_events_platform_interface.dart'; |
| 4 | +// import 'package:courier_flutter/courier_provider.dart'; |
| 5 | +// import 'package:courier_flutter/ios_foreground_notification_presentation_options.dart'; |
| 6 | +// import 'package:courier_flutter/notification_permission_status.dart'; |
| 7 | +// import 'package:flutter_test/flutter_test.dart'; |
| 8 | +// import 'package:courier_flutter/courier_flutter.dart'; |
| 9 | +// import 'package:courier_flutter/platform_interfaces/courier_flutter_core_platform_interface.dart'; |
| 10 | +// import 'package:plugin_platform_interface/plugin_platform_interface.dart'; |
| 11 | +// |
| 12 | +// class MockCourierFlutterCorePlatform |
| 13 | +// with MockPlatformInterfaceMixin |
| 14 | +// implements CourierFlutterCorePlatform { |
| 15 | +// String? _userId; |
| 16 | +// String? _accessToken; |
| 17 | +// String? _apnsToken; |
| 18 | +// String? _fcmToken; |
| 19 | +// final bool _isDebugging = false; |
| 20 | +// |
| 21 | +// @override |
| 22 | +// Future<bool> isDebugging(bool isDebugging) { |
| 23 | +// return Future.value(_isDebugging); |
| 24 | +// } |
| 25 | +// |
| 26 | +// @override |
| 27 | +// Future<String?> userId() { |
| 28 | +// return Future.value(_userId); |
| 29 | +// } |
| 30 | +// |
| 31 | +// @override |
| 32 | +// Future signIn(String accessToken, String userId) { |
| 33 | +// _userId = userId; |
| 34 | +// _accessToken = accessToken; |
| 35 | +// return Future.value(); |
| 36 | +// } |
| 37 | +// |
| 38 | +// @override |
| 39 | +// Future signOut() { |
| 40 | +// _userId = null; |
| 41 | +// _accessToken = null; |
| 42 | +// return Future.value(); |
| 43 | +// } |
| 44 | +// |
| 45 | +// @override |
| 46 | +// Future<String?> apnsToken() { |
| 47 | +// return Future.value(_apnsToken); |
| 48 | +// } |
| 49 | +// |
| 50 | +// @override |
| 51 | +// Future<String?> fcmToken() { |
| 52 | +// return Future.value(_fcmToken); |
| 53 | +// } |
| 54 | +// |
| 55 | +// @override |
| 56 | +// Future setFcmToken(String token) { |
| 57 | +// if (_userId == null) { |
| 58 | +// print('No user set'); |
| 59 | +// return Future.value(); |
| 60 | +// } |
| 61 | +// |
| 62 | +// _fcmToken = token; |
| 63 | +// return Future.value(); |
| 64 | +// } |
| 65 | +// |
| 66 | +// @override |
| 67 | +// Future<String> sendPush(String authKey, String userId, String title, |
| 68 | +// String body, List<CourierPushProvider> providers) { |
| 69 | +// throw Future.value('asdf'); |
| 70 | +// } |
| 71 | +// } |
| 72 | +// |
| 73 | +// class MockCourierFlutterEventsPlatform |
| 74 | +// with MockPlatformInterfaceMixin |
| 75 | +// implements CourierFlutterEventsPlatform { |
| 76 | +// @override |
| 77 | +// Future iOSForegroundPresentationOptions( |
| 78 | +// List<iOSNotificationPresentationOption> options) { |
| 79 | +// return Future.value(); |
| 80 | +// } |
| 81 | +// |
| 82 | +// @override |
| 83 | +// registerMessagingListeners( |
| 84 | +// {required Function(dynamic message) onPushNotificationDelivered, |
| 85 | +// required Function(dynamic message) onPushNotificationClicked, |
| 86 | +// required Function(dynamic log) onLogPosted}) { |
| 87 | +// return; |
| 88 | +// } |
| 89 | +// |
| 90 | +// @override |
| 91 | +// Future<String> getNotificationPermissionStatus() { |
| 92 | +// const permissions = NotificationPermissionStatus.values; |
| 93 | +// final randomPermission = |
| 94 | +// permissions.elementAt(Random().nextInt(permissions.length)); |
| 95 | +// return Future.value(randomPermission.value); |
| 96 | +// } |
| 97 | +// |
| 98 | +// @override |
| 99 | +// Future<String> requestNotificationPermission() { |
| 100 | +// const permissions = NotificationPermissionStatus.values; |
| 101 | +// final randomPermission = |
| 102 | +// permissions.elementAt(Random().nextInt(permissions.length)); |
| 103 | +// return Future.value(randomPermission.value); |
| 104 | +// } |
| 105 | +// |
| 106 | +// @override |
| 107 | +// Future getClickedNotification() { |
| 108 | +// return Future.value(); |
| 109 | +// } |
| 110 | +// } |
| 111 | +// |
| 112 | +// void main() { |
| 113 | +// const exampleUserId = 'example_user_id'; |
| 114 | +// const exampleAccessToken = 'example_access_token'; |
| 115 | +// const exampleFcmToken = 'asdfasdf'; |
| 116 | +// |
| 117 | +// setUpAll(() { |
| 118 | +// CourierFlutterCorePlatform.instance = MockCourierFlutterCorePlatform(); |
| 119 | +// CourierFlutterEventsPlatform.instance = MockCourierFlutterEventsPlatform(); |
| 120 | +// }); |
| 121 | +// |
| 122 | +// test('setFcmToken Failure', () async { |
| 123 | +// await Courier.shared.setFcmToken(token: exampleFcmToken); |
| 124 | +// final token = await Courier.shared.fcmToken; |
| 125 | +// expect(token, null); |
| 126 | +// }); |
| 127 | +// |
| 128 | +// test('signIn', () async { |
| 129 | +// await Courier.shared.signIn( |
| 130 | +// accessToken: exampleAccessToken, |
| 131 | +// userId: exampleUserId, |
| 132 | +// ); |
| 133 | +// final userId = await Courier.shared.userId; |
| 134 | +// expect(userId, userId); |
| 135 | +// }); |
| 136 | +// |
| 137 | +// test('setFcmToken Success', () async { |
| 138 | +// await Courier.shared.setFcmToken(token: exampleFcmToken); |
| 139 | +// final storedToken = await Courier.shared.fcmToken; |
| 140 | +// expect(exampleFcmToken, storedToken); |
| 141 | +// }); |
| 142 | +// |
| 143 | +// test('getApnsToken', () async { |
| 144 | +// final token = await Courier.shared.apnsToken; |
| 145 | +// expect(token, null); |
| 146 | +// }); |
| 147 | +// |
| 148 | +// test('getFcmToken', () async { |
| 149 | +// final token = await Courier.shared.fcmToken; |
| 150 | +// expect(token, exampleFcmToken); |
| 151 | +// }); |
| 152 | +// |
| 153 | +// test('signOut', () async { |
| 154 | +// await Courier.shared.signOut(); |
| 155 | +// final userId = await Courier.shared.userId; |
| 156 | +// final fcmToken = await Courier.shared.fcmToken; |
| 157 | +// final apnsToken = await Courier.shared.apnsToken; |
| 158 | +// expect(userId, null); |
| 159 | +// expect(fcmToken, fcmToken); |
| 160 | +// expect(apnsToken, null); |
| 161 | +// }); |
| 162 | +// } |
0 commit comments