forked from eatvio/eatvio_app
feat(tests): added services tests and fixtures
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'package:eatvio_app/features/chat/models/chat_message_model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import '../../../fixtures/fixture_reader.dart';
|
||||
|
||||
void main() {
|
||||
group('ChatMessageModel', () {
|
||||
@@ -23,22 +24,24 @@ void main() {
|
||||
});
|
||||
|
||||
test('fromJson создает ChatMessageModel из JSON', () {
|
||||
final json = {
|
||||
'id': 1,
|
||||
'data': 'Test message',
|
||||
'media_data': null,
|
||||
'author_id': 123,
|
||||
'updated_at': '2024-01-01T00:00:00Z',
|
||||
'read_by_to_user': false,
|
||||
'is_author_message_auth_user': true,
|
||||
'room_id': 'room-1',
|
||||
};
|
||||
final json = FixtureReader.readAsMap('chat/chat_message_response.json');
|
||||
|
||||
final model = ChatMessageModel.fromJson(json);
|
||||
|
||||
expect(model.id, 1);
|
||||
expect(model.data, 'Test message');
|
||||
expect(model.authorId, 123);
|
||||
expect(model.authorId, 1);
|
||||
});
|
||||
|
||||
test('fromJson создает ChatMessageModel с медиа из JSON', () {
|
||||
final json = FixtureReader.readAsMap('chat/chat_message_with_media_response.json');
|
||||
|
||||
final model = ChatMessageModel.fromJson(json);
|
||||
|
||||
expect(model.id, 2);
|
||||
expect(model.data, 'Message with attachment');
|
||||
expect(model.mediaData, isNotNull);
|
||||
expect(model.mediaData!.length, 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:eatvio_app/features/chat/models/chat_message_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_meta_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_messages_model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import '../../../fixtures/fixture_reader.dart';
|
||||
|
||||
void main() {
|
||||
group('ChatMessagesModel', () {
|
||||
@@ -19,10 +20,7 @@ void main() {
|
||||
|
||||
const meta = ChatMetaModel(lastPage: 1);
|
||||
|
||||
final model = ChatMessagesModel(
|
||||
messagesList: [message],
|
||||
meta: meta,
|
||||
);
|
||||
final model = ChatMessagesModel(messagesList: [message], meta: meta);
|
||||
|
||||
expect(model.messagesList.length, 1);
|
||||
expect(model.messagesList.first.id, 1);
|
||||
@@ -30,30 +28,14 @@ void main() {
|
||||
});
|
||||
|
||||
test('fromJson создает ChatMessagesModel из JSON', () {
|
||||
final json = {
|
||||
'data': [
|
||||
{
|
||||
'id': 1,
|
||||
'data': 'Test message',
|
||||
'media_data': null,
|
||||
'author_id': 123,
|
||||
'updated_at': '2024-01-01T00:00:00Z',
|
||||
'read_by_to_user': false,
|
||||
'is_author_message_auth_user': true,
|
||||
'room_id': 'room-1',
|
||||
}
|
||||
],
|
||||
'meta': {
|
||||
'last_page': 1,
|
||||
},
|
||||
};
|
||||
final json = FixtureReader.readAsMap('chat/chat_messages_response.json');
|
||||
|
||||
final model = ChatMessagesModel.fromJson(json);
|
||||
|
||||
expect(model.messagesList.length, 1);
|
||||
expect(model.messagesList.length, 2);
|
||||
expect(model.messagesList.first.id, 1);
|
||||
expect(model.messagesList.first.data, 'First message');
|
||||
expect(model.meta.lastPage, 1);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:eatvio_app/features/chat/models/chat_room_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_room_settings_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_user_model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import '../../../fixtures/fixture_reader.dart';
|
||||
|
||||
void main() {
|
||||
group('ChatRoomModel', () {
|
||||
@@ -41,34 +42,12 @@ void main() {
|
||||
});
|
||||
|
||||
test('fromJson создает ChatRoomModel из JSON', () {
|
||||
final json = {
|
||||
'id': 'room-1',
|
||||
'chat_room_setting': {
|
||||
'room_name': 'Room Name',
|
||||
'state': 'active',
|
||||
},
|
||||
'users': {
|
||||
'from_chat_user': {
|
||||
'id': 1,
|
||||
'name': 'Sender',
|
||||
'slug': 'sender',
|
||||
'profile_photo_url': 'https://example.com/sender.jpg',
|
||||
},
|
||||
'to_chat_user': {
|
||||
'id': 2,
|
||||
'name': 'Receiver',
|
||||
'slug': 'receiver',
|
||||
'profile_photo_url': 'https://example.com/receiver.jpg',
|
||||
},
|
||||
},
|
||||
'chosen_plan_id': 1,
|
||||
'chosen_plan': null,
|
||||
};
|
||||
final json = FixtureReader.readAsMap('chat/chat_room_response.json');
|
||||
|
||||
final model = ChatRoomModel.fromJson(json);
|
||||
|
||||
expect(model.id, 'room-1');
|
||||
expect(model.chosenPlanId, 1);
|
||||
expect(model.id, 'chat-1');
|
||||
expect(model.chosenPlanId, null);
|
||||
expect(model.users.sender.id, 1);
|
||||
expect(model.users.receiver.id, 2);
|
||||
});
|
||||
@@ -76,22 +55,10 @@ void main() {
|
||||
|
||||
group('Users', () {
|
||||
test('fromJson создает Users из JSON', () {
|
||||
final json = {
|
||||
'from_chat_user': {
|
||||
'id': 1,
|
||||
'name': 'Sender',
|
||||
'slug': 'sender',
|
||||
'profile_photo_url': 'https://example.com/sender.jpg',
|
||||
},
|
||||
'to_chat_user': {
|
||||
'id': 2,
|
||||
'name': 'Receiver',
|
||||
'slug': 'receiver',
|
||||
'profile_photo_url': 'https://example.com/receiver.jpg',
|
||||
},
|
||||
};
|
||||
final roomJson = FixtureReader.readAsMap('chat/chat_room_response.json');
|
||||
final usersJson = roomJson['users'] as Map<String, dynamic>;
|
||||
|
||||
final users = Users.fromJson(json);
|
||||
final users = Users.fromJson(usersJson);
|
||||
|
||||
expect(users.sender.id, 1);
|
||||
expect(users.receiver.id, 2);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import 'package:eatvio_app/core/models/pagination_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_room_pagination_model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import '../../../fixtures/fixture_reader.dart';
|
||||
|
||||
void main() {
|
||||
group('ChatRoomPaginationModel', () {
|
||||
@@ -46,54 +47,12 @@ void main() {
|
||||
});
|
||||
|
||||
test('fromJson создает ChatRoomPaginationModel из JSON', () {
|
||||
final json = {
|
||||
'data': [
|
||||
{
|
||||
'id': 'room-1',
|
||||
'last_message': {
|
||||
'id': 1,
|
||||
'data': 'Test message',
|
||||
'media_data': null,
|
||||
'author_id': 123,
|
||||
'updated_at': '2024-01-01T00:00:00Z',
|
||||
'read_by_to_user': false,
|
||||
'is_author_message_auth_user': true,
|
||||
'room_id': 'room-1',
|
||||
},
|
||||
'users': {
|
||||
'from_chat_user': {
|
||||
'id': 1,
|
||||
'name': 'User 1',
|
||||
'profile_photo_path': null,
|
||||
'profile_photo_url': 'https://example.com/user1.jpg',
|
||||
},
|
||||
'to_chat_user': {
|
||||
'id': 2,
|
||||
'name': 'User 2',
|
||||
'profile_photo_path': null,
|
||||
'profile_photo_url': 'https://example.com/user2.jpg',
|
||||
},
|
||||
},
|
||||
'unread_messages_count': 5,
|
||||
'chosen_plan': null,
|
||||
},
|
||||
],
|
||||
'number_of_unread_chat_rooms': 1,
|
||||
'meta': {
|
||||
'current_page': 1,
|
||||
'from': 1,
|
||||
'last_page': 1,
|
||||
'links': [],
|
||||
'per_page': 10,
|
||||
'to': 1,
|
||||
'total': 1,
|
||||
},
|
||||
};
|
||||
final json = FixtureReader.readAsMap('chat/chat_room_pagination_response.json');
|
||||
|
||||
final pagination = ChatRoomPaginationModel.fromJson(json);
|
||||
|
||||
expect(pagination.data.length, 1);
|
||||
expect(pagination.data.first.id, 'room-1');
|
||||
expect(pagination.data.length, 2);
|
||||
expect(pagination.data.first.id, 'chat-1');
|
||||
expect(pagination.unreadChatsCount, 1);
|
||||
});
|
||||
});
|
||||
@@ -106,16 +65,7 @@ void main() {
|
||||
});
|
||||
|
||||
test('parseLastMessage создает ChatMessageModel из Map', () {
|
||||
final json = {
|
||||
'id': 1,
|
||||
'data': 'Test message',
|
||||
'media_data': null,
|
||||
'author_id': 123,
|
||||
'updated_at': '2024-01-01T00:00:00Z',
|
||||
'read_by_to_user': false,
|
||||
'is_author_message_auth_user': true,
|
||||
'room_id': 'room-1',
|
||||
};
|
||||
final json = FixtureReader.readAsMap('chat/chat_message_response.json');
|
||||
|
||||
final result = parseLastMessage(json);
|
||||
|
||||
@@ -127,39 +77,12 @@ void main() {
|
||||
|
||||
group('ChatRoom', () {
|
||||
test('fromJson создает ChatRoom из JSON', () {
|
||||
final json = {
|
||||
'id': 'room-1',
|
||||
'last_message': {
|
||||
'id': 1,
|
||||
'data': 'Test message',
|
||||
'media_data': null,
|
||||
'author_id': 123,
|
||||
'updated_at': '2024-01-01T00:00:00Z',
|
||||
'read_by_to_user': false,
|
||||
'is_author_message_auth_user': true,
|
||||
'room_id': 'room-1',
|
||||
},
|
||||
'users': {
|
||||
'from_chat_user': {
|
||||
'id': 1,
|
||||
'name': 'User 1',
|
||||
'profile_photo_path': null,
|
||||
'profile_photo_url': 'https://example.com/user1.jpg',
|
||||
},
|
||||
'to_chat_user': {
|
||||
'id': 2,
|
||||
'name': 'User 2',
|
||||
'profile_photo_path': null,
|
||||
'profile_photo_url': 'https://example.com/user2.jpg',
|
||||
},
|
||||
},
|
||||
'unread_messages_count': 5,
|
||||
'chosen_plan': null,
|
||||
};
|
||||
final paginationJson = FixtureReader.readAsMap('chat/chat_room_pagination_response.json');
|
||||
final chatRoomJson = (paginationJson['data'] as List).first as Map<String, dynamic>;
|
||||
|
||||
final chatRoom = ChatRoom.fromJson(json);
|
||||
final chatRoom = ChatRoom.fromJson(chatRoomJson);
|
||||
|
||||
expect(chatRoom.id, 'room-1');
|
||||
expect(chatRoom.id, 'chat-1');
|
||||
expect(chatRoom.unreadMessagesCount, 5);
|
||||
expect(chatRoom.lastMessage, isNotNull);
|
||||
});
|
||||
@@ -194,22 +117,11 @@ void main() {
|
||||
|
||||
group('Users', () {
|
||||
test('fromJson создает Users из JSON', () {
|
||||
final json = {
|
||||
'from_chat_user': {
|
||||
'id': 1,
|
||||
'name': 'User 1',
|
||||
'profile_photo_path': null,
|
||||
'profile_photo_url': 'https://example.com/user1.jpg',
|
||||
},
|
||||
'to_chat_user': {
|
||||
'id': 2,
|
||||
'name': 'User 2',
|
||||
'profile_photo_path': null,
|
||||
'profile_photo_url': 'https://example.com/user2.jpg',
|
||||
},
|
||||
};
|
||||
final paginationJson = FixtureReader.readAsMap('chat/chat_room_pagination_response.json');
|
||||
final chatRoomJson = (paginationJson['data'] as List).first as Map<String, dynamic>;
|
||||
final usersJson = chatRoomJson['users'] as Map<String, dynamic>;
|
||||
|
||||
final users = Users.fromJson(json);
|
||||
final users = Users.fromJson(usersJson);
|
||||
|
||||
expect(users.fromChatUser.id, 1);
|
||||
expect(users.toChatUser.id, 2);
|
||||
@@ -218,14 +130,12 @@ void main() {
|
||||
|
||||
group('ChatUser', () {
|
||||
test('fromJson создает ChatUser из JSON', () {
|
||||
final json = {
|
||||
'id': 1,
|
||||
'name': 'User 1',
|
||||
'profile_photo_path': null,
|
||||
'profile_photo_url': 'https://example.com/user1.jpg',
|
||||
};
|
||||
final paginationJson = FixtureReader.readAsMap('chat/chat_room_pagination_response.json');
|
||||
final chatRoomJson = (paginationJson['data'] as List).first as Map<String, dynamic>;
|
||||
final usersJson = chatRoomJson['users'] as Map<String, dynamic>;
|
||||
final chatUserJson = usersJson['from_chat_user'] as Map<String, dynamic>;
|
||||
|
||||
final chatUser = ChatUser.fromJson(json);
|
||||
final chatUser = ChatUser.fromJson(chatUserJson);
|
||||
|
||||
expect(chatUser.id, 1);
|
||||
expect(chatUser.name, 'User 1');
|
||||
|
||||
@@ -3,23 +3,18 @@ import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/core/models/pagination_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_message_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_messages_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_meta_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_room_model.dart' as chat_room;
|
||||
import 'package:eatvio_app/features/chat/models/chat_room_pagination_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_room_settings_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_user_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/payment_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/plan_complain_model.dart';
|
||||
import 'package:eatvio_app/features/chat/repositories/chat_repository.dart';
|
||||
import 'package:eatvio_app/features/chat/services/chat_service.dart';
|
||||
import 'package:eatvio_app/features/plans/enums/chosen_plan_state_enum.dart';
|
||||
import 'package:eatvio_app/features/plans/models/chosen_plan_model.dart';
|
||||
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart';
|
||||
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:retrofit/retrofit.dart';
|
||||
import '../../../fixtures/fixture_reader.dart';
|
||||
import 'chat_repository_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<ChatService>()])
|
||||
@@ -35,16 +30,8 @@ void main() {
|
||||
});
|
||||
|
||||
test('emitNewMessageToChats - эмитит новое сообщение в поток', () async {
|
||||
final message = ChatMessageModel(
|
||||
id: 1,
|
||||
data: 'Test message',
|
||||
mediaData: null,
|
||||
authorId: 1,
|
||||
updatedAt: DateTime.now(),
|
||||
isRead: false,
|
||||
isCurrentUserAuthor: true,
|
||||
roomId: 'room-1',
|
||||
);
|
||||
final messageFixture = FixtureReader.readAsMap('chat/chat_message_response.json');
|
||||
final message = ChatMessageModel.fromJson(messageFixture);
|
||||
|
||||
chatRepository.emitNewMessageToChats(message);
|
||||
|
||||
@@ -123,29 +110,9 @@ void main() {
|
||||
});
|
||||
|
||||
test('getChatRoom - получает комнату чата по UUID', () async {
|
||||
const uuid = 'room-uuid-123';
|
||||
const expectedRoom = chat_room.ChatRoomModel(
|
||||
id: uuid,
|
||||
chatRoomSettings: ChatRoomSettingsModel(
|
||||
name: 'Test Room',
|
||||
state: 'active',
|
||||
),
|
||||
users: chat_room.Users(
|
||||
sender: ChatUserModel(
|
||||
id: 1,
|
||||
slug: 'user-1',
|
||||
name: 'User 1',
|
||||
profilePhotoUrl: null,
|
||||
),
|
||||
receiver: ChatUserModel(
|
||||
id: 2,
|
||||
slug: 'user-2',
|
||||
name: 'User 2',
|
||||
profilePhotoUrl: null,
|
||||
),
|
||||
),
|
||||
chosenPlanId: null,
|
||||
);
|
||||
const uuid = 'chat-1';
|
||||
final roomFixture = FixtureReader.readAsMap('chat/chat_room_response.json');
|
||||
final expectedRoom = chat_room.ChatRoomModel.fromJson(roomFixture);
|
||||
|
||||
when(mockChatService.getChatRoom(uuid: uuid))
|
||||
.thenAnswer((_) async => expectedRoom);
|
||||
@@ -170,19 +137,8 @@ void main() {
|
||||
});
|
||||
|
||||
test('getChatRooms - получает список комнат чата', () async {
|
||||
const expectedPagination = ChatRoomPaginationModel(
|
||||
data: [],
|
||||
unreadChatsCount: 0,
|
||||
meta: Meta(
|
||||
currentPage: 1,
|
||||
from: null,
|
||||
lastPage: 1,
|
||||
links: [],
|
||||
perPage: 10,
|
||||
to: null,
|
||||
total: 0,
|
||||
),
|
||||
);
|
||||
final paginationFixture = FixtureReader.readAsMap('chat/chat_room_pagination_response.json');
|
||||
final expectedPagination = ChatRoomPaginationModel.fromJson(paginationFixture);
|
||||
|
||||
when(mockChatService.getChatRooms(query: null, page: 1))
|
||||
.thenAnswer((_) async => expectedPagination);
|
||||
@@ -190,24 +146,14 @@ void main() {
|
||||
final result = await chatRepository.getChatRooms();
|
||||
|
||||
expect(result, isA<ChatRoomPaginationModel>());
|
||||
expect(result.data.length, 2);
|
||||
verify(mockChatService.getChatRooms(query: null, page: 1)).called(1);
|
||||
});
|
||||
|
||||
test('getChatRooms - получает список комнат с запросом', () async {
|
||||
const query = 'test query';
|
||||
const expectedPagination = ChatRoomPaginationModel(
|
||||
data: [],
|
||||
unreadChatsCount: 0,
|
||||
meta: Meta(
|
||||
currentPage: 1,
|
||||
from: null,
|
||||
lastPage: 1,
|
||||
links: [],
|
||||
perPage: 10,
|
||||
to: null,
|
||||
total: 0,
|
||||
),
|
||||
);
|
||||
final paginationFixture = FixtureReader.readAsMap('chat/chat_room_pagination_response.json');
|
||||
final expectedPagination = ChatRoomPaginationModel.fromJson(paginationFixture);
|
||||
|
||||
when(mockChatService.getChatRooms(query: query, page: 1))
|
||||
.thenAnswer((_) async => expectedPagination);
|
||||
@@ -243,23 +189,10 @@ void main() {
|
||||
});
|
||||
|
||||
test('getChatMessages - получает сообщения чата', () async {
|
||||
const chatId = 'chat-id-123';
|
||||
const chatId = 'chat-1';
|
||||
const page = 1;
|
||||
final expectedMessages = ChatMessagesModel(
|
||||
messagesList: [
|
||||
ChatMessageModel(
|
||||
id: 1,
|
||||
data: 'Message 1',
|
||||
mediaData: null,
|
||||
authorId: 1,
|
||||
updatedAt: DateTime.now(),
|
||||
isRead: false,
|
||||
isCurrentUserAuthor: true,
|
||||
roomId: chatId,
|
||||
),
|
||||
],
|
||||
meta: const ChatMetaModel(lastPage: 1),
|
||||
);
|
||||
final messagesFixture = FixtureReader.readAsMap('chat/chat_messages_response.json');
|
||||
final expectedMessages = ChatMessagesModel.fromJson(messagesFixture);
|
||||
|
||||
when(mockChatService.getChatMessages(id: chatId, page: page))
|
||||
.thenAnswer((_) async => expectedMessages);
|
||||
@@ -267,34 +200,14 @@ void main() {
|
||||
final result = await chatRepository.getChatMessages(chatId, page);
|
||||
|
||||
expect(result, isA<ChatMessagesModel>());
|
||||
expect(result.messagesList.length, 1);
|
||||
expect(result.messagesList.length, 2);
|
||||
verify(mockChatService.getChatMessages(id: chatId, page: page)).called(1);
|
||||
});
|
||||
|
||||
test('getChatRoomIdByUserSlug - получает комнату по slug пользователя', () async {
|
||||
const slug = 'user-slug';
|
||||
const expectedRoom = chat_room.ChatRoomModel(
|
||||
id: 'room-id',
|
||||
chatRoomSettings: ChatRoomSettingsModel(
|
||||
name: 'Test Room',
|
||||
state: 'active',
|
||||
),
|
||||
users: chat_room.Users(
|
||||
sender: ChatUserModel(
|
||||
id: 1,
|
||||
slug: slug,
|
||||
name: 'User',
|
||||
profilePhotoUrl: null,
|
||||
),
|
||||
receiver: ChatUserModel(
|
||||
id: 2,
|
||||
slug: 'other-user',
|
||||
name: 'Other User',
|
||||
profilePhotoUrl: null,
|
||||
),
|
||||
),
|
||||
chosenPlanId: null,
|
||||
);
|
||||
const slug = 'user-1';
|
||||
final roomFixture = FixtureReader.readAsMap('chat/chat_room_response.json');
|
||||
final expectedRoom = chat_room.ChatRoomModel.fromJson(roomFixture);
|
||||
|
||||
when(mockChatService.getChatRoomIdByUserSlug(user: slug))
|
||||
.thenAnswer((_) async => expectedRoom);
|
||||
@@ -347,7 +260,8 @@ void main() {
|
||||
|
||||
test('getPaymentLink - получает ссылку на оплату', () async {
|
||||
const planId = 123;
|
||||
final expectedPayment = PaymentModel(paymentUrl: 'https://payment.url');
|
||||
final paymentFixture = FixtureReader.readAsMap('chat/payment_response.json');
|
||||
final expectedPayment = PaymentModel.fromJson(paymentFixture);
|
||||
|
||||
when(mockChatService.getPaymentLink(id: planId))
|
||||
.thenAnswer((_) async => expectedPayment);
|
||||
@@ -355,49 +269,14 @@ void main() {
|
||||
final result = await chatRepository.getPaymentLink(id: planId);
|
||||
|
||||
expect(result, isA<PaymentModel>());
|
||||
expect(result.paymentUrl, 'https://payment.url');
|
||||
expect(result.paymentUrl, 'https://example.com/checkout/payment-123');
|
||||
verify(mockChatService.getPaymentLink(id: planId)).called(1);
|
||||
});
|
||||
|
||||
test('getChosenPlan - получает выбранный план', () async {
|
||||
const planId = 123;
|
||||
final expectedPlan = ChosenPlanModel(
|
||||
id: planId,
|
||||
optionType: 'standard',
|
||||
startDate: DateTime.now(),
|
||||
chosenPlanState: ChosenPlanStateEnum.stateInCoordination,
|
||||
chatId: 'chat-id',
|
||||
consultantId: 1,
|
||||
plan: const PlanModel(
|
||||
id: 456,
|
||||
slug: 'plan-slug',
|
||||
name: 'Test Plan',
|
||||
image: '',
|
||||
duration: 30,
|
||||
state: 'active',
|
||||
type: PlanType(
|
||||
fit: true,
|
||||
slim: false,
|
||||
behavior: false,
|
||||
wellness: false,
|
||||
),
|
||||
details: '',
|
||||
packetsCount: 1,
|
||||
author: Author(
|
||||
authorSlug: 'author',
|
||||
authorName: 'Author',
|
||||
authorProfileIcon: '',
|
||||
authorIsMe: false,
|
||||
),
|
||||
totalLikes: 0,
|
||||
totalViews: 0,
|
||||
totalComments: 0,
|
||||
isFavorite: false,
|
||||
minPriceOfOptions: 0.0,
|
||||
maxPriceOfOptions: 100.0,
|
||||
wasLikedByMe: false,
|
||||
),
|
||||
);
|
||||
const planId = 1;
|
||||
final chosenPlanFixture = FixtureReader.readAsMap('chat/chosen_plan_response.json');
|
||||
final expectedPlan = ChosenPlanModel.fromJson(chosenPlanFixture);
|
||||
|
||||
when(mockChatService.getChosenPlan(id: planId))
|
||||
.thenAnswer((_) async => expectedPlan);
|
||||
@@ -422,7 +301,8 @@ void main() {
|
||||
|
||||
test('complainAboutConsultation - отправляет жалобу на консультацию', () async {
|
||||
const planId = 123;
|
||||
final complainModel = PlanComplainModel(description: 'Test complaint');
|
||||
final complainFixture = FixtureReader.readAsMap('chat/plan_complain_response.json');
|
||||
final complainModel = PlanComplainModel.fromJson(complainFixture);
|
||||
|
||||
when(mockChatService.complainAboutConsultation(id: planId, body: complainModel))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
|
||||
@@ -1,23 +1,16 @@
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/core/models/pagination_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_message_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_messages_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_meta_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_room_model.dart' as chat_room;
|
||||
import 'package:eatvio_app/features/chat/models/chat_room_pagination_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_room_settings_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/chat_user_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/payment_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/plan_complain_model.dart';
|
||||
import 'package:eatvio_app/features/chat/services/chat_service.dart';
|
||||
import 'package:eatvio_app/features/plans/enums/chosen_plan_state_enum.dart';
|
||||
import 'package:eatvio_app/features/plans/models/chosen_plan_model.dart';
|
||||
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart';
|
||||
import 'package:eatvio_app/features/feed/models/diets_pagination_model.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/annotations.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:retrofit/retrofit.dart';
|
||||
import '../../../fixtures/fixture_reader.dart';
|
||||
import 'chat_service_test.mocks.dart';
|
||||
|
||||
@GenerateNiceMocks([MockSpec<ChatService>()])
|
||||
@@ -30,48 +23,24 @@ void main() {
|
||||
});
|
||||
|
||||
test('getChatRooms - возвращает список комнат чата', () async {
|
||||
const expectedPagination = ChatRoomPaginationModel(
|
||||
data: [],
|
||||
unreadChatsCount: 0,
|
||||
meta: Meta(
|
||||
currentPage: 1,
|
||||
from: null,
|
||||
lastPage: 1,
|
||||
links: [],
|
||||
perPage: 10,
|
||||
to: null,
|
||||
total: 0,
|
||||
),
|
||||
);
|
||||
final paginationFixture = FixtureReader.readAsMap('chat/chat_room_pagination_response.json');
|
||||
final expectedPagination = ChatRoomPaginationModel.fromJson(paginationFixture);
|
||||
|
||||
when(mockChatService.getChatRooms(query: null, page: 1))
|
||||
.thenAnswer((_) async => expectedPagination);
|
||||
when(mockChatService.getChatRooms(query: null, page: 1)).thenAnswer((_) async => expectedPagination);
|
||||
|
||||
final result = await mockChatService.getChatRooms(query: null, page: 1);
|
||||
|
||||
expect(result, isA<ChatRoomPaginationModel>());
|
||||
expect(result.data.length, 0);
|
||||
expect(result.data.length, 2);
|
||||
verify(mockChatService.getChatRooms(query: null, page: 1)).called(1);
|
||||
});
|
||||
|
||||
test('getChatRooms - возвращает список комнат с запросом', () async {
|
||||
const query = 'test query';
|
||||
const expectedPagination = ChatRoomPaginationModel(
|
||||
data: [],
|
||||
unreadChatsCount: 0,
|
||||
meta: Meta(
|
||||
currentPage: 1,
|
||||
from: null,
|
||||
lastPage: 1,
|
||||
links: [],
|
||||
perPage: 10,
|
||||
to: null,
|
||||
total: 0,
|
||||
),
|
||||
);
|
||||
final paginationFixture = FixtureReader.readAsMap('chat/chat_room_pagination_response.json');
|
||||
final expectedPagination = ChatRoomPaginationModel.fromJson(paginationFixture);
|
||||
|
||||
when(mockChatService.getChatRooms(query: query, page: 1))
|
||||
.thenAnswer((_) async => expectedPagination);
|
||||
when(mockChatService.getChatRooms(query: query, page: 1)).thenAnswer((_) async => expectedPagination);
|
||||
|
||||
final result = await mockChatService.getChatRooms(query: query, page: 1);
|
||||
|
||||
@@ -80,32 +49,11 @@ void main() {
|
||||
});
|
||||
|
||||
test('getChatRoom - возвращает комнату чата по UUID', () async {
|
||||
const uuid = 'room-uuid-123';
|
||||
const expectedRoom = chat_room.ChatRoomModel(
|
||||
id: uuid,
|
||||
chatRoomSettings: ChatRoomSettingsModel(
|
||||
name: 'Test Room',
|
||||
state: 'active',
|
||||
),
|
||||
users: chat_room.Users(
|
||||
sender: ChatUserModel(
|
||||
id: 1,
|
||||
slug: 'user-1',
|
||||
name: 'User 1',
|
||||
profilePhotoUrl: null,
|
||||
),
|
||||
receiver: ChatUserModel(
|
||||
id: 2,
|
||||
slug: 'user-2',
|
||||
name: 'User 2',
|
||||
profilePhotoUrl: null,
|
||||
),
|
||||
),
|
||||
chosenPlanId: null,
|
||||
);
|
||||
const uuid = 'chat-1';
|
||||
final roomFixture = FixtureReader.readAsMap('chat/chat_room_response.json');
|
||||
final expectedRoom = chat_room.ChatRoomModel.fromJson(roomFixture);
|
||||
|
||||
when(mockChatService.getChatRoom(uuid: uuid))
|
||||
.thenAnswer((_) async => expectedRoom);
|
||||
when(mockChatService.getChatRoom(uuid: uuid)).thenAnswer((_) async => expectedRoom);
|
||||
|
||||
final result = await mockChatService.getChatRoom(uuid: uuid);
|
||||
|
||||
@@ -119,84 +67,34 @@ void main() {
|
||||
const data = 'Test message';
|
||||
const socketId = 'socket-id-123';
|
||||
|
||||
when(mockChatService.sendMessage(
|
||||
slug: slug,
|
||||
data: data,
|
||||
mediaData: null,
|
||||
socketId: socketId,
|
||||
)).thenAnswer((_) async => Future.value());
|
||||
when(mockChatService.sendMessage(slug: slug, data: data, mediaData: null, socketId: socketId)).thenAnswer((_) async => Future.value());
|
||||
|
||||
await mockChatService.sendMessage(
|
||||
slug: slug,
|
||||
data: data,
|
||||
mediaData: null,
|
||||
socketId: socketId,
|
||||
);
|
||||
await mockChatService.sendMessage(slug: slug, data: data, mediaData: null, socketId: socketId);
|
||||
|
||||
verify(mockChatService.sendMessage(
|
||||
slug: slug,
|
||||
data: data,
|
||||
mediaData: null,
|
||||
socketId: socketId,
|
||||
)).called(1);
|
||||
verify(mockChatService.sendMessage(slug: slug, data: data, mediaData: null, socketId: socketId)).called(1);
|
||||
});
|
||||
|
||||
test('getChatMessages - возвращает сообщения чата', () async {
|
||||
const chatId = 'chat-id-123';
|
||||
const chatId = 'chat-1';
|
||||
const page = 1;
|
||||
final expectedMessages = ChatMessagesModel(
|
||||
messagesList: [
|
||||
ChatMessageModel(
|
||||
id: 1,
|
||||
data: 'Message 1',
|
||||
mediaData: null,
|
||||
authorId: 1,
|
||||
updatedAt: DateTime.now(),
|
||||
isRead: false,
|
||||
isCurrentUserAuthor: true,
|
||||
roomId: chatId,
|
||||
),
|
||||
],
|
||||
meta: const ChatMetaModel(lastPage: 1),
|
||||
);
|
||||
final messagesFixture = FixtureReader.readAsMap('chat/chat_messages_response.json');
|
||||
final expectedMessages = ChatMessagesModel.fromJson(messagesFixture);
|
||||
|
||||
when(mockChatService.getChatMessages(id: chatId, page: page))
|
||||
.thenAnswer((_) async => expectedMessages);
|
||||
when(mockChatService.getChatMessages(id: chatId, page: page)).thenAnswer((_) async => expectedMessages);
|
||||
|
||||
final result = await mockChatService.getChatMessages(id: chatId, page: page);
|
||||
|
||||
expect(result, isA<ChatMessagesModel>());
|
||||
expect(result.messagesList.length, 1);
|
||||
expect(result.messagesList.length, 2);
|
||||
verify(mockChatService.getChatMessages(id: chatId, page: page)).called(1);
|
||||
});
|
||||
|
||||
test('getChatRoomIdByUserSlug - возвращает комнату по slug пользователя', () async {
|
||||
const slug = 'user-slug';
|
||||
const expectedRoom = chat_room.ChatRoomModel(
|
||||
id: 'room-id',
|
||||
chatRoomSettings: ChatRoomSettingsModel(
|
||||
name: 'Test Room',
|
||||
state: 'active',
|
||||
),
|
||||
users: chat_room.Users(
|
||||
sender: ChatUserModel(
|
||||
id: 1,
|
||||
slug: slug,
|
||||
name: 'User',
|
||||
profilePhotoUrl: null,
|
||||
),
|
||||
receiver: ChatUserModel(
|
||||
id: 2,
|
||||
slug: 'other-user',
|
||||
name: 'Other User',
|
||||
profilePhotoUrl: null,
|
||||
),
|
||||
),
|
||||
chosenPlanId: null,
|
||||
);
|
||||
const slug = 'user-1';
|
||||
final roomFixture = FixtureReader.readAsMap('chat/chat_room_response.json');
|
||||
final expectedRoom = chat_room.ChatRoomModel.fromJson(roomFixture);
|
||||
|
||||
when(mockChatService.getChatRoomIdByUserSlug(user: slug))
|
||||
.thenAnswer((_) async => expectedRoom);
|
||||
when(mockChatService.getChatRoomIdByUserSlug(user: slug)).thenAnswer((_) async => expectedRoom);
|
||||
|
||||
final result = await mockChatService.getChatRoomIdByUserSlug(user: slug);
|
||||
|
||||
@@ -208,27 +106,17 @@ void main() {
|
||||
const chatId = 'chat-id-123';
|
||||
final messageIds = [1, 2, 3];
|
||||
|
||||
when(mockChatService.markMessagesAsRead(
|
||||
id: chatId,
|
||||
body: {'messages_ids': messageIds},
|
||||
)).thenAnswer((_) async => Future.value());
|
||||
when(mockChatService.markMessagesAsRead(id: chatId, body: {'messages_ids': messageIds})).thenAnswer((_) async => Future.value());
|
||||
|
||||
await mockChatService.markMessagesAsRead(
|
||||
id: chatId,
|
||||
body: {'messages_ids': messageIds},
|
||||
);
|
||||
await mockChatService.markMessagesAsRead(id: chatId, body: {'messages_ids': messageIds});
|
||||
|
||||
verify(mockChatService.markMessagesAsRead(
|
||||
id: chatId,
|
||||
body: {'messages_ids': messageIds},
|
||||
)).called(1);
|
||||
verify(mockChatService.markMessagesAsRead(id: chatId, body: {'messages_ids': messageIds})).called(1);
|
||||
});
|
||||
|
||||
test('cancelChosenPlan - отменяет выбранный план', () async {
|
||||
const planId = 123;
|
||||
|
||||
when(mockChatService.cancelChosenPlan(id: planId))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
when(mockChatService.cancelChosenPlan(id: planId)).thenAnswer((_) async => Future.value());
|
||||
|
||||
await mockChatService.cancelChosenPlan(id: planId);
|
||||
|
||||
@@ -239,8 +127,7 @@ void main() {
|
||||
const planId = 123;
|
||||
final date = {'start_date': '2024-01-15'};
|
||||
|
||||
when(mockChatService.choseStartPlanDate(id: planId, date: date))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
when(mockChatService.choseStartPlanDate(id: planId, date: date)).thenAnswer((_) async => Future.value());
|
||||
|
||||
await mockChatService.choseStartPlanDate(id: planId, date: date);
|
||||
|
||||
@@ -249,60 +136,24 @@ void main() {
|
||||
|
||||
test('getPaymentLink - возвращает ссылку на оплату', () async {
|
||||
const planId = 123;
|
||||
final expectedPayment = PaymentModel(paymentUrl: 'https://payment.url');
|
||||
final paymentFixture = FixtureReader.readAsMap('chat/payment_response.json');
|
||||
final expectedPayment = PaymentModel.fromJson(paymentFixture);
|
||||
|
||||
when(mockChatService.getPaymentLink(id: planId))
|
||||
.thenAnswer((_) async => expectedPayment);
|
||||
when(mockChatService.getPaymentLink(id: planId)).thenAnswer((_) async => expectedPayment);
|
||||
|
||||
final result = await mockChatService.getPaymentLink(id: planId);
|
||||
|
||||
expect(result, isA<PaymentModel>());
|
||||
expect(result.paymentUrl, 'https://payment.url');
|
||||
expect(result.paymentUrl, 'https://example.com/checkout/payment-123');
|
||||
verify(mockChatService.getPaymentLink(id: planId)).called(1);
|
||||
});
|
||||
|
||||
test('getChosenPlan - возвращает выбранный план', () async {
|
||||
const planId = 123;
|
||||
final expectedPlan = ChosenPlanModel(
|
||||
id: planId,
|
||||
optionType: 'standard',
|
||||
startDate: DateTime.now(),
|
||||
chosenPlanState: ChosenPlanStateEnum.stateInCoordination,
|
||||
chatId: 'chat-id',
|
||||
consultantId: 1,
|
||||
plan: const PlanModel(
|
||||
id: 456,
|
||||
slug: 'plan-slug',
|
||||
name: 'Test Plan',
|
||||
image: '',
|
||||
duration: 30,
|
||||
state: 'active',
|
||||
type: PlanType(
|
||||
fit: true,
|
||||
slim: false,
|
||||
behavior: false,
|
||||
wellness: false,
|
||||
),
|
||||
details: '',
|
||||
packetsCount: 1,
|
||||
author: Author(
|
||||
authorSlug: 'author',
|
||||
authorName: 'Author',
|
||||
authorProfileIcon: '',
|
||||
authorIsMe: false,
|
||||
),
|
||||
totalLikes: 0,
|
||||
totalViews: 0,
|
||||
totalComments: 0,
|
||||
isFavorite: false,
|
||||
minPriceOfOptions: 0.0,
|
||||
maxPriceOfOptions: 100.0,
|
||||
wasLikedByMe: false,
|
||||
),
|
||||
);
|
||||
const planId = 1;
|
||||
final chosenPlanFixture = FixtureReader.readAsMap('chat/chosen_plan_response.json');
|
||||
final expectedPlan = ChosenPlanModel.fromJson(chosenPlanFixture);
|
||||
|
||||
when(mockChatService.getChosenPlan(id: planId))
|
||||
.thenAnswer((_) async => expectedPlan);
|
||||
when(mockChatService.getChosenPlan(id: planId)).thenAnswer((_) async => expectedPlan);
|
||||
|
||||
final result = await mockChatService.getChosenPlan(id: planId);
|
||||
|
||||
@@ -314,8 +165,7 @@ void main() {
|
||||
test('finishChosenPlan - завершает выбранный план', () async {
|
||||
const planId = 123;
|
||||
|
||||
when(mockChatService.finishChosenPlan(id: planId))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
when(mockChatService.finishChosenPlan(id: planId)).thenAnswer((_) async => Future.value());
|
||||
|
||||
await mockChatService.finishChosenPlan(id: planId);
|
||||
|
||||
@@ -324,30 +174,22 @@ void main() {
|
||||
|
||||
test('complainAboutConsultation - отправляет жалобу на консультацию', () async {
|
||||
const planId = 123;
|
||||
final complainModel = PlanComplainModel(description: 'Test complaint');
|
||||
final complainFixture = FixtureReader.readAsMap('chat/plan_complain_response.json');
|
||||
final complainModel = PlanComplainModel.fromJson(complainFixture);
|
||||
|
||||
when(mockChatService.complainAboutConsultation(id: planId, body: complainModel))
|
||||
.thenAnswer((_) async => Future.value());
|
||||
when(mockChatService.complainAboutConsultation(id: planId, body: complainModel)).thenAnswer((_) async => Future.value());
|
||||
|
||||
await mockChatService.complainAboutConsultation(id: planId, body: complainModel);
|
||||
|
||||
verify(mockChatService.complainAboutConsultation(id: planId, body: complainModel))
|
||||
.called(1);
|
||||
verify(mockChatService.complainAboutConsultation(id: planId, body: complainModel)).called(1);
|
||||
});
|
||||
|
||||
test('getChatByUserSlug - возвращает HttpResponse', () async {
|
||||
const slug = 'user-slug';
|
||||
const chatId = 'chat-id-123';
|
||||
final response = HttpResponse(
|
||||
{'id': chatId},
|
||||
Response(
|
||||
requestOptions: RequestOptions(path: ''),
|
||||
statusCode: 200,
|
||||
),
|
||||
);
|
||||
final response = HttpResponse({'id': chatId}, Response(requestOptions: RequestOptions(path: ''), statusCode: 200));
|
||||
|
||||
when(mockChatService.getChatByUserSlug(slug: slug))
|
||||
.thenAnswer((_) async => response);
|
||||
when(mockChatService.getChatByUserSlug(slug: slug)).thenAnswer((_) async => response);
|
||||
|
||||
final result = await mockChatService.getChatByUserSlug(slug: slug);
|
||||
|
||||
@@ -357,4 +199,3 @@ void main() {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user