Files
eatvio_app/test/features/auth/models/oauth_model_test.dart
2025-11-28 14:22:05 +03:00

143 lines
4.6 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:eatvio_app/features/auth/models/oauth_model.dart';
import 'package:flutter_test/flutter_test.dart';
import '../../../fixtures/fixture_reader.dart';
void main() {
group('OAuthModel', () {
late Map<String, dynamic> oauthSignUpFixture;
setUp(() {
oauthSignUpFixture = FixtureReader.readAsMap('auth/oauth_signup_request.json');
});
test('создание модели из JSON', () {
final model = OAuthModel.fromJson(oauthSignUpFixture);
expect(model.provider, oauthSignUpFixture['provider']);
expect(model.accessToken, oauthSignUpFixture['access_token']);
expect(model.refreshToken, oauthSignUpFixture['refresh_token']);
expect(model.id, oauthSignUpFixture['id']);
expect(model.firstName, oauthSignUpFixture['first_name']);
expect(model.lastName, oauthSignUpFixture['last_name']);
expect(model.email, oauthSignUpFixture['email']);
expect(model.phone, oauthSignUpFixture['phone']);
expect(model.dateOfBirth, oauthSignUpFixture['date_of_birth']);
expect(model.gender, oauthSignUpFixture['gender']);
expect(model.weight, oauthSignUpFixture['weight']);
expect(model.height, oauthSignUpFixture['height']);
expect(model.clientId, oauthSignUpFixture['client_id']);
});
test('создание модели через конструктор', () {
const model = OAuthModel(
provider: 'vk',
accessToken: 'access_token_123',
refreshToken: 'refresh_token_123',
id: 'user_id_123',
firstName: 'Иван',
lastName: 'Иванов',
email: 'ivan@example.com',
phone: '+79001234567',
dateOfBirth: '1990-01-01',
gender: 'male',
weight: 75,
height: 180,
clientId: 'client_id_123',
);
expect(model.provider, 'vk');
expect(model.email, 'ivan@example.com');
expect(model.gender, 'male');
expect(model.weight, 75);
expect(model.height, 180);
});
test('преобразование модели в JSON с правильными ключами', () {
const model = OAuthModel(
provider: 'vk',
accessToken: 'access_token_123',
refreshToken: 'refresh_token_123',
id: 'user_id_123',
firstName: 'Иван',
lastName: 'Иванов',
email: 'ivan@example.com',
phone: '+79001234567',
dateOfBirth: '1990-01-01',
gender: 'male',
weight: 75,
height: 180,
clientId: 'client_id_123',
);
final json = model.toJson();
expect(json['provider'], 'vk');
expect(json['access_token'], 'access_token_123');
expect(json['refresh_token'], 'refresh_token_123');
expect(json['id'], 'user_id_123');
expect(json['first_name'], 'Иван');
expect(json['last_name'], 'Иванов');
expect(json['email'], 'ivan@example.com');
expect(json['phone'], '+79001234567');
expect(json['date_of_birth'], '1990-01-01');
expect(json['gender'], 'male');
expect(json['weight'], 75);
expect(json['height'], 180);
expect(json['client_id'], 'client_id_123');
});
test('равенство моделей', () {
const model1 = OAuthModel(
provider: 'vk',
accessToken: 'access_token_123',
refreshToken: 'refresh_token_123',
id: 'user_id_123',
firstName: 'Иван',
lastName: 'Иванов',
email: 'ivan@example.com',
phone: '+79001234567',
dateOfBirth: '1990-01-01',
gender: 'male',
weight: 75,
height: 180,
clientId: 'client_id_123',
);
const model2 = OAuthModel(
provider: 'vk',
accessToken: 'access_token_123',
refreshToken: 'refresh_token_123',
id: 'user_id_123',
firstName: 'Иван',
lastName: 'Иванов',
email: 'ivan@example.com',
phone: '+79001234567',
dateOfBirth: '1990-01-01',
gender: 'male',
weight: 75,
height: 180,
clientId: 'client_id_123',
);
const model3 = OAuthModel(
provider: 'google',
accessToken: 'access_token_123',
refreshToken: 'refresh_token_123',
id: 'user_id_123',
firstName: 'Иван',
lastName: 'Иванов',
email: 'ivan@example.com',
phone: '+79001234567',
dateOfBirth: '1990-01-01',
gender: 'male',
weight: 75,
height: 180,
clientId: 'client_id_123',
);
expect(model1, equals(model2));
expect(model1, isNot(equals(model3)));
});
});
}