46 lines
1.4 KiB
Dart
46 lines
1.4 KiB
Dart
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:tdc114plus/src/features/auth/data/auth_session_store.dart';
|
|
import 'package:tdc114plus/src/features/auth/domain/auth_models.dart';
|
|
|
|
void main() {
|
|
setUp(() {
|
|
SharedPreferences.setMockInitialValues({});
|
|
});
|
|
|
|
test('saves loads and clears login session', () async {
|
|
const store = AuthSessionStore();
|
|
final response = PhoneLoginResponse(
|
|
status: 'ok',
|
|
token: 'session-token',
|
|
expiresAt: DateTime.parse('2026-07-02T12:00:00Z'),
|
|
user: const LoginUser(
|
|
id: 'user-uuid',
|
|
name: 'User One',
|
|
phoneNumber: '+821012345678',
|
|
tenantId: 'tenant-uuid',
|
|
tenantName: 'Hanmac',
|
|
tenantSlug: 'hanmac',
|
|
),
|
|
orgContextCredential: OrgContextCredential(
|
|
baseUrl: 'https://sadmin.hmac.kr',
|
|
tenantSlug: 'hanmac-family',
|
|
keyId: 'session-key-id',
|
|
keySecret: 'session-key-secret',
|
|
expiresAt: DateTime.parse('2099-07-02T13:00:00Z'),
|
|
),
|
|
);
|
|
|
|
await store.save(response);
|
|
final loaded = await store.load();
|
|
|
|
expect(loaded?.token, 'session-token');
|
|
expect(loaded?.user.name, 'User One');
|
|
expect(loaded?.orgContextCredential?.keyId, 'session-key-id');
|
|
expect(loaded?.orgContextCredential?.keySecret, 'session-key-secret');
|
|
|
|
await store.clear();
|
|
expect(await store.load(), isNull);
|
|
});
|
|
}
|