forked from eatvio/eatvio_app
feat(chat): reorganize test fixtures
This commit is contained in:
@@ -5,7 +5,8 @@ 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_room_model.dart' as chat_room;
|
||||
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/payment_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/plan_complain_model.dart';
|
||||
@@ -32,7 +33,9 @@ void main() {
|
||||
});
|
||||
|
||||
test('emitNewMessageToChats - эмитит новое сообщение в поток', () async {
|
||||
final messageFixture = FixtureReader.readAsMap('chat/chat_message_response.json');
|
||||
final messageFixture = FixtureReader.readAsMap(
|
||||
'chat/chat_message_response.json',
|
||||
);
|
||||
final message = ChatMessageModel.fromJson(messageFixture);
|
||||
|
||||
chatRepository.emitNewMessageToChats(message);
|
||||
@@ -45,12 +48,14 @@ 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());
|
||||
|
||||
// Note: SocketIdStorage is static and can't be easily mocked
|
||||
// This test verifies the repository calls the service correctly
|
||||
@@ -68,12 +73,14 @@ void main() {
|
||||
const data = 'Test message with files';
|
||||
const socketId = 'socket-id-123';
|
||||
|
||||
when(mockChatService.sendMessage(
|
||||
slug: slug,
|
||||
data: data,
|
||||
mediaData: anyNamed('mediaData'),
|
||||
socketId: socketId,
|
||||
)).thenAnswer((_) async => Future.value());
|
||||
when(
|
||||
mockChatService.sendMessage(
|
||||
slug: slug,
|
||||
data: data,
|
||||
mediaData: anyNamed('mediaData'),
|
||||
socketId: socketId,
|
||||
),
|
||||
).thenAnswer((_) async => Future.value());
|
||||
|
||||
// Создаем временные файлы для теста
|
||||
final tempFile1 = File('test1.jpg');
|
||||
@@ -113,11 +120,14 @@ void main() {
|
||||
|
||||
test('getChatRoom - получает комнату чата по UUID', () async {
|
||||
const uuid = 'chat-1';
|
||||
final roomFixture = FixtureReader.readAsMap('chat/chat_room_response.json');
|
||||
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 chatRepository.getChatRoom(uuid);
|
||||
|
||||
@@ -132,18 +142,20 @@ void main() {
|
||||
|
||||
when(mockChatService.getChatRoom(uuid: uuid)).thenThrow(error);
|
||||
|
||||
expect(
|
||||
() => chatRepository.getChatRoom(uuid),
|
||||
throwsException,
|
||||
);
|
||||
expect(() => chatRepository.getChatRoom(uuid), throwsException);
|
||||
});
|
||||
|
||||
test('getChatRooms - получает список комнат чата', () async {
|
||||
final paginationFixture = FixtureReader.readAsMap('chat/chat_room_pagination_response.json');
|
||||
final expectedPagination = ChatRoomPaginationModel.fromJson(paginationFixture);
|
||||
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 chatRepository.getChatRooms();
|
||||
|
||||
@@ -154,11 +166,16 @@ void main() {
|
||||
|
||||
test('getChatRooms - получает список комнат с запросом', () async {
|
||||
const query = 'test query';
|
||||
final paginationFixture = FixtureReader.readAsMap('chat/chat_room_pagination_response.json');
|
||||
final expectedPagination = ChatRoomPaginationModel.fromJson(paginationFixture);
|
||||
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 chatRepository.getChatRooms(query: query);
|
||||
|
||||
@@ -181,8 +198,9 @@ void main() {
|
||||
),
|
||||
);
|
||||
|
||||
when(mockChatService.getChatRooms(query: null, page: 2))
|
||||
.thenAnswer((_) async => expectedPagination);
|
||||
when(
|
||||
mockChatService.getChatRooms(query: null, page: 2),
|
||||
).thenAnswer((_) async => expectedPagination);
|
||||
|
||||
final result = await chatRepository.getChatRooms(page: 2);
|
||||
|
||||
@@ -193,11 +211,14 @@ void main() {
|
||||
test('getChatMessages - получает сообщения чата', () async {
|
||||
const chatId = 'chat-1';
|
||||
const page = 1;
|
||||
final messagesFixture = FixtureReader.readAsMap('chat/chat_messages_response.json');
|
||||
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 chatRepository.getChatMessages(chatId, page);
|
||||
|
||||
@@ -206,42 +227,53 @@ void main() {
|
||||
verify(mockChatService.getChatMessages(id: chatId, page: page)).called(1);
|
||||
});
|
||||
|
||||
test('getChatRoomIdByUserSlug - получает комнату по slug пользователя', () async {
|
||||
const slug = 'user-1';
|
||||
final roomFixture = FixtureReader.readAsMap('chat/chat_room_response.json');
|
||||
final expectedRoom = chat_room.ChatRoomModel.fromJson(roomFixture);
|
||||
test(
|
||||
'getChatRoomIdByUserSlug - получает комнату по slug пользователя',
|
||||
() async {
|
||||
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 chatRepository.getChatRoomIdByUserSlug(slug: slug);
|
||||
final result = await chatRepository.getChatRoomIdByUserSlug(slug: slug);
|
||||
|
||||
expect(result, isA<chat_room.ChatRoomModel>());
|
||||
verify(mockChatService.getChatRoomIdByUserSlug(user: slug)).called(1);
|
||||
});
|
||||
expect(result, isA<chat_room.ChatRoomModel>());
|
||||
verify(mockChatService.getChatRoomIdByUserSlug(user: slug)).called(1);
|
||||
},
|
||||
);
|
||||
|
||||
test('markMessagesAsRead - отмечает сообщения как прочитанные', () async {
|
||||
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 chatRepository.markMessagesAsRead(chatId, 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 chatRepository.cancelChosenPlan(id: planId);
|
||||
|
||||
@@ -252,21 +284,27 @@ 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 chatRepository.choseStartPlanDate(id: planId, date: date);
|
||||
|
||||
verify(mockChatService.choseStartPlanDate(id: planId, date: date)).called(1);
|
||||
verify(
|
||||
mockChatService.choseStartPlanDate(id: planId, date: date),
|
||||
).called(1);
|
||||
});
|
||||
|
||||
test('getPaymentLink - получает ссылку на оплату', () async {
|
||||
const planId = 123;
|
||||
final paymentFixture = FixtureReader.readAsMap('chat/payment_response.json');
|
||||
final paymentFixture = FixtureReader.readAsMap(
|
||||
'chat/payments/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 chatRepository.getPaymentLink(id: planId);
|
||||
|
||||
@@ -277,11 +315,14 @@ void main() {
|
||||
|
||||
test('getChosenPlan - получает выбранный план', () async {
|
||||
const planId = 1;
|
||||
final chosenPlanFixture = FixtureReader.readAsMap('chat/chosen_plan_response.json');
|
||||
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 chatRepository.getChosenPlan(id: planId);
|
||||
|
||||
@@ -293,63 +334,75 @@ 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 chatRepository.finishChosenPlan(id: planId);
|
||||
|
||||
verify(mockChatService.finishChosenPlan(id: planId)).called(1);
|
||||
});
|
||||
|
||||
test('complainAboutConsultation - отправляет жалобу на консультацию', () async {
|
||||
const planId = 123;
|
||||
final complainFixture = FixtureReader.readAsMap('chat/plan_complain_response.json');
|
||||
final complainModel = PlanComplainModel.fromJson(complainFixture);
|
||||
test(
|
||||
'complainAboutConsultation - отправляет жалобу на консультацию',
|
||||
() async {
|
||||
const planId = 123;
|
||||
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 chatRepository.complainAboutConsultation(
|
||||
id: planId,
|
||||
body: complainModel,
|
||||
);
|
||||
await chatRepository.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 - возвращает ID чата при успешном ответе', () async {
|
||||
const slug = 'user-slug';
|
||||
const chatId = 'chat-id-123';
|
||||
final response = HttpResponse(
|
||||
{'id': chatId},
|
||||
Response(
|
||||
requestOptions: RequestOptions(path: ''),
|
||||
statusCode: 200,
|
||||
),
|
||||
);
|
||||
test(
|
||||
'getChatByUserSlug - возвращает ID чата при успешном ответе',
|
||||
() async {
|
||||
const slug = 'user-slug';
|
||||
const chatId = 'chat-id-123';
|
||||
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 chatRepository.getChatByUserSlug(slug);
|
||||
final result = await chatRepository.getChatByUserSlug(slug);
|
||||
|
||||
expect(result, chatId);
|
||||
verify(mockChatService.getChatByUserSlug(slug: slug)).called(1);
|
||||
});
|
||||
expect(result, chatId);
|
||||
verify(mockChatService.getChatByUserSlug(slug: slug)).called(1);
|
||||
},
|
||||
);
|
||||
|
||||
test('getChatByUserSlug - возвращает 404 при отсутствии чата', () async {
|
||||
const slug = 'user-slug';
|
||||
final response = HttpResponse(
|
||||
{},
|
||||
Response(
|
||||
requestOptions: RequestOptions(path: ''),
|
||||
statusCode: 404,
|
||||
),
|
||||
Response(requestOptions: RequestOptions(path: ''), statusCode: 404),
|
||||
);
|
||||
|
||||
when(mockChatService.getChatByUserSlug(slug: slug))
|
||||
.thenAnswer((_) async => response);
|
||||
when(
|
||||
mockChatService.getChatByUserSlug(slug: slug),
|
||||
).thenAnswer((_) async => response);
|
||||
|
||||
final result = await chatRepository.getChatByUserSlug(slug);
|
||||
|
||||
@@ -357,17 +410,20 @@ void main() {
|
||||
verify(mockChatService.getChatByUserSlug(slug: slug)).called(1);
|
||||
});
|
||||
|
||||
test('getChatByUserSlug - пробрасывает исключение при ошибке сети', () async {
|
||||
const slug = 'user-slug';
|
||||
test(
|
||||
'getChatByUserSlug - пробрасывает исключение при ошибке сети',
|
||||
() async {
|
||||
const slug = 'user-slug';
|
||||
|
||||
when(mockChatService.getChatByUserSlug(slug: slug))
|
||||
.thenThrow(Exception('Network error'));
|
||||
when(
|
||||
mockChatService.getChatByUserSlug(slug: slug),
|
||||
).thenThrow(Exception('Network error'));
|
||||
|
||||
await expectLater(
|
||||
chatRepository.getChatByUserSlug(slug),
|
||||
throwsA(isA<Exception>()),
|
||||
);
|
||||
});
|
||||
await expectLater(
|
||||
chatRepository.getChatByUserSlug(slug),
|
||||
throwsA(isA<Exception>()),
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import 'package:dio/dio.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_room_model.dart' as chat_room;
|
||||
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/payment_model.dart';
|
||||
import 'package:eatvio_app/features/chat/models/plan_complain_model.dart';
|
||||
@@ -24,10 +25,16 @@ void main() {
|
||||
});
|
||||
|
||||
test('getChatRooms - возвращает список комнат чата', () async {
|
||||
final paginationFixture = FixtureReader.readAsMap('chat/chat_room_pagination_response.json');
|
||||
final expectedPagination = ChatRoomPaginationModel.fromJson(paginationFixture);
|
||||
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);
|
||||
|
||||
@@ -38,10 +45,16 @@ void main() {
|
||||
|
||||
test('getChatRooms - возвращает список комнат с запросом', () async {
|
||||
const query = 'test query';
|
||||
final paginationFixture = FixtureReader.readAsMap('chat/chat_room_pagination_response.json');
|
||||
final expectedPagination = ChatRoomPaginationModel.fromJson(paginationFixture);
|
||||
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);
|
||||
|
||||
@@ -51,10 +64,14 @@ void main() {
|
||||
|
||||
test('getChatRoom - возвращает комнату чата по UUID', () async {
|
||||
const uuid = 'chat-1';
|
||||
final roomFixture = FixtureReader.readAsMap('chat/chat_room_response.json');
|
||||
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);
|
||||
|
||||
@@ -67,62 +84,114 @@ void main() {
|
||||
const slug = 'user-slug';
|
||||
const data = 'Test message';
|
||||
const socketId = 'socket-id-123';
|
||||
final messageFixture = FixtureReader.readAsMap('chat/chat_message_response.json');
|
||||
final messageFixture = FixtureReader.readAsMap(
|
||||
'chat/chat_message_response.json',
|
||||
);
|
||||
final expectedMessage = ChatMessageModel.fromJson(messageFixture);
|
||||
|
||||
// ignore: null_argument_to_non_null_type
|
||||
when(mockChatService.sendMessage(slug: slug, data: data, mediaData: null, socketId: socketId)).thenAnswer((_) async => expectedMessage);
|
||||
when(
|
||||
mockChatService.sendMessage(
|
||||
slug: slug,
|
||||
data: data,
|
||||
mediaData: null,
|
||||
socketId: socketId,
|
||||
),
|
||||
).thenAnswer((_) async => expectedMessage);
|
||||
|
||||
final result = await mockChatService.sendMessage(slug: slug, data: data, mediaData: null, socketId: socketId);
|
||||
final result = await mockChatService.sendMessage(
|
||||
slug: slug,
|
||||
data: data,
|
||||
mediaData: null,
|
||||
socketId: socketId,
|
||||
);
|
||||
|
||||
expect(result, isA<ChatMessageModel>());
|
||||
expect(result.data, data);
|
||||
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-1';
|
||||
const page = 1;
|
||||
final messagesFixture = FixtureReader.readAsMap('chat/chat_messages_response.json');
|
||||
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);
|
||||
final result = await mockChatService.getChatMessages(
|
||||
id: chatId,
|
||||
page: page,
|
||||
);
|
||||
|
||||
expect(result, isA<ChatMessagesModel>());
|
||||
expect(result.messagesList.length, 2);
|
||||
verify(mockChatService.getChatMessages(id: chatId, page: page)).called(1);
|
||||
});
|
||||
|
||||
test('getChatRoomIdByUserSlug - возвращает комнату по slug пользователя', () async {
|
||||
const slug = 'user-1';
|
||||
final roomFixture = FixtureReader.readAsMap('chat/chat_room_response.json');
|
||||
final expectedRoom = chat_room.ChatRoomModel.fromJson(roomFixture);
|
||||
test(
|
||||
'getChatRoomIdByUserSlug - возвращает комнату по slug пользователя',
|
||||
() async {
|
||||
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);
|
||||
final result = await mockChatService.getChatRoomIdByUserSlug(
|
||||
user: slug,
|
||||
);
|
||||
|
||||
expect(result, isA<chat_room.ChatRoomModel>());
|
||||
verify(mockChatService.getChatRoomIdByUserSlug(user: slug)).called(1);
|
||||
});
|
||||
expect(result, isA<chat_room.ChatRoomModel>());
|
||||
verify(mockChatService.getChatRoomIdByUserSlug(user: slug)).called(1);
|
||||
},
|
||||
);
|
||||
|
||||
test('markMessagesAsRead - отмечает сообщения как прочитанные', () async {
|
||||
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);
|
||||
|
||||
@@ -133,19 +202,27 @@ 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);
|
||||
|
||||
verify(mockChatService.choseStartPlanDate(id: planId, date: date)).called(1);
|
||||
verify(
|
||||
mockChatService.choseStartPlanDate(id: planId, date: date),
|
||||
).called(1);
|
||||
});
|
||||
|
||||
test('getPaymentLink - возвращает ссылку на оплату', () async {
|
||||
const planId = 123;
|
||||
final paymentFixture = FixtureReader.readAsMap('chat/payment_response.json');
|
||||
final paymentFixture = FixtureReader.readAsMap(
|
||||
'chat/payments/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);
|
||||
|
||||
@@ -156,10 +233,14 @@ void main() {
|
||||
|
||||
test('getChosenPlan - возвращает выбранный план', () async {
|
||||
const planId = 1;
|
||||
final chosenPlanFixture = FixtureReader.readAsMap('chat/chosen_plan_response.json');
|
||||
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);
|
||||
|
||||
@@ -171,31 +252,55 @@ 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);
|
||||
|
||||
verify(mockChatService.finishChosenPlan(id: planId)).called(1);
|
||||
});
|
||||
|
||||
test('complainAboutConsultation - отправляет жалобу на консультацию', () async {
|
||||
const planId = 123;
|
||||
final complainFixture = FixtureReader.readAsMap('chat/plan_complain_response.json');
|
||||
final complainModel = PlanComplainModel.fromJson(complainFixture);
|
||||
test(
|
||||
'complainAboutConsultation - отправляет жалобу на консультацию',
|
||||
() async {
|
||||
const planId = 123;
|
||||
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);
|
||||
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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user