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);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user