File tree Expand file tree Collapse file tree 2 files changed +21
-5
lines changed
packages/supabase_flutter/test Expand file tree Collapse file tree 2 files changed +21
-5
lines changed Original file line number Diff line number Diff line change
1
+ import 'package:flutter/services.dart' ;
1
2
import 'package:flutter_test/flutter_test.dart' ;
2
3
import 'package:supabase_flutter/supabase_flutter.dart' ;
3
4
@@ -93,11 +94,12 @@ void main() {
93
94
94
95
group ('Deep Link with PKCE code' , () {
95
96
late final PkceHttpClient pkceHttpClient;
97
+ late final EventChannel appLinksEventChannel;
96
98
setUp (() async {
97
99
pkceHttpClient = PkceHttpClient ();
98
100
99
101
// Add initial deep link with a `code` parameter
100
- mockAppLink (
102
+ appLinksEventChannel = mockAppLink (
101
103
initialLink: 'com.supabase://callback/?code=my-code-verifier' ,
102
104
);
103
105
await Supabase .initialize (
@@ -118,6 +120,9 @@ void main() {
118
120
test (
119
121
'Having `code` as the query parameter triggers `getSessionFromUrl` call on initialize' ,
120
122
() async {
123
+ // Wait for the initial app link to be handled, as this is an async process
124
+ final stream = appLinksEventChannel.receiveBroadcastStream ();
125
+ await stream.first;
121
126
expect (pkceHttpClient.requestCount, 1 );
122
127
expect (pkceHttpClient.lastRequestBody['auth_code' ], 'my-code-verifier' );
123
128
});
Original file line number Diff line number Diff line change @@ -94,10 +94,12 @@ class MockEmptyLocalStorage extends LocalStorage {
94
94
Future <void > removePersistedSession () async {}
95
95
}
96
96
97
- /// Registers the mock handler for uni_links
98
- void mockAppLink ({String ? initialLink}) {
97
+ /// Registers the mock handler for app_links
98
+ ///
99
+ /// Returns the [EventChannel] used to mock the incoming links.
100
+ EventChannel mockAppLink ({String ? initialLink}) {
99
101
const channel = MethodChannel ('com.llfbandit.app_links/messages' );
100
- const anotherChannel = MethodChannel ('com.llfbandit.app_links/events' );
102
+ const eventChannel = EventChannel ('com.llfbandit.app_links/events' );
101
103
102
104
TestWidgetsFlutterBinding .ensureInitialized ();
103
105
@@ -107,7 +109,16 @@ void mockAppLink({String? initialLink}) {
107
109
108
110
// ignore: invalid_null_aware_operator
109
111
TestDefaultBinaryMessengerBinding .instance? .defaultBinaryMessenger
110
- .setMockMethodCallHandler (anotherChannel, (message) async => null );
112
+ .setMockStreamHandler (
113
+ eventChannel,
114
+ MockStreamHandler .inline (
115
+ onListen: (arguments, events) {
116
+ events.success (initialLink);
117
+ },
118
+ ),
119
+ );
120
+
121
+ return eventChannel;
111
122
}
112
123
113
124
class MockAsyncStorage extends GotrueAsyncStorage {
You can’t perform that action at this time.
0 commit comments