feat(test): oauth, prefs, credentials

This commit is contained in:
mso7nueh
2025-11-28 14:22:05 +03:00
parent 2a25be5aa4
commit 9fcfac87d4
9 changed files with 624 additions and 76 deletions

View File

@@ -0,0 +1,62 @@
import 'package:eatvio_app/features/auth/models/credentials_model.dart';
import 'package:flutter_test/flutter_test.dart';
import '../../../fixtures/fixture_reader.dart';
void main() {
group('CredentialsModel', () {
late Map<String, dynamic> credentialsFixture;
setUp(() {
credentialsFixture = FixtureReader.readAsMap('auth/login_credentials.json');
});
test('создание модели из JSON', () {
final model = CredentialsModel.fromJson(credentialsFixture);
expect(model.email, credentialsFixture['email']);
expect(model.password, credentialsFixture['password']);
});
test('создание модели через конструктор', () {
const model = CredentialsModel(
email: 'test@example.com',
password: 'password123',
);
expect(model.email, 'test@example.com');
expect(model.password, 'password123');
});
test('преобразование модели в JSON', () {
const model = CredentialsModel(
email: 'test@example.com',
password: 'password123',
);
final json = model.toJson();
expect(json['email'], 'test@example.com');
expect(json['password'], 'password123');
});
test('равенство моделей', () {
const model1 = CredentialsModel(
email: 'test@example.com',
password: 'password123',
);
const model2 = CredentialsModel(
email: 'test@example.com',
password: 'password123',
);
const model3 = CredentialsModel(
email: 'other@example.com',
password: 'password123',
);
expect(model1, equals(model2));
expect(model1, isNot(equals(model3)));
});
});
}

View File

@@ -0,0 +1,78 @@
import 'package:eatvio_app/features/auth/models/oauth_login_request.dart';
import 'package:flutter_test/flutter_test.dart';
import '../../../fixtures/fixture_reader.dart';
void main() {
group('OAuthLoginRequest', () {
late Map<String, dynamic> oauthSignInFixture;
setUp(() {
oauthSignInFixture = FixtureReader.readAsMap('auth/oauth_signin_request.json');
});
test('создание модели из JSON', () {
final model = OAuthLoginRequest.fromJson(oauthSignInFixture);
expect(model.provider, oauthSignInFixture['provider']);
expect(model.accessToken, oauthSignInFixture['access_token']);
expect(model.refreshToken, oauthSignInFixture['refresh_token']);
expect(model.clientId, oauthSignInFixture['client_id']);
});
test('создание модели через конструктор', () {
const model = OAuthLoginRequest(
provider: 'vk',
accessToken: 'access_token_123',
refreshToken: 'refresh_token_123',
clientId: 'client_id_123',
);
expect(model.provider, 'vk');
expect(model.accessToken, 'access_token_123');
expect(model.refreshToken, 'refresh_token_123');
expect(model.clientId, 'client_id_123');
});
test('преобразование модели в JSON с правильными ключами', () {
const model = OAuthLoginRequest(
provider: 'vk',
accessToken: 'access_token_123',
refreshToken: 'refresh_token_123',
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['client_id'], 'client_id_123');
});
test('равенство моделей', () {
const model1 = OAuthLoginRequest(
provider: 'vk',
accessToken: 'access_token_123',
refreshToken: 'refresh_token_123',
clientId: 'client_id_123',
);
const model2 = OAuthLoginRequest(
provider: 'vk',
accessToken: 'access_token_123',
refreshToken: 'refresh_token_123',
clientId: 'client_id_123',
);
const model3 = OAuthLoginRequest(
provider: 'google',
accessToken: 'access_token_123',
refreshToken: 'refresh_token_123',
clientId: 'client_id_123',
);
expect(model1, equals(model2));
expect(model1, isNot(equals(model3)));
});
});
}

View File

@@ -0,0 +1,142 @@
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)));
});
});
}