forked from eatvio/eatvio_app
feat(tests): test coverage is 70.4
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
import 'package:eatvio_app/features/auth/models/oauth_verification_confirm_request.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('OAuthVerificationConfirmRequest', () {
|
||||
test('creates instance with required fields', () {
|
||||
const request = OAuthVerificationConfirmRequest(
|
||||
accessToken: 'access_token_123',
|
||||
refreshToken: 'refresh_token_123',
|
||||
clientId: 'client_id_123',
|
||||
provider: 'vk',
|
||||
id: 'user_id_123',
|
||||
code: 'code_123',
|
||||
verificationType: 'email',
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
dateOfBirth: '1990-01-01',
|
||||
gender: 'male',
|
||||
weight: 70,
|
||||
height: 180,
|
||||
);
|
||||
|
||||
expect(request.accessToken, 'access_token_123');
|
||||
expect(request.refreshToken, 'refresh_token_123');
|
||||
expect(request.clientId, 'client_id_123');
|
||||
expect(request.provider, 'vk');
|
||||
expect(request.id, 'user_id_123');
|
||||
expect(request.code, 'code_123');
|
||||
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, 70);
|
||||
expect(request.height, 180);
|
||||
});
|
||||
|
||||
test('creates instance with optional email', () {
|
||||
const request = OAuthVerificationConfirmRequest(
|
||||
accessToken: 'access_token_123',
|
||||
refreshToken: 'refresh_token_123',
|
||||
clientId: 'client_id_123',
|
||||
provider: 'vk',
|
||||
id: 'user_id_123',
|
||||
email: 'test@example.com',
|
||||
code: 'code_123',
|
||||
verificationType: 'email',
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
dateOfBirth: '1990-01-01',
|
||||
gender: 'male',
|
||||
weight: 70,
|
||||
height: 180,
|
||||
);
|
||||
|
||||
expect(request.email, 'test@example.com');
|
||||
});
|
||||
|
||||
test('creates instance with optional phone', () {
|
||||
const request = OAuthVerificationConfirmRequest(
|
||||
accessToken: 'access_token_123',
|
||||
refreshToken: 'refresh_token_123',
|
||||
clientId: 'client_id_123',
|
||||
provider: 'vk',
|
||||
id: 'user_id_123',
|
||||
phone: '+79991234567',
|
||||
code: 'code_123',
|
||||
verificationType: 'phone',
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
dateOfBirth: '1990-01-01',
|
||||
gender: 'male',
|
||||
weight: 70,
|
||||
height: 180,
|
||||
);
|
||||
|
||||
expect(request.phone, '+79991234567');
|
||||
});
|
||||
|
||||
test('fromJson creates instance from JSON', () {
|
||||
final json = {
|
||||
'access_token': 'access_token_123',
|
||||
'refresh_token': 'refresh_token_123',
|
||||
'client_id': 'client_id_123',
|
||||
'provider': 'vk',
|
||||
'id': 'user_id_123',
|
||||
'code': 'code_123',
|
||||
'verification_type': 'email',
|
||||
'first_name': 'John',
|
||||
'last_name': 'Doe',
|
||||
'date_of_birth': '1990-01-01',
|
||||
'gender': 'male',
|
||||
'weight': 70,
|
||||
'height': 180,
|
||||
};
|
||||
|
||||
final request = OAuthVerificationConfirmRequest.fromJson(json);
|
||||
|
||||
expect(request.accessToken, 'access_token_123');
|
||||
expect(request.refreshToken, 'refresh_token_123');
|
||||
expect(request.clientId, 'client_id_123');
|
||||
expect(request.provider, 'vk');
|
||||
expect(request.id, 'user_id_123');
|
||||
expect(request.code, 'code_123');
|
||||
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, 70);
|
||||
expect(request.height, 180);
|
||||
});
|
||||
|
||||
test('toJson converts instance to JSON', () {
|
||||
const request = OAuthVerificationConfirmRequest(
|
||||
accessToken: 'access_token_123',
|
||||
refreshToken: 'refresh_token_123',
|
||||
clientId: 'client_id_123',
|
||||
provider: 'vk',
|
||||
id: 'user_id_123',
|
||||
email: 'test@example.com',
|
||||
code: 'code_123',
|
||||
verificationType: 'email',
|
||||
firstName: 'John',
|
||||
lastName: 'Doe',
|
||||
dateOfBirth: '1990-01-01',
|
||||
gender: 'male',
|
||||
weight: 70,
|
||||
height: 180,
|
||||
);
|
||||
|
||||
final json = request.toJson();
|
||||
|
||||
expect(json['access_token'], 'access_token_123');
|
||||
expect(json['refresh_token'], 'refresh_token_123');
|
||||
expect(json['client_id'], 'client_id_123');
|
||||
expect(json['provider'], 'vk');
|
||||
expect(json['id'], 'user_id_123');
|
||||
expect(json['email'], 'test@example.com');
|
||||
expect(json['code'], 'code_123');
|
||||
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'], 70);
|
||||
expect(json['height'], 180);
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
import 'package:eatvio_app/features/auth/models/oauth_verification_confirm_response.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('OAuthVerificationConfirmResponse', () {
|
||||
test('creates instance with required fields', () {
|
||||
const response = OAuthVerificationConfirmResponse(
|
||||
success: true,
|
||||
message: 'Success',
|
||||
token: 'token_123',
|
||||
user: {'id': 1, 'name': 'John'},
|
||||
isNewUser: false,
|
||||
);
|
||||
|
||||
expect(response.success, true);
|
||||
expect(response.message, 'Success');
|
||||
expect(response.token, 'token_123');
|
||||
expect(response.user, {'id': 1, 'name': 'John'});
|
||||
expect(response.isNewUser, false);
|
||||
});
|
||||
|
||||
test('creates instance with isNewUser true', () {
|
||||
const response = OAuthVerificationConfirmResponse(
|
||||
success: true,
|
||||
message: 'New user created',
|
||||
token: 'token_123',
|
||||
user: {'id': 1, 'name': 'John'},
|
||||
isNewUser: true,
|
||||
);
|
||||
|
||||
expect(response.isNewUser, true);
|
||||
});
|
||||
|
||||
test('fromJson creates instance from JSON', () {
|
||||
final json = {
|
||||
'success': true,
|
||||
'message': 'Success',
|
||||
'token': 'token_123',
|
||||
'user': {'id': 1, 'name': 'John'},
|
||||
'is_new_user': false,
|
||||
};
|
||||
|
||||
final response = OAuthVerificationConfirmResponse.fromJson(json);
|
||||
|
||||
expect(response.success, true);
|
||||
expect(response.message, 'Success');
|
||||
expect(response.token, 'token_123');
|
||||
expect(response.user, {'id': 1, 'name': 'John'});
|
||||
expect(response.isNewUser, false);
|
||||
});
|
||||
|
||||
test('toJson converts instance to JSON', () {
|
||||
const response = OAuthVerificationConfirmResponse(
|
||||
success: true,
|
||||
message: 'Success',
|
||||
token: 'token_123',
|
||||
user: {'id': 1, 'name': 'John'},
|
||||
isNewUser: false,
|
||||
);
|
||||
|
||||
final json = response.toJson();
|
||||
|
||||
expect(json['success'], true);
|
||||
expect(json['message'], 'Success');
|
||||
expect(json['token'], 'token_123');
|
||||
expect(json['user'], {'id': 1, 'name': 'John'});
|
||||
expect(json['is_new_user'], false);
|
||||
});
|
||||
|
||||
test('equality works correctly', () {
|
||||
const response1 = OAuthVerificationConfirmResponse(
|
||||
success: true,
|
||||
message: 'Success',
|
||||
token: 'token_123',
|
||||
user: {'id': 1},
|
||||
isNewUser: false,
|
||||
);
|
||||
const response2 = OAuthVerificationConfirmResponse(
|
||||
success: true,
|
||||
message: 'Success',
|
||||
token: 'token_123',
|
||||
user: {'id': 1},
|
||||
isNewUser: false,
|
||||
);
|
||||
const response3 = OAuthVerificationConfirmResponse(
|
||||
success: false,
|
||||
message: 'Error',
|
||||
token: 'token_123',
|
||||
user: {'id': 1},
|
||||
isNewUser: false,
|
||||
);
|
||||
|
||||
expect(response1, equals(response2));
|
||||
expect(response1, isNot(equals(response3)));
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import 'package:eatvio_app/features/auth/models/oauth_verification_request_response.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('OAuthVerificationRequestResponse', () {
|
||||
test('creates instance with required fields', () {
|
||||
const response = OAuthVerificationRequestResponse(
|
||||
email: 'test@example.com',
|
||||
status: 'pending',
|
||||
);
|
||||
|
||||
expect(response.email, 'test@example.com');
|
||||
expect(response.status, 'pending');
|
||||
});
|
||||
|
||||
test('fromJson creates instance from JSON', () {
|
||||
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 converts instance to JSON', () {
|
||||
const response = OAuthVerificationRequestResponse(
|
||||
email: 'test@example.com',
|
||||
status: 'pending',
|
||||
);
|
||||
|
||||
final json = response.toJson();
|
||||
|
||||
expect(json['email'], 'test@example.com');
|
||||
expect(json['status'], 'pending');
|
||||
});
|
||||
|
||||
test('equality works correctly', () {
|
||||
const response1 = OAuthVerificationRequestResponse(
|
||||
email: 'test@example.com',
|
||||
status: 'pending',
|
||||
);
|
||||
const response2 = OAuthVerificationRequestResponse(
|
||||
email: 'test@example.com',
|
||||
status: 'pending',
|
||||
);
|
||||
const response3 = OAuthVerificationRequestResponse(
|
||||
email: 'other@example.com',
|
||||
status: 'pending',
|
||||
);
|
||||
|
||||
expect(response1, equals(response2));
|
||||
expect(response1, isNot(equals(response3)));
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user