70 lines
1.8 KiB
Dart
70 lines
1.8 KiB
Dart
import 'package:ai_contract_mobile/features/auth/application/auth_controller.dart';
|
||
import 'package:ai_contract_mobile/features/auth/domain/auth_session.dart';
|
||
import 'package:ai_contract_mobile/shared/network/api_client.dart';
|
||
import 'package:ai_contract_mobile/shared/storage/session_store.dart';
|
||
import 'package:flutter_test/flutter_test.dart';
|
||
|
||
void main() {
|
||
TestWidgetsFlutterBinding.ensureInitialized();
|
||
|
||
setUp(() {
|
||
SessionStore.useStorageDriverForTesting(InMemorySessionStorageDriver());
|
||
});
|
||
|
||
tearDown(() async {
|
||
await SessionStore.clear();
|
||
SessionStore.resetStorageDriverForTesting();
|
||
});
|
||
|
||
test('normalizes full-width email punctuation before login request',
|
||
() async {
|
||
final apiClient = _CapturingLoginApiClient();
|
||
final controller = AuthController(apiClient: apiClient);
|
||
|
||
await controller.login(
|
||
account: ' cyuqei@gmail。com ',
|
||
password: '816301',
|
||
);
|
||
|
||
expect(apiClient.account, 'cyuqei@gmail.com');
|
||
expect(apiClient.password, '816301');
|
||
expect(SessionStore.current?.username, 'cyuqei@gmail.com');
|
||
});
|
||
}
|
||
|
||
class _CapturingLoginApiClient extends ApiClient {
|
||
String? account;
|
||
String? password;
|
||
|
||
@override
|
||
Future<AuthSession> login({
|
||
required String account,
|
||
required String password,
|
||
}) async {
|
||
this.account = account;
|
||
this.password = password;
|
||
return AuthSession(
|
||
accessToken: 'token',
|
||
userId: 'user-1',
|
||
tenantId: 'tenant-1',
|
||
username: account,
|
||
userDisplayName: 'Member',
|
||
role: 'member',
|
||
status: 'active',
|
||
);
|
||
}
|
||
|
||
@override
|
||
Future<AuthSession> fetchCurrentUser(String accessToken) async {
|
||
return const AuthSession(
|
||
accessToken: 'token',
|
||
userId: 'user-1',
|
||
tenantId: 'tenant-1',
|
||
username: 'cyuqei@gmail.com',
|
||
userDisplayName: 'Member',
|
||
role: 'member',
|
||
status: 'active',
|
||
);
|
||
}
|
||
}
|