Files
eatvio_app/test/features/chat/models/chat_user_model_test.dart
2026-01-14 18:47:11 +03:00

92 lines
2.4 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/chat/models/chat_user_model.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
group('ChatUserModel', () {
test('создает ChatUserModel с правильными значениями', () {
const model = ChatUserModel(
id: 1,
name: 'User Name',
slug: 'user-slug',
profilePhotoUrl: 'https://example.com/photo.jpg',
);
expect(model.id, 1);
expect(model.name, 'User Name');
expect(model.slug, 'user-slug');
expect(model.profilePhotoUrl, 'https://example.com/photo.jpg');
});
test('создает ChatUserModel без фото', () {
const model = ChatUserModel(
id: 1,
name: 'User Name',
slug: 'user-slug',
profilePhotoUrl: null,
);
expect(model.profilePhotoUrl, isNull);
});
test('fromJson создает ChatUserModel из JSON', () {
final json = {
'id': 1,
'name': 'User Name',
'slug': 'user-slug',
'profile_photo_url': 'https://example.com/photo.jpg',
};
final model = ChatUserModel.fromJson(json);
expect(model.id, 1);
expect(model.name, 'User Name');
expect(model.slug, 'user-slug');
expect(model.profilePhotoUrl, 'https://example.com/photo.jpg');
});
test('fromJson создает ChatUserModel из JSON без фото', () {
final json = {
'id': 1,
'name': 'User Name',
'slug': 'user-slug',
};
final model = ChatUserModel.fromJson(json);
expect(model.id, 1);
expect(model.name, 'User Name');
expect(model.profilePhotoUrl, isNull);
});
test('toJson serializes ChatUserModel correctly', () {
const model = ChatUserModel(
id: 1,
name: 'User Name',
slug: 'user-slug',
profilePhotoUrl: 'https://example.com/photo.jpg',
);
final json = model.toJson();
expect(json['id'], 1);
expect(json['name'], 'User Name');
expect(json['slug'], 'user-slug');
expect(json['profile_photo_url'], 'https://example.com/photo.jpg');
});
test('toJson handles null profilePhotoUrl', () {
const model = ChatUserModel(
id: 1,
name: 'User Name',
slug: 'user-slug',
profilePhotoUrl: null,
);
final json = model.toJson();
expect(json['profile_photo_url'], isNull);
});
});
}