Skip to content

Commit 9b26feb

Browse files
authored
PSG-5785: TokenStore class updates (#92)
* tests are updated for token store * inline docs updated
1 parent 6f00c04 commit 9b26feb

File tree

5 files changed

+51
-19
lines changed

5 files changed

+51
-19
lines changed

integrationtestapp/integration_test/helper/integration_test_config.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import 'package:passage_flutter/passage_flutter_models/passage_user.dart';
33
class IntegrationTestConfig {
44
static const String apiBaseUrl = "https://auth-uat.passage.dev/v1";
55
static const String appIdOtp = "Ezbk6fSdx9pNQ7v7UbVEnzeC";
6-
static const String appIdPassage = "passage";
6+
static const String appIdPassage = "passage";
77
static const String appIdMagicLink = "Pea2GdtBHN3esylK4ZRlF19U";
88
static const int waitTimeMilliseconds = 8000;
99
static const String existingUserEmailOtp =

integrationtestapp/integration_test/helper/mailosaur_api_client.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ class GetMessageResponse {
121121
class MailosaurAPIClient {
122122
static const String serverId = 'ncor7c1m';
123123
static const String apiURL = 'https://mailosaur.com/api/messages';
124-
static const String mailosaurAPIKey = "YOUR_MAILOSAUR_API_KEY";
124+
static const String mailosaurAPIKey = "MAILOSAUR_API_KEY";
125125

126126
static String appUrl(String path) {
127127
if (kIsWeb) {

integrationtestapp/integration_test/token_store_test.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,5 +80,35 @@ void main() {
8080
//success
8181
}
8282
});
83+
test('isAuthTokenValid_returnsTrueForValidToken', () async {
84+
await loginWithMagicLink();
85+
final validToken = await passage.tokenStore.getValidAuthToken();
86+
final isValid = await passage.tokenStore.isAuthTokenValid(validToken);
87+
expect(isValid, isTrue);
88+
});
89+
90+
test('isAuthTokenValid_returnsFalseForInvalidToken', () async {
91+
const invalidToken = 'invalidToken';
92+
final isValid = await passage.tokenStore.isAuthTokenValid(invalidToken);
93+
expect(isValid, isFalse);
94+
});
95+
96+
test('refreshAuthToken_returnsNewAuthToken', () async {
97+
await loginWithMagicLink();
98+
final authResult = await passage.tokenStore.refreshAuthToken();
99+
expect(authResult, isNotNull);
100+
expect(authResult.authToken, isNotNull);
101+
expect(authResult.refreshToken, isNotNull);
102+
});
103+
104+
test('refreshAuthToken_throwsPassageError', () async {
105+
try {
106+
final authResult = await passage.tokenStore.refreshAuthToken();
107+
fail('Expected PassageError but got success');
108+
} catch (e) {
109+
// success
110+
}
111+
});
112+
83113
});
84114
}

integrationtestapp/pubspec.lock

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -323,18 +323,18 @@ packages:
323323
dependency: transitive
324324
description:
325325
name: leak_tracker
326-
sha256: "7f0df31977cb2c0b88585095d168e689669a2cc9b97c309665e3386f3e9d341a"
326+
sha256: "3f87a60e8c63aecc975dda1ceedbc8f24de75f09e4856ea27daf8958f2f0ce05"
327327
url: "https://pub.dev"
328328
source: hosted
329-
version: "10.0.4"
329+
version: "10.0.5"
330330
leak_tracker_flutter_testing:
331331
dependency: transitive
332332
description:
333333
name: leak_tracker_flutter_testing
334-
sha256: "06e98f569d004c1315b991ded39924b21af84cf14cc94791b8aea337d25b57f8"
334+
sha256: "932549fb305594d82d7183ecd9fa93463e9914e1b67cacc34bc40906594a1806"
335335
url: "https://pub.dev"
336336
source: hosted
337-
version: "3.0.3"
337+
version: "3.0.5"
338338
leak_tracker_testing:
339339
dependency: transitive
340340
description:
@@ -371,18 +371,18 @@ packages:
371371
dependency: transitive
372372
description:
373373
name: material_color_utilities
374-
sha256: "0e0a020085b65b6083975e499759762399b4475f766c21668c4ecca34ea74e5a"
374+
sha256: f7142bb1154231d7ea5f96bc7bde4bda2a0945d2806bb11670e30b850d56bdec
375375
url: "https://pub.dev"
376376
source: hosted
377-
version: "0.8.0"
377+
version: "0.11.1"
378378
meta:
379379
dependency: transitive
380380
description:
381381
name: meta
382-
sha256: "7687075e408b093f36e6bbf6c91878cc0d4cd10f409506f7bc996f68220b9136"
382+
sha256: bdb68674043280c3428e9ec998512fb681678676b3c54e773629ffe74419f8c7
383383
url: "https://pub.dev"
384384
source: hosted
385-
version: "1.12.0"
385+
version: "1.15.0"
386386
mime:
387387
dependency: transitive
388388
description:
@@ -405,7 +405,7 @@ packages:
405405
path: ".."
406406
relative: true
407407
source: path
408-
version: "1.0.0"
408+
version: "1.1.0"
409409
path:
410410
dependency: transitive
411411
description:
@@ -418,10 +418,10 @@ packages:
418418
dependency: transitive
419419
description:
420420
name: platform
421-
sha256: "12220bb4b65720483f8fa9450b4332347737cf8213dd2840d8b2c823e47243ec"
421+
sha256: "9b71283fc13df574056616011fb138fd3b793ea47cc509c189a6c3fa5f8a1a65"
422422
url: "https://pub.dev"
423423
source: hosted
424-
version: "3.1.4"
424+
version: "3.1.5"
425425
plugin_platform_interface:
426426
dependency: transitive
427427
description:
@@ -559,10 +559,10 @@ packages:
559559
dependency: transitive
560560
description:
561561
name: test_api
562-
sha256: "9955ae474176f7ac8ee4e989dadfb411a58c30415bcfb648fa04b2b8a03afa7f"
562+
sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb"
563563
url: "https://pub.dev"
564564
source: hosted
565-
version: "0.7.0"
565+
version: "0.7.2"
566566
timing:
567567
dependency: transitive
568568
description:
@@ -591,10 +591,10 @@ packages:
591591
dependency: transitive
592592
description:
593593
name: vm_service
594-
sha256: "3923c89304b715fb1eb6423f017651664a03bf5f4b29983627c4da791f74a4ec"
594+
sha256: "5c5f338a667b4c644744b661f309fb8080bb94b18a7e91ef1dbd343bed00ed6d"
595595
url: "https://pub.dev"
596596
source: hosted
597-
version: "14.2.1"
597+
version: "14.2.5"
598598
watcher:
599599
dependency: transitive
600600
description:

lib/passage_token_store.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ import 'passage_flutter_platform/passage_flutter_platform_interface.dart';
55
class PassageTokenStore {
66

77
/// Returns the auth token for the currently authenticated user.
8+
/// If the stored auth token is invalid, this method will use the refresh token to get and save a new auth token.
89
///
910
/// Returns:
10-
/// A `Future<String?>` representing the current Passage user's auth token,
11-
/// or `null` if no token has been stored.
11+
/// A `Future<String?>` representing the user's auth token,
12+
/// Throws:
13+
/// `PassageError`
1214
Future<String> getValidAuthToken() {
1315
return PassageFlutterPlatform.instance.getValidAuthToken();
1416
}

0 commit comments

Comments
 (0)