@@ -1490,7 +1490,6 @@ void main() {
|
||||
|
||||
test('`.getReplies`', () async {
|
||||
const parentId = 'test-parent-id';
|
||||
const options = PaginationParams();
|
||||
|
||||
final messages = List.generate(
|
||||
3,
|
||||
@@ -1500,22 +1499,21 @@ void main() {
|
||||
),
|
||||
);
|
||||
|
||||
when(() => client.getReplies(parentId, options)).thenAnswer(
|
||||
when(() => client.getReplies(parentId)).thenAnswer(
|
||||
(_) async => QueryRepliesResponse()..messages = messages,
|
||||
);
|
||||
|
||||
final res = await channel.getReplies(parentId, options);
|
||||
final res = await channel.getReplies(parentId);
|
||||
|
||||
expect(res, isNotNull);
|
||||
expect(res.messages.length, messages.length);
|
||||
expect(res.messages.every((it) => it.parentId == parentId), isTrue);
|
||||
|
||||
verify(() => client.getReplies(parentId, options)).called(1);
|
||||
verify(() => client.getReplies(parentId)).called(1);
|
||||
});
|
||||
|
||||
test('`.getReactions`', () async {
|
||||
const messageId = 'test-message-id';
|
||||
const options = PaginationParams();
|
||||
|
||||
final reactions = List.generate(
|
||||
3,
|
||||
@@ -1525,17 +1523,17 @@ void main() {
|
||||
),
|
||||
);
|
||||
|
||||
when(() => client.getReactions(messageId, options)).thenAnswer(
|
||||
when(() => client.getReactions(messageId)).thenAnswer(
|
||||
(_) async => QueryReactionsResponse()..reactions = reactions,
|
||||
);
|
||||
|
||||
final res = await channel.getReactions(messageId, options);
|
||||
final res = await channel.getReactions(messageId);
|
||||
|
||||
expect(res, isNotNull);
|
||||
expect(res.reactions.length, reactions.length);
|
||||
expect(res.reactions.every((it) => it.messageId == messageId), isTrue);
|
||||
|
||||
verify(() => client.getReactions(messageId, options)).called(1);
|
||||
verify(() => client.getReactions(messageId)).called(1);
|
||||
});
|
||||
|
||||
test('`.getMessagesById`', () async {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -252,7 +252,7 @@ void main() {
|
||||
'reactions': [...reactions.map((it) => it.toJson())]
|
||||
}));
|
||||
|
||||
final res = await messageApi.getReactions(messageId, options);
|
||||
final res = await messageApi.getReactions(messageId, options: options);
|
||||
|
||||
expect(res, isNotNull);
|
||||
expect(res.reactions.length, reactions.length);
|
||||
@@ -311,7 +311,7 @@ void main() {
|
||||
'messages': [...messages.map((it) => it.toJson())]
|
||||
}));
|
||||
|
||||
final res = await messageApi.getReplies(parentId, options);
|
||||
final res = await messageApi.getReplies(parentId, options: options);
|
||||
|
||||
expect(res, isNotNull);
|
||||
expect(res.messages.length, messages.length);
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
import 'package:stream_chat/src/core/api/channel_api.dart';
|
||||
import 'package:stream_chat/src/core/api/device_api.dart';
|
||||
import 'package:stream_chat/src/core/api/general_api.dart';
|
||||
@@ -10,6 +13,7 @@ import 'package:stream_chat/src/core/api/user_api.dart';
|
||||
import 'package:stream_chat/src/core/api/guest_api.dart';
|
||||
import 'package:stream_chat/src/core/http/token.dart';
|
||||
import 'package:stream_chat/src/core/http/token_manager.dart';
|
||||
import 'package:stream_chat/src/ws/websocket.dart';
|
||||
import 'package:stream_chat/stream_chat.dart';
|
||||
|
||||
import 'mocks.dart';
|
||||
@@ -96,3 +100,88 @@ class FakeMessage extends Fake implements Message {}
|
||||
class FakeAttachmentFile extends Fake implements AttachmentFile {}
|
||||
|
||||
class FakeEvent extends Fake implements Event {}
|
||||
|
||||
class FakeUser extends Fake implements User {}
|
||||
|
||||
class FakeWebSocket extends Fake implements WebSocket {
|
||||
BehaviorSubject<ConnectionStatus>? _connectionStatusController;
|
||||
|
||||
BehaviorSubject<ConnectionStatus> get connectionStatusController =>
|
||||
_connectionStatusController ??=
|
||||
BehaviorSubject.seeded(ConnectionStatus.disconnected);
|
||||
|
||||
set connectionStatus(ConnectionStatus value) {
|
||||
connectionStatusController.add(value);
|
||||
}
|
||||
|
||||
@override
|
||||
ConnectionStatus get connectionStatus => connectionStatusController.value;
|
||||
|
||||
@override
|
||||
Stream<ConnectionStatus> get connectionStatusStream =>
|
||||
connectionStatusController.stream;
|
||||
|
||||
@override
|
||||
Completer<Event>? connectionCompleter;
|
||||
|
||||
@override
|
||||
Future<Event> connect(User user) async {
|
||||
connectionStatus = ConnectionStatus.connecting;
|
||||
final event = Event(
|
||||
type: EventType.healthCheck,
|
||||
connectionId: 'fake-connection-id',
|
||||
me: OwnUser.fromUser(user),
|
||||
);
|
||||
connectionCompleter = Completer()..complete(event);
|
||||
connectionStatus = ConnectionStatus.connected;
|
||||
return connectionCompleter!.future;
|
||||
}
|
||||
|
||||
@override
|
||||
void disconnect() {
|
||||
connectionStatus = ConnectionStatus.disconnected;
|
||||
connectionCompleter = null;
|
||||
_connectionStatusController?.close();
|
||||
_connectionStatusController = null;
|
||||
}
|
||||
}
|
||||
|
||||
class FakeWebSocketWithConnectionError extends Fake implements WebSocket {
|
||||
BehaviorSubject<ConnectionStatus>? _connectionStatusController;
|
||||
|
||||
BehaviorSubject<ConnectionStatus> get connectionStatusController =>
|
||||
_connectionStatusController ??=
|
||||
BehaviorSubject.seeded(ConnectionStatus.disconnected);
|
||||
|
||||
set connectionStatus(ConnectionStatus value) {
|
||||
connectionStatusController.add(value);
|
||||
}
|
||||
|
||||
@override
|
||||
ConnectionStatus get connectionStatus => connectionStatusController.value;
|
||||
|
||||
@override
|
||||
Stream<ConnectionStatus> get connectionStatusStream =>
|
||||
connectionStatusController.stream;
|
||||
|
||||
@override
|
||||
Completer<Event>? connectionCompleter;
|
||||
|
||||
@override
|
||||
Future<Event> connect(User user) async {
|
||||
connectionStatus = ConnectionStatus.connecting;
|
||||
const error = StreamWebSocketError('Error Connecting');
|
||||
connectionCompleter = Completer()..completeError(error);
|
||||
return connectionCompleter!.future;
|
||||
}
|
||||
|
||||
@override
|
||||
void disconnect() {
|
||||
connectionStatus = ConnectionStatus.disconnected;
|
||||
connectionCompleter = null;
|
||||
_connectionStatusController?.close();
|
||||
_connectionStatusController = null;
|
||||
}
|
||||
}
|
||||
|
||||
class FakeChannelState extends Fake implements ChannelState {}
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:dio/dio.dart' show MultipartFile;
|
||||
import 'package:stream_chat/src/client/channel.dart';
|
||||
import 'package:stream_chat/src/core/models/channel_model.dart';
|
||||
import 'package:stream_chat/src/core/models/channel_state.dart';
|
||||
import 'package:stream_chat/src/core/models/event.dart';
|
||||
import 'package:stream_chat/src/core/models/message.dart';
|
||||
import 'package:stream_chat/src/core/models/user.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
Matcher isSameMultipartFileAs(MultipartFile targetFile) =>
|
||||
@@ -96,3 +100,35 @@ class _IsSameMessageAs extends Matcher {
|
||||
return matches;
|
||||
}
|
||||
}
|
||||
|
||||
Matcher isSameUserAs(User targetUser) => _IsSameUserAs(targetUser: targetUser);
|
||||
|
||||
class _IsSameUserAs extends Matcher {
|
||||
const _IsSameUserAs({required this.targetUser});
|
||||
|
||||
final User targetUser;
|
||||
|
||||
@override
|
||||
Description describe(Description description) =>
|
||||
description.add('is same user as $targetUser');
|
||||
|
||||
@override
|
||||
bool matches(covariant User user, Map matchState) => user.id == targetUser.id;
|
||||
}
|
||||
|
||||
Matcher isCorrectChannelFor(ChannelState channelState) =>
|
||||
_IsCorrectChannelFor(channelState: channelState);
|
||||
|
||||
class _IsCorrectChannelFor extends Matcher {
|
||||
const _IsCorrectChannelFor({required this.channelState});
|
||||
|
||||
final ChannelState channelState;
|
||||
|
||||
@override
|
||||
Description describe(Description description) =>
|
||||
description.add('is correct channel for $channelState');
|
||||
|
||||
@override
|
||||
bool matches(covariant Channel channel, Map matchState) =>
|
||||
channel.cid == channelState.channel?.cid;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ import 'package:stream_chat/src/core/http/token_manager.dart';
|
||||
import 'package:stream_chat/src/core/models/channel_config.dart';
|
||||
import 'package:stream_chat/src/core/models/channel_model.dart';
|
||||
import 'package:stream_chat/src/db/chat_persistence_client.dart';
|
||||
import 'package:stream_chat/src/ws/websocket.dart';
|
||||
import 'package:web_socket_channel/web_socket_channel.dart';
|
||||
|
||||
import 'db/chat_persistence_client_test.dart';
|
||||
@@ -66,7 +67,13 @@ class MockGeneralApi extends Mock implements GeneralApi {}
|
||||
class MockAttachmentFileUploader extends Mock
|
||||
implements AttachmentFileUploader {}
|
||||
|
||||
class MockPersistenceClient extends Mock implements ChatPersistenceClient {}
|
||||
class MockPersistenceClient extends Mock implements ChatPersistenceClient {
|
||||
@override
|
||||
Future<void> connect(String userId) => Future.value();
|
||||
|
||||
@override
|
||||
Future<void> disconnect({bool flush = false}) => Future.value();
|
||||
}
|
||||
|
||||
class MockStreamChatClient extends Mock implements StreamChatClient {
|
||||
@override
|
||||
@@ -105,3 +112,5 @@ class MockRetryQueueChannel extends Mock implements Channel {
|
||||
@override
|
||||
StreamChatClient get client => _client ??= MockStreamChatClient();
|
||||
}
|
||||
|
||||
class MockWebSocket extends Mock implements WebSocket {}
|
||||
|
||||
@@ -13,3 +13,12 @@ Directory get currentDirectory {
|
||||
}
|
||||
return directory;
|
||||
}
|
||||
|
||||
// Extension function to convert int into durations
|
||||
extension IntX on num {
|
||||
Duration toDuration() => Duration(milliseconds: toInt());
|
||||
}
|
||||
|
||||
// Top level util function to delay the code execution
|
||||
Future delay(num milliseconds) =>
|
||||
Future.delayed(Duration(milliseconds: milliseconds.toInt()));
|
||||
|
||||
Reference in New Issue
Block a user