forked from eatvio/eatvio_app
feat(tests): updated tests coverage to 66.5%
This commit is contained in:
133
test/features/settings/models/oauth_account_model_test.dart
Normal file
133
test/features/settings/models/oauth_account_model_test.dart
Normal file
@@ -0,0 +1,133 @@
|
||||
import 'package:eatvio_app/features/settings/models/oauth_account_model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('OAuthAccountModel', () {
|
||||
test('fromJson parses all fields correctly', () {
|
||||
final json = {
|
||||
'oauth_id': 'oauth-123',
|
||||
'name': 'John Doe',
|
||||
'email': 'john@example.com',
|
||||
'phone': '+1234567890',
|
||||
'linked_at': '2024-01-01T12:00:00Z',
|
||||
};
|
||||
|
||||
final model = OAuthAccountModel.fromJson(json);
|
||||
|
||||
expect(model.oauthId, 'oauth-123');
|
||||
expect(model.name, 'John Doe');
|
||||
expect(model.email, 'john@example.com');
|
||||
expect(model.phone, '+1234567890');
|
||||
expect(model.linkedAt, isA<DateTime>());
|
||||
});
|
||||
|
||||
test('toJson serializes all fields correctly', () {
|
||||
final model = OAuthAccountModel(
|
||||
oauthId: 'oauth-123',
|
||||
name: 'John Doe',
|
||||
email: 'john@example.com',
|
||||
phone: '+1234567890',
|
||||
linkedAt: DateTime(2024, 1, 1, 12, 0, 0),
|
||||
);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json['oauth_id'], 'oauth-123');
|
||||
expect(json['name'], 'John Doe');
|
||||
expect(json['email'], 'john@example.com');
|
||||
expect(json['phone'], '+1234567890');
|
||||
expect(json['linked_at'], isA<String>());
|
||||
});
|
||||
});
|
||||
|
||||
group('OAuthAccountsResponseModel', () {
|
||||
test('fromJson parses all fields correctly', () {
|
||||
final json = {
|
||||
'success': true,
|
||||
'data': {
|
||||
'vk': {
|
||||
'oauth_id': 'vk-123',
|
||||
'name': 'VK User',
|
||||
'email': 'vk@example.com',
|
||||
'phone': '+1234567890',
|
||||
'linked_at': '2024-01-01T12:00:00Z',
|
||||
},
|
||||
'yandex': {
|
||||
'oauth_id': 'yandex-123',
|
||||
'name': 'Yandex User',
|
||||
'email': 'yandex@example.com',
|
||||
'phone': '+1234567890',
|
||||
'linked_at': '2024-01-01T12:00:00Z',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
final model = OAuthAccountsResponseModel.fromJson(json);
|
||||
|
||||
expect(model.success, isTrue);
|
||||
expect(model.data.vk, isNotNull);
|
||||
expect(model.data.yandex, isNotNull);
|
||||
expect(model.data.vk?.oauthId, 'vk-123');
|
||||
expect(model.data.yandex?.oauthId, 'yandex-123');
|
||||
});
|
||||
|
||||
test('fromJson handles null OAuth accounts', () {
|
||||
final json = {
|
||||
'success': true,
|
||||
'data': {
|
||||
'vk': null,
|
||||
'yandex': null,
|
||||
},
|
||||
};
|
||||
|
||||
final model = OAuthAccountsResponseModel.fromJson(json);
|
||||
|
||||
expect(model.success, isTrue);
|
||||
expect(model.data.vk, isNull);
|
||||
expect(model.data.yandex, isNull);
|
||||
});
|
||||
|
||||
test('fromJson handles empty array for OAuth accounts', () {
|
||||
final json = {
|
||||
'success': true,
|
||||
'data': {
|
||||
'vk': [],
|
||||
'yandex': [],
|
||||
},
|
||||
};
|
||||
|
||||
final model = OAuthAccountsResponseModel.fromJson(json);
|
||||
|
||||
expect(model.success, isTrue);
|
||||
expect(model.data.vk, isNull);
|
||||
expect(model.data.yandex, isNull);
|
||||
});
|
||||
|
||||
test('toJson serializes all fields correctly', () {
|
||||
final vkAccount = OAuthAccountModel(
|
||||
oauthId: 'vk-123',
|
||||
name: 'VK User',
|
||||
email: 'vk@example.com',
|
||||
phone: '+1234567890',
|
||||
linkedAt: DateTime(2024, 1, 1, 12, 0, 0),
|
||||
);
|
||||
final data = OAuthAccountsDataModel(vk: vkAccount, yandex: null);
|
||||
final model = OAuthAccountsResponseModel(success: true, data: data);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json['success'], isTrue);
|
||||
expect(json['data'], isNotNull);
|
||||
if (json['data'] is Map) {
|
||||
final dataJson = json['data'] as Map<String, dynamic>;
|
||||
expect(dataJson['vk'], isNotNull);
|
||||
expect(dataJson['yandex'], isNull);
|
||||
} else {
|
||||
// If data is already a model, check it directly
|
||||
expect(model.data.vk, isNotNull);
|
||||
expect(model.data.yandex, isNull);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -78,5 +78,36 @@ void main() {
|
||||
expect(googleRequest.provider, 'google');
|
||||
expect(facebookRequest.provider, 'facebook');
|
||||
});
|
||||
|
||||
test('toJson serializes OAuthAttachRequest correctly', () {
|
||||
const request = OAuthAttachRequest(
|
||||
provider: 'google',
|
||||
clientId: 'client123',
|
||||
accessToken: 'access_token_123',
|
||||
refreshToken: 'refresh_token_123',
|
||||
);
|
||||
|
||||
final json = request.toJson();
|
||||
|
||||
expect(json['provider'], 'google');
|
||||
expect(json['client_id'], 'client123');
|
||||
expect(json['access_token'], 'access_token_123');
|
||||
expect(json['refresh_token'], 'refresh_token_123');
|
||||
});
|
||||
|
||||
test('toJson serializes OAuthAttachRequest with null clientId correctly', () {
|
||||
const request = OAuthAttachRequest(
|
||||
provider: 'facebook',
|
||||
clientId: null,
|
||||
accessToken: 'access_token_456',
|
||||
refreshToken: 'refresh_token_456',
|
||||
);
|
||||
|
||||
final json = request.toJson();
|
||||
|
||||
expect(json['provider'], 'facebook');
|
||||
expect(json['access_token'], 'access_token_456');
|
||||
expect(json['refresh_token'], 'refresh_token_456');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
import 'package:eatvio_app/features/settings/models/profile_settings_model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('ProfileSettingsModel', () {
|
||||
test('fromJson parses all fields correctly', () {
|
||||
final json = {
|
||||
'new_updates_notifications': true,
|
||||
'diary_reminder_notifications': {'enabled': true},
|
||||
'is_mood_fillable': true,
|
||||
'is_bedtime_fillable': false,
|
||||
'is_public_profile': true,
|
||||
};
|
||||
|
||||
final model = ProfileSettingsModel.fromJson(json);
|
||||
|
||||
expect(model.newUpdatesNotifications, isTrue);
|
||||
expect(model.diaryReminderNotifications, isNotNull);
|
||||
expect(model.isMoodFillable, isTrue);
|
||||
expect(model.isBedtimeFillable, isFalse);
|
||||
expect(model.isPublicProfile, isTrue);
|
||||
});
|
||||
|
||||
test('fromJson handles different notification types', () {
|
||||
final json = {
|
||||
'new_updates_notifications': false,
|
||||
'diary_reminder_notifications': null,
|
||||
'is_mood_fillable': false,
|
||||
'is_bedtime_fillable': true,
|
||||
'is_public_profile': false,
|
||||
};
|
||||
|
||||
final model = ProfileSettingsModel.fromJson(json);
|
||||
|
||||
expect(model.newUpdatesNotifications, isFalse);
|
||||
expect(model.isMoodFillable, isFalse);
|
||||
expect(model.isBedtimeFillable, isTrue);
|
||||
expect(model.isPublicProfile, isFalse);
|
||||
});
|
||||
|
||||
test('toJson serializes all fields correctly', () {
|
||||
const model = ProfileSettingsModel(
|
||||
newUpdatesNotifications: true,
|
||||
diaryReminderNotifications: {'enabled': true},
|
||||
isMoodFillable: true,
|
||||
isBedtimeFillable: false,
|
||||
isPublicProfile: true,
|
||||
);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json['new_updates_notifications'], isTrue);
|
||||
expect(json.containsKey('diary_reminder_notifications'), isTrue);
|
||||
expect(json['is_mood_fillable'], isTrue);
|
||||
expect(json['is_bedtime_fillable'], isFalse);
|
||||
expect(json['is_public_profile'], isTrue);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user