1
1
import 'package:flutter_test/flutter_test.dart' ;
2
2
import 'package:passage_flutter/passage_flutter.dart' ;
3
+ import 'package:passage_flutter/passage_flutter_models/meta_data.dart' ;
4
+ import 'package:passage_flutter/passage_flutter_models/passage_social_connection.dart' ;
5
+ import 'package:passage_flutter/passage_flutter_models/passage_user_social_connections.dart' ;
6
+ import 'package:passage_flutter/passage_flutter_models/passkey.dart' ;
3
7
import 'helper/integration_test_config.dart' ;
4
8
import 'helper/mailosaur_api_client.dart' ;
5
9
import 'package:flutter/foundation.dart' ;
@@ -10,16 +14,15 @@ void main() {
10
14
IntegrationTestWidgetsFlutterBinding .ensureInitialized ();
11
15
PassageFlutter passage = PassageFlutter (IntegrationTestConfig .appIdMagicLink);
12
16
13
- setUp (() async {
17
+ setUpAll (() async {
14
18
if (! kIsWeb) {
15
19
String basePath = IntegrationTestConfig .apiBaseUrl;
16
- await passage.overrideBasePath (basePath);
17
20
}
18
21
});
19
22
20
23
tearDown (() async {
21
24
try {
22
- await passage.signOut ();
25
+ await passage.currentUser. logout ();
23
26
} catch (e) {
24
27
// an error happened during sign out
25
28
}
@@ -28,14 +31,15 @@ void main() {
28
31
Future <void > loginWithMagicLink () async {
29
32
try {
30
33
await passage
31
- .newLoginMagicLink (IntegrationTestConfig .existingUserEmailMagicLink);
32
- await Future .delayed (const Duration (
33
- milliseconds: IntegrationTestConfig .waitTimeMilliseconds));
34
+ .magliclink
35
+ .login (IntegrationTestConfig .existingUserEmailMagicLink);
36
+ await Future .delayed (
37
+ const Duration (milliseconds: IntegrationTestConfig .waitTimeMilliseconds));
34
38
final magicLinkStr = await MailosaurAPIClient .getMostRecentMagicLink ();
35
39
if (magicLinkStr.isEmpty) {
36
40
fail ('Test failed: Magic link is empty' );
37
41
}
38
- await passage.magicLinkActivate (magicLinkStr);
42
+ await passage.magliclink. activate (magicLinkStr);
39
43
} catch (e) {
40
44
fail ('Expected to activate login magic link, but got an exception: $e ' );
41
45
}
@@ -45,15 +49,15 @@ void main() {
45
49
test ('testCurrentUser' , () async {
46
50
try {
47
51
await loginWithMagicLink ();
48
- final response = await passage.getCurrentUser ();
52
+ final response = await passage.currentUser. userInfo ();
49
53
expect (response? .id, IntegrationTestConfig .currentUser.id);
50
54
expect (response? .email, IntegrationTestConfig .currentUser.email);
51
55
expect (response? .status, IntegrationTestConfig .currentUser.status);
52
- expect (response ? .emailVerified,
53
- IntegrationTestConfig .currentUser.emailVerified);
56
+ expect (
57
+ response ? .emailVerified, IntegrationTestConfig .currentUser.emailVerified);
54
58
expect (response? .phone, IntegrationTestConfig .currentUser.phone);
55
- expect (response ? .phoneVerified,
56
- IntegrationTestConfig .currentUser.phoneVerified);
59
+ expect (
60
+ response ? .phoneVerified, IntegrationTestConfig .currentUser.phoneVerified);
57
61
expect (response? .webauthn, IntegrationTestConfig .currentUser.webauthn);
58
62
} catch (e) {
59
63
fail ('Test failed due to unexpected exception: $e ' );
@@ -62,13 +66,70 @@ void main() {
62
66
63
67
test ('testCurrentUserNotAuthorized' , () async {
64
68
try {
65
- final response = await passage.getCurrentUser ();
66
- if (response == null ) {
67
- expect (true , true );
68
- } else {
69
- fail ('Test failed: response must be null' );
70
- }
69
+ final response = await passage.currentUser.userInfo ();
70
+ fail ('Test failed: must throw an error' );
71
71
} catch (e) {
72
+ //success
73
+ }
74
+ });
75
+
76
+ test ('testPasskeys' , () async {
77
+ try {
78
+ await loginWithMagicLink ();
79
+ final passkeys = await passage.currentUser.passkeys ();
80
+ expect (passkeys, isNotNull);
81
+ expect (passkeys, isA <List <Passkey >>());
82
+ } catch (e) {
83
+ fail ('Test failed due to unexpected exception: $e ' );
84
+ }
85
+ });
86
+
87
+ test ('testSocialConnections' , () async {
88
+ try {
89
+ await loginWithMagicLink ();
90
+ final socialConnections = await passage.currentUser.socialConnections ();
91
+ expect (socialConnections, isNotNull);
92
+ expect (socialConnections, isA <UserSocialConnections >());
93
+ } catch (e) {
94
+ fail ('Test failed due to unexpected exception: $e ' );
95
+ }
96
+ });
97
+
98
+ test ('testDeleteSocialConnection' , () async {
99
+ try {
100
+ await loginWithMagicLink ();
101
+
102
+ final socialConnectionType = SocialConnection .github;
103
+ await passage.currentUser.deleteSocialConnection (socialConnectionType);
104
+ final socialConnections = await passage.currentUser.socialConnections ();
105
+ expect (socialConnections, isNotNull);
106
+ } catch (e) {
107
+ fail ('Test failed due to unexpected exception: $e ' );
108
+ }
109
+ });
110
+
111
+ test ('testMetadata' , () async {
112
+ try {
113
+ await loginWithMagicLink ();
114
+ final metadata = await passage.currentUser.metadata ();
115
+ expect (metadata, isNotNull);
116
+ expect (metadata, isA <Metadata >());
117
+ } catch (e) {
118
+ print (e.toString ());
119
+ fail ('Test failed due to unexpected exception: $e ' );
120
+ }
121
+ });
122
+
123
+ test ('testUpdateMetadata' , () async {
124
+ try {
125
+ await loginWithMagicLink ();
126
+
127
+ Metadata newMetadata = Metadata (userMetadata: {'testkey' : 'testValue' });
128
+ await passage.currentUser.updateMetadata (newMetadata);
129
+ final updatedMetadata = await passage.currentUser.metadata ();
130
+ expect (updatedMetadata, isNotNull);
131
+ } catch (e) {
132
+ print (e.toString ());
72
133
fail ('Test failed due to unexpected exception: $e ' );
73
134
}
74
135
});
0 commit comments