Files
social-app/apps/test/features/auth/data/models/auth_models_test.dart
T
qzl 0661016827 feat(auth): transition from email to phone-based OTP authentication
- Replace Email+Password login with Phone+OTP flow
- Remove RegisterCubit and registration screens (email verification)
- Remove ResetPasswordCubit and reset password screens
- Add phone normalization and international dial code support
- Update LoginCubit with sendCode/resend cooldown logic
- Add new widgets: phone prefix selector, confirm sheet
- Update all auth API endpoints: /otp/send, /phone-session
- Update form inputs: Email -> Phone with E.164 validation
- Update tests for new auth flow
2026-03-19 18:42:05 +08:00

56 lines
1.6 KiB
Dart

import 'package:flutter_test/flutter_test.dart';
import 'package:social_app/features/auth/data/models/signup_request.dart';
import 'package:social_app/features/auth/data/models/login_request.dart';
import 'package:social_app/features/auth/data/models/auth_response.dart';
void main() {
group('OtpSendRequest', () {
test('serializes e164 phone to JSON', () {
final request = OtpSendRequest(phone: '+14155552671');
final json = request.toJson();
expect(json['phone'], '+14155552671');
});
test('normalizes 00 prefix to plus', () {
final request = OtpSendRequest(phone: '0014155552671');
final json = request.toJson();
expect(json['phone'], '+14155552671');
});
});
group('LoginRequest', () {
test('serializes e164 to JSON', () {
final request = LoginRequest(phone: '+14155552671', token: '123456');
final json = request.toJson();
expect(json['phone'], '+14155552671');
expect(json['token'], '123456');
});
});
group('AuthResponse', () {
test('parses from JSON', () {
final json = {
'access_token': 'test_access',
'refresh_token': 'test_refresh',
'expires_in': 3600,
'token_type': 'bearer',
'user': {'id': '123', 'phone': '+8613812345678'},
};
final response = AuthResponse.fromJson(json);
expect(response.accessToken, 'test_access');
expect(response.refreshToken, 'test_refresh');
expect(response.expiresIn, 3600);
expect(response.user.id, '123');
expect(response.user.phone, '+8613812345678');
});
});
}