Skip to content

Commit

Permalink
refactor: formatting and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel committed Jul 20, 2024
1 parent 360ef0b commit a2ca7ec
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/fresh/lib/src/fresh.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ mixin FreshMixin<T> {
/// Returns the current token.
Future<T?> get token async {
if (_authenticationStatus != AuthenticationStatus.initial) return _token;
await authenticationStatus.firstWhere((status) => status != AuthenticationStatus.initial);
await authenticationStatus.firstWhere(
(status) => status != AuthenticationStatus.initial,
);
return _token;
}

Expand Down
11 changes: 11 additions & 0 deletions packages/fresh/test/fresh_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ void main() {
final token = await freshController.token;
expect(token, mockToken);
});

test('token waits for storage read to complete.', () async {
final mockToken = MockToken();
when(() => tokenStorage.read()).thenAnswer((_) async {
await Future<void>.delayed(Duration.zero);
return mockToken;
});
final freshController = FreshController<OAuth2Token>(tokenStorage);
final token = await freshController.token;
expect(token, mockToken);
});
});

group('revokeToken', () {
Expand Down

0 comments on commit a2ca7ec

Please sign in to comment.