forked from eatvio/eatvio_app
feat(tests): updated tests coverage to 66.5%
This commit is contained in:
167
test/features/auth/models/oauth_models_test.dart
Normal file
167
test/features/auth/models/oauth_models_test.dart
Normal file
@@ -0,0 +1,167 @@
|
||||
import 'package:eatvio_app/features/auth/models/oauth_verification_confirm_request.dart';
|
||||
import 'package:eatvio_app/features/auth/models/oauth_verification_confirm_response.dart';
|
||||
import 'package:eatvio_app/features/auth/models/oauth_verification_request_response.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('OAuthVerificationRequestResponse', () {
|
||||
test('fromJson parses JSON correctly', () {
|
||||
final json = {'email': 'test@example.com', 'status': 'pending'};
|
||||
|
||||
final response = OAuthVerificationRequestResponse.fromJson(json);
|
||||
|
||||
expect(response.email, 'test@example.com');
|
||||
expect(response.status, 'pending');
|
||||
});
|
||||
|
||||
test('toJson serializes correctly', () {
|
||||
const response = OAuthVerificationRequestResponse(email: 'test@example.com', status: 'pending');
|
||||
|
||||
final json = response.toJson();
|
||||
|
||||
expect(json['email'], 'test@example.com');
|
||||
expect(json['status'], 'pending');
|
||||
});
|
||||
});
|
||||
|
||||
group('OAuthVerificationConfirmRequest', () {
|
||||
test('fromJson parses JSON correctly', () {
|
||||
final json = {
|
||||
'access_token': 'access123',
|
||||
'refresh_token': 'refresh123',
|
||||
'client_id': 'client123',
|
||||
'provider': 'google',
|
||||
'id': 'user123',
|
||||
'email': 'test@example.com',
|
||||
'phone': '+1234567890',
|
||||
'code': 'verification_code',
|
||||
'verification_type': 'email',
|
||||
'first_name': 'John',
|
||||
'last_name': 'Doe',
|
||||
'date_of_birth': '1990-01-01',
|
||||
'gender': 'male',
|
||||
'weight': 75,
|
||||
'height': 180,
|
||||
};
|
||||
|
||||
final request = OAuthVerificationConfirmRequest.fromJson(json);
|
||||
|
||||
expect(request.accessToken, 'access123');
|
||||
expect(request.refreshToken, 'refresh123');
|
||||
expect(request.clientId, 'client123');
|
||||
expect(request.provider, 'google');
|
||||
expect(request.id, 'user123');
|
||||
expect(request.email, 'test@example.com');
|
||||
expect(request.phone, '+1234567890');
|
||||
expect(request.code, 'verification_code');
|
||||
expect(request.verificationType, 'email');
|
||||
expect(request.firstName, 'John');
|
||||
expect(request.lastName, 'Doe');
|
||||
expect(request.dateOfBirth, '1990-01-01');
|
||||
expect(request.gender, 'male');
|
||||
expect(request.weight, 75);
|
||||
expect(request.height, 180);
|
||||
});
|
||||
|
||||
test('fromJson handles optional fields', () {
|
||||
final json = {
|
||||
'access_token': 'access123',
|
||||
'refresh_token': 'refresh123',
|
||||
'client_id': 'client123',
|
||||
'provider': 'google',
|
||||
'id': 'user123',
|
||||
'code': 'verification_code',
|
||||
'verification_type': 'email',
|
||||
'first_name': 'John',
|
||||
'last_name': 'Doe',
|
||||
'date_of_birth': '1990-01-01',
|
||||
'gender': 'male',
|
||||
'weight': 75,
|
||||
'height': 180,
|
||||
};
|
||||
|
||||
final request = OAuthVerificationConfirmRequest.fromJson(json);
|
||||
|
||||
expect(request.email, isNull);
|
||||
expect(request.phone, isNull);
|
||||
});
|
||||
|
||||
test('toJson serializes correctly', () {
|
||||
const request = OAuthVerificationConfirmRequest(
|
||||
accessToken: 'access123',
|
||||
refreshToken: 'refresh123',
|
||||
clientId: 'client123',
|
||||
provider: 'google',
|
||||
id: 'user123',
|
||||
email: 'test@example.com',
|
||||
phone: '+1234567890',
|
||||
code: 'verification_code',
|
||||
verificationType: 'email',
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
dateOfBirth: '1990-01-01',
|
||||
gender: 'male',
|
||||
weight: 75,
|
||||
height: 180,
|
||||
);
|
||||
|
||||
final json = request.toJson();
|
||||
|
||||
expect(json['access_token'], 'access123');
|
||||
expect(json['refresh_token'], 'refresh123');
|
||||
expect(json['client_id'], 'client123');
|
||||
expect(json['provider'], 'google');
|
||||
expect(json['id'], 'user123');
|
||||
expect(json['email'], 'test@example.com');
|
||||
expect(json['phone'], '+1234567890');
|
||||
expect(json['code'], 'verification_code');
|
||||
expect(json['verification_type'], 'email');
|
||||
expect(json['first_name'], 'John');
|
||||
expect(json['last_name'], 'Doe');
|
||||
expect(json['date_of_birth'], '1990-01-01');
|
||||
expect(json['gender'], 'male');
|
||||
expect(json['weight'], 75);
|
||||
expect(json['height'], 180);
|
||||
});
|
||||
});
|
||||
|
||||
group('OAuthVerificationConfirmResponse', () {
|
||||
test('fromJson parses JSON correctly', () {
|
||||
final json = {
|
||||
'success': true,
|
||||
'message': 'Verification successful',
|
||||
'token': 'auth_token_123',
|
||||
'user': {'id': 1, 'name': 'John Doe'},
|
||||
'is_new_user': true,
|
||||
};
|
||||
|
||||
final response = OAuthVerificationConfirmResponse.fromJson(json);
|
||||
|
||||
expect(response.success, isTrue);
|
||||
expect(response.message, 'Verification successful');
|
||||
expect(response.token, 'auth_token_123');
|
||||
expect(response.user['id'], 1);
|
||||
expect(response.user['name'], 'John Doe');
|
||||
expect(response.isNewUser, isTrue);
|
||||
});
|
||||
|
||||
test('toJson serializes correctly', () {
|
||||
const response = OAuthVerificationConfirmResponse(
|
||||
success: true,
|
||||
message: 'Verification successful',
|
||||
token: 'auth_token_123',
|
||||
user: {'id': 1, 'name': 'John Doe'},
|
||||
isNewUser: false,
|
||||
);
|
||||
|
||||
final json = response.toJson();
|
||||
|
||||
expect(json['success'], isTrue);
|
||||
expect(json['message'], 'Verification successful');
|
||||
expect(json['token'], 'auth_token_123');
|
||||
expect(json['user']['id'], 1);
|
||||
expect(json['user']['name'], 'John Doe');
|
||||
expect(json['is_new_user'], isFalse);
|
||||
});
|
||||
});
|
||||
}
|
||||
29
test/features/auth/models/token_model_test.dart
Normal file
29
test/features/auth/models/token_model_test.dart
Normal file
@@ -0,0 +1,29 @@
|
||||
import 'package:eatvio_app/features/auth/models/token_model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('TokenModel', () {
|
||||
test('fromJson parses token correctly', () {
|
||||
final json = {'token': 'test-token-12345'};
|
||||
|
||||
final model = TokenModel.fromJson(json);
|
||||
|
||||
expect(model.token, 'test-token-12345');
|
||||
});
|
||||
|
||||
test('toJson serializes token correctly', () {
|
||||
const model = TokenModel(token: 'test-token-12345');
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json['token'], 'test-token-12345');
|
||||
});
|
||||
|
||||
test('creates instance with token', () {
|
||||
const model = TokenModel(token: 'another-token');
|
||||
|
||||
expect(model.token, 'another-token');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -48,6 +48,56 @@ void main() {
|
||||
expect(model.login, 'test@yandex.ru');
|
||||
expect(model.defaultPhone.number, '+79001234567');
|
||||
});
|
||||
|
||||
test('fromJson handles null sex field', () {
|
||||
final json = {
|
||||
'id': '123',
|
||||
'login': 'test@yandex.ru',
|
||||
'birthday': '1990-01-01',
|
||||
'client_id': 'client-123',
|
||||
'display_name': 'Display Name',
|
||||
'real_name': 'Real Name',
|
||||
'first_name': 'First',
|
||||
'last_name': 'Last',
|
||||
'sex': null,
|
||||
'default_email': 'test@yandex.ru',
|
||||
'default_phone': {
|
||||
'id': 1,
|
||||
'number': '+79001234567',
|
||||
},
|
||||
};
|
||||
|
||||
final model = YandexProfileModel.fromJson(json);
|
||||
|
||||
expect(model.sex, isNull);
|
||||
});
|
||||
|
||||
test('toJson serializes YandexProfileModel correctly', () {
|
||||
final phoneData = YandexPhoneData(id: 1, number: '+79001234567');
|
||||
final model = YandexProfileModel(
|
||||
id: '123',
|
||||
login: 'test@yandex.ru',
|
||||
birthday: '1990-01-01',
|
||||
clientId: 'client-123',
|
||||
displayName: 'Display Name',
|
||||
realName: 'Real Name',
|
||||
firstName: 'First',
|
||||
lastName: 'Last',
|
||||
sex: 'male',
|
||||
defaultEmail: 'test@yandex.ru',
|
||||
defaultPhone: phoneData,
|
||||
);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json['id'], '123');
|
||||
expect(json['login'], 'test@yandex.ru');
|
||||
expect(json['client_id'], 'client-123');
|
||||
expect(json['first_name'], 'First');
|
||||
expect(json['last_name'], 'Last');
|
||||
expect(json['sex'], 'male');
|
||||
expect(json.containsKey('default_phone'), isTrue);
|
||||
});
|
||||
});
|
||||
|
||||
group('YandexPhoneData', () {
|
||||
@@ -69,6 +119,15 @@ void main() {
|
||||
expect(phoneData.id, 1);
|
||||
expect(phoneData.number, '+79001234567');
|
||||
});
|
||||
|
||||
test('toJson serializes YandexPhoneData correctly', () {
|
||||
final phoneData = YandexPhoneData(id: 1, number: '+79001234567');
|
||||
|
||||
final json = phoneData.toJson();
|
||||
|
||||
expect(json['id'], 1);
|
||||
expect(json['number'], '+79001234567');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user