feat(apps): add core API infrastructure

This commit is contained in:
qzl
2026-02-25 14:36:03 +08:00
parent 53c72e48e6
commit 75f4d2c3fb
6 changed files with 236 additions and 0 deletions
@@ -0,0 +1,44 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:social_app/core/storage/token_storage.dart';
class MockTokenStorage extends Mock implements TokenStorage {}
void main() {
late TokenStorage storage;
setUp(() {
storage = MockTokenStorage();
});
group('TokenStorage', () {
test('saves and retrieves access token', () async {
when(
() => storage.getAccessToken(),
).thenAnswer((_) async => 'test_access');
when(
() =>
storage.saveTokens(access: 'test_access', refresh: 'test_refresh'),
).thenAnswer((_) async {});
await storage.saveTokens(access: 'test_access', refresh: 'test_refresh');
final token = await storage.getAccessToken();
expect(token, 'test_access');
verify(
() =>
storage.saveTokens(access: 'test_access', refresh: 'test_refresh'),
).called(1);
});
test('clear removes all tokens', () async {
when(() => storage.clear()).thenAnswer((_) async {});
when(() => storage.getAccessToken()).thenAnswer((_) async => null);
await storage.clear();
final token = await storage.getAccessToken();
expect(token, isNull);
});
});
}