forked from eatvio/eatvio_app
feat(tests): updated tests coverage to 66.5%
This commit is contained in:
@@ -43,6 +43,50 @@ void main() {
|
||||
expect(model.mediaData, isNotNull);
|
||||
expect(model.mediaData!.length, 1);
|
||||
});
|
||||
|
||||
test('toJson serializes ChatMessageModel correctly', () {
|
||||
final model = ChatMessageModel(
|
||||
id: 1,
|
||||
data: 'Test message',
|
||||
mediaData: null,
|
||||
authorId: 123,
|
||||
updatedAt: DateTime(2024, 1, 1, 12, 0, 0),
|
||||
isRead: false,
|
||||
isCurrentUserAuthor: true,
|
||||
roomId: 'room-1',
|
||||
type: 'text',
|
||||
);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json['id'], 1);
|
||||
expect(json['data'], 'Test message');
|
||||
expect(json['author_id'], 123);
|
||||
expect(json['read_by_to_user'], false);
|
||||
expect(json['is_author_message_auth_user'], true);
|
||||
expect(json['room_id'], 'room-1');
|
||||
expect(json['type'], 'text');
|
||||
});
|
||||
|
||||
test('toJson handles null fields correctly', () {
|
||||
final model = ChatMessageModel(
|
||||
id: 1,
|
||||
data: 'Test message',
|
||||
mediaData: null,
|
||||
authorId: 123,
|
||||
updatedAt: DateTime(2024, 1, 1, 12, 0, 0),
|
||||
isRead: false,
|
||||
isCurrentUserAuthor: null,
|
||||
roomId: null,
|
||||
type: null,
|
||||
);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json['is_author_message_auth_user'], isNull);
|
||||
expect(json['room_id'], isNull);
|
||||
expect(json['type'], isNull);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -37,5 +37,30 @@ void main() {
|
||||
expect(model.messagesList.first.data, 'First message');
|
||||
expect(model.meta.lastPage, 1);
|
||||
});
|
||||
|
||||
test('toJson serializes ChatMessagesModel correctly', () {
|
||||
final message = ChatMessageModel(
|
||||
id: 1,
|
||||
data: 'Test message',
|
||||
mediaData: null,
|
||||
authorId: 123,
|
||||
updatedAt: DateTime(2024, 1, 1, 12, 0, 0),
|
||||
isRead: false,
|
||||
isCurrentUserAuthor: true,
|
||||
roomId: 'room-1',
|
||||
type: 'text',
|
||||
);
|
||||
|
||||
const meta = ChatMetaModel(lastPage: 1);
|
||||
|
||||
final model = ChatMessagesModel(messagesList: [message], meta: meta);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json, isNotNull);
|
||||
expect(json, isA<Map<String, dynamic>>());
|
||||
expect(json.containsKey('data'), isTrue);
|
||||
expect((json['data'] as List).length, 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -20,6 +20,14 @@ void main() {
|
||||
|
||||
expect(model.lastPage, 5);
|
||||
});
|
||||
|
||||
test('toJson serializes ChatMetaModel correctly', () {
|
||||
const model = ChatMetaModel(lastPage: 5);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json['last_page'], 5);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -51,6 +51,46 @@ void main() {
|
||||
expect(model.users.sender.id, 1);
|
||||
expect(model.users.receiver.id, 2);
|
||||
});
|
||||
|
||||
test('toJson serializes ChatRoomModel correctly', () {
|
||||
const settings = ChatRoomSettingsModel(
|
||||
name: 'Room Name',
|
||||
state: 'active',
|
||||
);
|
||||
|
||||
const sender = ChatUserModel(
|
||||
id: 1,
|
||||
name: 'Sender',
|
||||
slug: 'sender',
|
||||
profilePhotoUrl: 'https://example.com/sender.jpg',
|
||||
);
|
||||
|
||||
const receiver = ChatUserModel(
|
||||
id: 2,
|
||||
name: 'Receiver',
|
||||
slug: 'receiver',
|
||||
profilePhotoUrl: 'https://example.com/receiver.jpg',
|
||||
);
|
||||
|
||||
const users = Users(sender: sender, receiver: receiver);
|
||||
|
||||
const model = ChatRoomModel(
|
||||
id: 'room-1',
|
||||
chatRoomSettings: settings,
|
||||
users: users,
|
||||
chosenPlanId: 1,
|
||||
chosenPlan: null,
|
||||
);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json, isNotNull);
|
||||
expect(json, isA<Map<String, dynamic>>());
|
||||
expect(json['id'], 'room-1');
|
||||
expect(json['chosen_plan_id'], 1);
|
||||
expect(json.containsKey('chat_room_setting'), isTrue);
|
||||
expect(json.containsKey('users'), isTrue);
|
||||
});
|
||||
});
|
||||
|
||||
group('Users', () {
|
||||
@@ -63,6 +103,31 @@ void main() {
|
||||
expect(users.sender.id, 1);
|
||||
expect(users.receiver.id, 2);
|
||||
});
|
||||
|
||||
test('toJson serializes Users correctly', () {
|
||||
const sender = ChatUserModel(
|
||||
id: 1,
|
||||
name: 'Sender',
|
||||
slug: 'sender',
|
||||
profilePhotoUrl: 'https://example.com/sender.jpg',
|
||||
);
|
||||
|
||||
const receiver = ChatUserModel(
|
||||
id: 2,
|
||||
name: 'Receiver',
|
||||
slug: 'receiver',
|
||||
profilePhotoUrl: 'https://example.com/receiver.jpg',
|
||||
);
|
||||
|
||||
const users = Users(sender: sender, receiver: receiver);
|
||||
|
||||
final json = users.toJson();
|
||||
|
||||
expect(json, isNotNull);
|
||||
expect(json, isA<Map<String, dynamic>>());
|
||||
expect(json.containsKey('from_chat_user'), isTrue);
|
||||
expect(json.containsKey('to_chat_user'), isTrue);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -141,6 +141,67 @@ void main() {
|
||||
expect(chatUser.name, 'User 1');
|
||||
expect(chatUser.profilePhotoUrl, 'https://example.com/user1.jpg');
|
||||
});
|
||||
|
||||
test('toJson serializes ChatUser correctly', () {
|
||||
const chatUser = ChatUser(
|
||||
id: 1,
|
||||
name: 'User 1',
|
||||
profilePhotoPath: null,
|
||||
profilePhotoUrl: 'https://example.com/user1.jpg',
|
||||
);
|
||||
|
||||
final json = chatUser.toJson();
|
||||
|
||||
expect(json['id'], 1);
|
||||
expect(json['name'], 'User 1');
|
||||
expect(json['profile_photo_url'], 'https://example.com/user1.jpg');
|
||||
});
|
||||
});
|
||||
|
||||
group('ChatRoomPaginationModel', () {
|
||||
test('toJson serializes ChatRoomPaginationModel correctly', () {
|
||||
const chatRoom = ChatRoom(
|
||||
id: 'room-1',
|
||||
lastMessage: null,
|
||||
users: Users(
|
||||
fromChatUser: ChatUser(
|
||||
id: 1,
|
||||
name: 'User 1',
|
||||
profilePhotoPath: null,
|
||||
profilePhotoUrl: 'https://example.com/user1.jpg',
|
||||
),
|
||||
toChatUser: ChatUser(
|
||||
id: 2,
|
||||
name: 'User 2',
|
||||
profilePhotoPath: null,
|
||||
profilePhotoUrl: 'https://example.com/user2.jpg',
|
||||
),
|
||||
),
|
||||
unreadMessagesCount: 5,
|
||||
chosenPlan: null,
|
||||
);
|
||||
|
||||
const pagination = ChatRoomPaginationModel(
|
||||
data: [chatRoom],
|
||||
unreadChatsCount: 1,
|
||||
meta: Meta(
|
||||
currentPage: 1,
|
||||
from: 1,
|
||||
lastPage: 1,
|
||||
links: [],
|
||||
perPage: 10,
|
||||
to: 1,
|
||||
total: 1,
|
||||
),
|
||||
);
|
||||
|
||||
final json = pagination.toJson();
|
||||
|
||||
expect(json.containsKey('data'), isTrue);
|
||||
expect(json.containsKey('number_of_unread_chat_rooms'), isTrue);
|
||||
expect(json.containsKey('meta'), isTrue);
|
||||
expect(json['number_of_unread_chat_rooms'], 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,18 @@ void main() {
|
||||
expect(model.name, 'Room Name');
|
||||
expect(model.state, 'active');
|
||||
});
|
||||
|
||||
test('toJson serializes ChatRoomSettingsModel correctly', () {
|
||||
const model = ChatRoomSettingsModel(
|
||||
name: 'Room Name',
|
||||
state: 'active',
|
||||
);
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json['room_name'], 'Room Name');
|
||||
expect(json['state'], 'active');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,35 @@ void main() {
|
||||
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);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -3,23 +3,26 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
group('PlanComplainModel', () {
|
||||
test('создает PlanComplainModel с правильными значениями', () {
|
||||
final model = PlanComplainModel(
|
||||
description: 'Test complaint',
|
||||
);
|
||||
|
||||
expect(model.description, 'Test complaint');
|
||||
});
|
||||
|
||||
test('fromJson создает PlanComplainModel из JSON', () {
|
||||
final json = {
|
||||
'description': 'Test complaint',
|
||||
};
|
||||
test('fromJson parses description correctly', () {
|
||||
final json = {'description': 'Test complaint description'};
|
||||
|
||||
final model = PlanComplainModel.fromJson(json);
|
||||
|
||||
expect(model.description, 'Test complaint');
|
||||
expect(model.description, 'Test complaint description');
|
||||
});
|
||||
|
||||
test('toJson serializes description correctly', () {
|
||||
final model = PlanComplainModel(description: 'Test complaint description');
|
||||
|
||||
final json = model.toJson();
|
||||
|
||||
expect(json['description'], 'Test complaint description');
|
||||
});
|
||||
|
||||
test('creates instance with description', () {
|
||||
final model = PlanComplainModel(description: 'Another complaint');
|
||||
|
||||
expect(model.description, 'Another complaint');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user