feat(apps): add auth data models
This commit is contained in:
@@ -0,0 +1,56 @@
|
|||||||
|
class AuthUser {
|
||||||
|
final String id;
|
||||||
|
final String email;
|
||||||
|
|
||||||
|
const AuthUser({required this.id, required this.email});
|
||||||
|
|
||||||
|
factory AuthUser.fromJson(Map<String, dynamic> json) {
|
||||||
|
return AuthUser(id: json['id'] as String, email: json['email'] as String);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AuthResponse {
|
||||||
|
final String accessToken;
|
||||||
|
final String refreshToken;
|
||||||
|
final int expiresIn;
|
||||||
|
final String tokenType;
|
||||||
|
final AuthUser user;
|
||||||
|
|
||||||
|
const AuthResponse({
|
||||||
|
required this.accessToken,
|
||||||
|
required this.refreshToken,
|
||||||
|
required this.expiresIn,
|
||||||
|
required this.tokenType,
|
||||||
|
required this.user,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory AuthResponse.fromJson(Map<String, dynamic> json) {
|
||||||
|
return AuthResponse(
|
||||||
|
accessToken: json['access_token'] as String,
|
||||||
|
refreshToken: json['refresh_token'] as String,
|
||||||
|
expiresIn: json['expires_in'] as int,
|
||||||
|
tokenType: json['token_type'] as String,
|
||||||
|
user: AuthUser.fromJson(json['user'] as Map<String, dynamic>),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class SignupStartResponse {
|
||||||
|
final String status;
|
||||||
|
final String email;
|
||||||
|
final String message;
|
||||||
|
|
||||||
|
const SignupStartResponse({
|
||||||
|
required this.status,
|
||||||
|
required this.email,
|
||||||
|
required this.message,
|
||||||
|
});
|
||||||
|
|
||||||
|
factory SignupStartResponse.fromJson(Map<String, dynamic> json) {
|
||||||
|
return SignupStartResponse(
|
||||||
|
status: json['status'] as String,
|
||||||
|
email: json['email'] as String,
|
||||||
|
message: json['message'] as String,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
class LoginRequest {
|
||||||
|
final String email;
|
||||||
|
final String password;
|
||||||
|
|
||||||
|
const LoginRequest({required this.email, required this.password});
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {'email': email, 'password': password};
|
||||||
|
}
|
||||||
|
|
||||||
|
class RefreshRequest {
|
||||||
|
final String refreshToken;
|
||||||
|
|
||||||
|
const RefreshRequest({required this.refreshToken});
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {'refresh_token': refreshToken};
|
||||||
|
}
|
||||||
|
|
||||||
|
class LogoutRequest {
|
||||||
|
final String refreshToken;
|
||||||
|
|
||||||
|
const LogoutRequest({required this.refreshToken});
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {'refresh_token': refreshToken};
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
class SignupStartRequest {
|
||||||
|
final String username;
|
||||||
|
final String email;
|
||||||
|
final String password;
|
||||||
|
|
||||||
|
const SignupStartRequest({
|
||||||
|
required this.username,
|
||||||
|
required this.email,
|
||||||
|
required this.password,
|
||||||
|
});
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {
|
||||||
|
'username': username,
|
||||||
|
'email': email,
|
||||||
|
'password': password,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
class SignupVerifyRequest {
|
||||||
|
final String email;
|
||||||
|
final String token;
|
||||||
|
|
||||||
|
const SignupVerifyRequest({required this.email, required this.token});
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {'email': email, 'token': token};
|
||||||
|
}
|
||||||
|
|
||||||
|
class SignupResendRequest {
|
||||||
|
final String email;
|
||||||
|
|
||||||
|
const SignupResendRequest({required this.email});
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {'email': email};
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
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('SignupStartRequest', () {
|
||||||
|
test('serializes to JSON', () {
|
||||||
|
final request = SignupStartRequest(
|
||||||
|
username: 'testuser',
|
||||||
|
email: 'test@example.com',
|
||||||
|
password: 'password123',
|
||||||
|
);
|
||||||
|
|
||||||
|
final json = request.toJson();
|
||||||
|
|
||||||
|
expect(json['username'], 'testuser');
|
||||||
|
expect(json['email'], 'test@example.com');
|
||||||
|
expect(json['password'], 'password123');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
group('LoginRequest', () {
|
||||||
|
test('serializes to JSON', () {
|
||||||
|
final request = LoginRequest(
|
||||||
|
email: 'test@example.com',
|
||||||
|
password: 'password123',
|
||||||
|
);
|
||||||
|
|
||||||
|
final json = request.toJson();
|
||||||
|
|
||||||
|
expect(json['email'], 'test@example.com');
|
||||||
|
expect(json['password'], 'password123');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
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', 'email': 'test@example.com'},
|
||||||
|
};
|
||||||
|
|
||||||
|
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.email, 'test@example.com');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user