Merge pull request #501 from GetStream/hotfix/queryMembers

fix: queryMembers payload
This commit is contained in:
Salvatore Giordano
2021-06-28 09:42:25 +02:00
committed by GitHub
13 changed files with 475 additions and 137 deletions
@@ -989,11 +989,11 @@ class Channel {
/// List the reactions for a message in the channel /// List the reactions for a message in the channel
Future<QueryReactionsResponse> getReactions( Future<QueryReactionsResponse> getReactions(
String messageId, { String messageId, {
PaginationParams? options, PaginationParams? pagination,
}) => }) =>
_client.getReactions( _client.getReactions(
messageId, messageId,
options: options, pagination: pagination,
); );
/// Retrieves a list of messages by ID /// Retrieves a list of messages by ID
@@ -1149,11 +1149,11 @@ class StreamChatClient {
/// Get all the reactions for a [messageId] /// Get all the reactions for a [messageId]
Future<QueryReactionsResponse> getReactions( Future<QueryReactionsResponse> getReactions(
String messageId, { String messageId, {
PaginationParams? options, PaginationParams? pagination,
}) => }) =>
_chatApi.message.getReactions( _chatApi.message.getReactions(
messageId, messageId,
options: options, pagination: pagination,
); );
/// Update the given message /// Update the given message
@@ -76,7 +76,7 @@ class ChannelApi {
// pagination // pagination
...paginationParams.toJson() ...paginationParams.toJson()
}) }),
}, },
); );
return QueryChannelsResponse.fromJson(response.data); return QueryChannelsResponse.fromJson(response.data);
@@ -79,16 +79,17 @@ class GeneralApi {
queryParameters: { queryParameters: {
'payload': jsonEncode({ 'payload': jsonEncode({
'type': channelType, 'type': channelType,
'filter_conditions': filter ?? {},
if (channelId != null) if (channelId != null)
'id': channelId 'id': channelId
else if (members != null) else if (members != null)
'members': members, 'members': members,
if (sort != null) 'sort': sort, if (sort != null) 'sort': sort,
if (filter != null) 'filter': filter,
if (pagination != null) ...pagination.toJson(), if (pagination != null) ...pagination.toJson(),
}), }),
}, },
); );
return QueryMembersResponse.fromJson(response.data); return QueryMembersResponse.fromJson(response.data);
} }
} }
@@ -143,12 +143,12 @@ class MessageApi {
/// Get all the reactions for a [messageId] /// Get all the reactions for a [messageId]
Future<QueryReactionsResponse> getReactions( Future<QueryReactionsResponse> getReactions(
String messageId, { String messageId, {
PaginationParams? options, PaginationParams? pagination,
}) async { }) async {
final response = await _client.get( final response = await _client.get(
'/messages/$messageId/reactions', '/messages/$messageId/reactions',
queryParameters: { queryParameters: {
if (options != null) ...options.toJson(), if (pagination != null) ...pagination.toJson(),
}, },
); );
return QueryReactionsResponse.fromJson(response.data); return QueryReactionsResponse.fromJson(response.data);
@@ -3,18 +3,17 @@ import 'dart:async';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:logging/logging.dart'; import 'package:logging/logging.dart';
import 'package:meta/meta.dart'; import 'package:meta/meta.dart';
import 'package:stream_chat/src/core/error/error.dart';
import 'package:stream_chat/src/core/http/connection_id_manager.dart';
import 'package:stream_chat/src/core/http/interceptor/auth_interceptor.dart'; import 'package:stream_chat/src/core/http/interceptor/auth_interceptor.dart';
import 'package:stream_chat/src/core/http/interceptor/connection_id_interceptor.dart'; import 'package:stream_chat/src/core/http/interceptor/connection_id_interceptor.dart';
import 'package:stream_chat/src/core/http/interceptor/logging_interceptor.dart'; import 'package:stream_chat/src/core/http/interceptor/logging_interceptor.dart';
import 'package:stream_chat/src/core/http/stream_chat_dio_error.dart'; import 'package:stream_chat/src/core/http/stream_chat_dio_error.dart';
import 'package:stream_chat/src/core/http/token_manager.dart'; import 'package:stream_chat/src/core/http/token_manager.dart';
import 'package:stream_chat/src/core/error/error.dart';
import 'package:stream_chat/src/location.dart';
import 'package:stream_chat/src/core/platform_detector/platform_detector.dart'; import 'package:stream_chat/src/core/platform_detector/platform_detector.dart';
import 'package:stream_chat/src/location.dart';
import 'package:stream_chat/version.dart'; import 'package:stream_chat/version.dart';
import 'package:stream_chat/src/core/http/connection_id_manager.dart';
part 'stream_http_client_options.dart'; part 'stream_http_client_options.dart';
/// This is where we configure the base url, headers, /// This is where we configure the base url, headers,
@@ -1,3 +1,5 @@
import 'dart:convert';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:mocktail/mocktail.dart'; import 'package:mocktail/mocktail.dart';
import 'package:stream_chat/src/core/api/channel_api.dart'; import 'package:stream_chat/src/core/api/channel_api.dart';
@@ -76,11 +78,24 @@ void main() {
const path = '$channelPath/query'; const path = '$channelPath/query';
final channelState = _generateChannelState(channelId, channelType); final channelState = _generateChannelState(channelId, channelType);
when(() => client.post(path, data: any(named: 'data')))
.thenAnswer((_) async => successResponse( final data = {
path, 'state': true,
data: channelState.toJson(), 'watch': false,
)); 'presence': false,
'data': channelData,
'messages': messagePagination,
'members': membersPagination,
'watchers': watchersPagination,
};
when(() => client.post(
path,
data: data,
)).thenAnswer((_) async => successResponse(
path,
data: channelState.toJson(),
));
final res = await channelApi.queryChannel( final res = await channelApi.queryChannel(
channelType, channelType,
@@ -115,13 +130,34 @@ void main() {
const path = '/channels'; const path = '/channels';
final channelState = _generateChannelState(channelId, channelType); final channelState = _generateChannelState(channelId, channelType);
when(() => client.get(path, queryParameters: any(named: 'queryParameters')))
.thenAnswer((_) async => successResponse( final payload = jsonEncode({
path, // default options
data: { 'state': true,
'channels': [channelState.toJson()] 'watch': true,
}, 'presence': false,
));
// passed options
'sort': sort,
'filter_conditions': filter,
'member_limit': memberLimit,
'message_limit': messageLimit,
// pagination
...const PaginationParams().toJson()
});
when(() => client.get(
path,
queryParameters: {
'payload': payload,
},
)).thenAnswer((_) async => successResponse(
path,
data: {
'channels': [channelState.toJson()]
},
));
final res = await channelApi.queryChannels( final res = await channelApi.queryChannels(
filter: filter, filter: filter,
@@ -166,11 +202,18 @@ void main() {
extraData: data, extraData: data,
); );
when(() => client.post(path, data: any(named: 'data'))) when(() => client.post(
.thenAnswer((_) async => successResponse(path, data: { path,
'channel': channelModel.toJson(), data: any(
'message': message.toJson(), named: 'data',
})); that: wrapMatcher((Map v) =>
containsPair('data', data).matches(v, {}) &&
contains('message').matches(v, {})),
),
)).thenAnswer((_) async => successResponse(path, data: {
'channel': channelModel.toJson(),
'message': message.toJson(),
}));
final res = await channelApi.updateChannel( final res = await channelApi.updateChannel(
channelId, channelId,
@@ -235,11 +278,16 @@ void main() {
final path = _getChannelUrl(channelId, channelType); final path = _getChannelUrl(channelId, channelType);
when(() => client.post(path, data: any(named: 'data'))) when(() => client.post(
.thenAnswer((_) async => successResponse(path, data: { path,
'channel': channelModel.toJson(), data: {
'message': message.toJson(), 'accept_invite': true,
})); 'message': message,
},
)).thenAnswer((_) async => successResponse(path, data: {
'channel': channelModel.toJson(),
'message': message.toJson(),
}));
final res = await channelApi.acceptChannelInvite( final res = await channelApi.acceptChannelInvite(
channelId, channelId,
@@ -264,11 +312,16 @@ void main() {
final path = _getChannelUrl(channelId, channelType); final path = _getChannelUrl(channelId, channelType);
when(() => client.post(path, data: any(named: 'data'))) when(() => client.post(
.thenAnswer((_) async => successResponse(path, data: { path,
'channel': channelModel.toJson(), data: {
'message': message.toJson(), 'reject_invite': true,
})); 'message': message,
},
)).thenAnswer((_) async => successResponse(path, data: {
'channel': channelModel.toJson(),
'message': message.toJson(),
}));
final res = await channelApi.rejectChannelInvite( final res = await channelApi.rejectChannelInvite(
channelId, channelId,
@@ -293,11 +346,16 @@ void main() {
final path = _getChannelUrl(channelId, channelType); final path = _getChannelUrl(channelId, channelType);
when(() => client.post(path, data: any(named: 'data'))) when(() => client.post(
.thenAnswer((_) async => successResponse(path, data: { path,
'channel': channelModel.toJson(), data: {
'message': message.toJson(), 'invites': memberIds,
})); 'message': message,
},
)).thenAnswer((_) async => successResponse(path, data: {
'channel': channelModel.toJson(),
'message': message.toJson(),
}));
final res = await channelApi.inviteChannelMembers( final res = await channelApi.inviteChannelMembers(
channelId, channelId,
@@ -323,11 +381,16 @@ void main() {
final path = _getChannelUrl(channelId, channelType); final path = _getChannelUrl(channelId, channelType);
when(() => client.post(path, data: any(named: 'data'))) when(() => client.post(
.thenAnswer((_) async => successResponse(path, data: { path,
'channel': channelModel.toJson(), data: {
'message': message.toJson(), 'add_members': memberIds,
})); 'message': message,
},
)).thenAnswer((_) async => successResponse(path, data: {
'channel': channelModel.toJson(),
'message': message.toJson(),
}));
final res = await channelApi.addMembers( final res = await channelApi.addMembers(
channelId, channelId,
@@ -353,11 +416,16 @@ void main() {
final path = _getChannelUrl(channelId, channelType); final path = _getChannelUrl(channelId, channelType);
when(() => client.post(path, data: any(named: 'data'))) when(() => client.post(
.thenAnswer((_) async => successResponse(path, data: { path,
'channel': channelModel.toJson(), data: {
'message': message.toJson(), 'remove_members': memberIds,
})); 'message': message,
},
)).thenAnswer((_) async => successResponse(path, data: {
'channel': channelModel.toJson(),
'message': message.toJson(),
}));
final res = await channelApi.removeMembers( final res = await channelApi.removeMembers(
channelId, channelId,
@@ -381,7 +449,7 @@ void main() {
final path = '${_getChannelUrl(channelId, channelType)}/event'; final path = '${_getChannelUrl(channelId, channelType)}/event';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer( when(() => client.post(path, data: {'event': event})).thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{})); (_) async => successResponse(path, data: <String, dynamic>{}));
final res = await channelApi.sendEvent(channelId, channelType, event); final res = await channelApi.sendEvent(channelId, channelType, event);
@@ -432,8 +500,14 @@ void main() {
final path = '${_getChannelUrl(channelId, channelType)}/hide'; final path = '${_getChannelUrl(channelId, channelType)}/hide';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer( when(
(_) async => successResponse(path, data: <String, dynamic>{})); () => client.post(
path,
data: {
'clear_history': false,
},
),
).thenAnswer((_) async => successResponse(path, data: <String, dynamic>{}));
final res = await channelApi.hideChannel(channelId, channelType); final res = await channelApi.hideChannel(channelId, channelType);
@@ -443,6 +517,33 @@ void main() {
verifyNoMoreInteractions(client); verifyNoMoreInteractions(client);
}); });
test('hideChannel with clear_history: true', () async {
const channelId = 'test-channel-id';
const channelType = 'test-channel-type';
final path = '${_getChannelUrl(channelId, channelType)}/hide';
when(
() => client.post(
path,
data: {
'clear_history': true,
},
),
).thenAnswer((_) async => successResponse(path, data: <String, dynamic>{}));
final res = await channelApi.hideChannel(
channelId,
channelType,
clearHistory: true,
);
expect(res, isNotNull);
verify(() => client.post(path, data: any(named: 'data'))).called(1);
verifyNoMoreInteractions(client);
});
test('showChannel', () async { test('showChannel', () async {
const channelId = 'test-channel-id'; const channelId = 'test-channel-id';
const channelType = 'test-channel-type'; const channelType = 'test-channel-type';
@@ -467,8 +568,14 @@ void main() {
final path = '${_getChannelUrl(channelId, channelType)}/read'; final path = '${_getChannelUrl(channelId, channelType)}/read';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer( when(() => client.post(
(_) async => successResponse(path, data: <String, dynamic>{})); path,
data: {
'message_id': messageId,
},
))
.thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
final res = await channelApi.markRead( final res = await channelApi.markRead(
channelId, channelId,
@@ -26,8 +26,15 @@ void main() {
const path = '/devices'; const path = '/devices';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer( when(() => client.post(
(_) async => successResponse(path, data: <String, dynamic>{})); path,
data: {
'id': deviceId,
'push_provider': pushProvider.name,
},
))
.thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
final res = await deviceApi.addDevice(deviceId, pushProvider); final res = await deviceApi.addDevice(deviceId, pushProvider);
@@ -69,7 +76,10 @@ void main() {
const path = '/devices'; const path = '/devices';
when( when(
() => client.delete(path, queryParameters: any(named: 'queryParameters')), () => client.delete(
path,
queryParameters: {'id': deviceId},
),
).thenAnswer((_) async => successResponse(path, data: <String, dynamic>{})); ).thenAnswer((_) async => successResponse(path, data: <String, dynamic>{}));
final res = await deviceApi.removeDevice(deviceId); final res = await deviceApi.removeDevice(deviceId);
@@ -1,3 +1,5 @@
import 'dart:convert';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:mocktail/mocktail.dart'; import 'package:mocktail/mocktail.dart';
import 'package:stream_chat/src/core/api/general_api.dart'; import 'package:stream_chat/src/core/api/general_api.dart';
@@ -33,10 +35,17 @@ void main() {
final events = final events =
List.generate(3, (index) => Event(type: 'test-event-type-$index')); List.generate(3, (index) => Event(type: 'test-event-type-$index'));
when(() => client.post(path, data: any(named: 'data'))) final data = {
.thenAnswer((_) async => successResponse(path, data: { 'channel_cids': cids,
'events': [...events.map((it) => it.toJson())] 'last_sync_at': lastSyncAt.toUtc().toIso8601String(),
})); };
when(() => client.post(
path,
data: data,
)).thenAnswer((_) async => successResponse(path, data: {
'events': [...events.map((it) => it.toJson())]
}));
final res = await generalApi.sync(cids, lastSyncAt); final res = await generalApi.sync(cids, lastSyncAt);
@@ -85,8 +94,20 @@ void main() {
const path = '/search'; const path = '/search';
final payload = jsonEncode({
'filter_conditions': filter,
'sort': sort,
'query': query,
...pagination.toJson(),
});
when( when(
() => client.get(path, queryParameters: any(named: 'queryParameters')), () => client.get(
path,
queryParameters: {
'payload': payload,
},
),
).thenAnswer((_) async => successResponse(path, data: {'results': []})); ).thenAnswer((_) async => successResponse(path, data: {'results': []}));
final res = await generalApi.searchMessages( final res = await generalApi.searchMessages(
@@ -113,8 +134,20 @@ void main() {
const path = '/search'; const path = '/search';
final payload = jsonEncode({
'filter_conditions': filter,
'sort': sort,
'message_filter_conditions': messageFilter,
...pagination.toJson(),
});
when( when(
() => client.get(path, queryParameters: any(named: 'queryParameters')), () => client.get(
path,
queryParameters: {
'payload': payload,
},
),
).thenAnswer((_) async => successResponse(path, data: {'results': []})); ).thenAnswer((_) async => successResponse(path, data: {'results': []}));
final res = await generalApi.searchMessages( final res = await generalApi.searchMessages(
@@ -149,11 +182,22 @@ void main() {
(index) => Member(userId: 'test-user-id=$index'), (index) => Member(userId: 'test-user-id=$index'),
); );
when(() => final payload = jsonEncode({
client.get(path, queryParameters: any(named: 'queryParameters'))) 'type': channelType,
.thenAnswer((_) async => successResponse(path, data: { 'filter_conditions': filter,
'members': [...members.map((it) => it.toJson())] 'id': channelId,
})); 'sort': sort,
...pagination.toJson(),
});
when(() => client.get(
path,
queryParameters: {
'payload': payload,
},
)).thenAnswer((_) async => successResponse(path, data: {
'members': [...members.map((it) => it.toJson())]
}));
final res = await generalApi.queryMembers( final res = await generalApi.queryMembers(
channelType, channelType,
@@ -185,11 +229,22 @@ void main() {
(index) => Member(userId: 'test-user-id=$index'), (index) => Member(userId: 'test-user-id=$index'),
); );
when(() => final payload = jsonEncode({
client.get(path, queryParameters: any(named: 'queryParameters'))) 'type': channelType,
.thenAnswer((_) async => successResponse(path, data: { 'filter_conditions': filter,
'members': [...members.map((it) => it.toJson())] 'members': members,
})); 'sort': sort,
...pagination.toJson(),
});
when(() => client.get(
path,
queryParameters: {
'payload': payload,
},
)).thenAnswer((_) async => successResponse(path, data: {
'members': [...members.map((it) => it.toJson())]
}));
final res = await generalApi.queryMembers( final res = await generalApi.queryMembers(
channelType, channelType,
@@ -26,11 +26,13 @@ void main() {
const path = '/guest'; const path = '/guest';
when(() => client.post(path, data: any(named: 'data'))) when(() => client.post(
.thenAnswer((_) async => successResponse(path, data: { path,
'access_token': accessToken, data: {'user': user},
'user': user.toJson(), )).thenAnswer((_) async => successResponse(path, data: {
})); 'access_token': accessToken,
'user': user.toJson(),
}));
final res = await guestApi.getGuestUser(user); final res = await guestApi.getGuestUser(user);
@@ -27,10 +27,15 @@ void main() {
const path = '/channels/$channelType/$channelId/message'; const path = '/channels/$channelType/$channelId/message';
when(() => client.post(path, data: any(named: 'data'))) when(() => client.post(
.thenAnswer((_) async => successResponse(path, data: { path,
'message': message.toJson(), data: {
})); 'message': message,
'skip_push': false,
},
)).thenAnswer((_) async => successResponse(path, data: {
'message': message.toJson(),
}));
final res = await messageApi.sendMessage(channelId, channelType, message); final res = await messageApi.sendMessage(channelId, channelType, message);
@@ -41,6 +46,37 @@ void main() {
verifyNoMoreInteractions(client); verifyNoMoreInteractions(client);
}); });
test('sendMessage with skipPush: true', () async {
const channelId = 'test-channel-id';
const channelType = 'test-channel-type';
final message = Message(id: 'test-message-id', text: 'test-message-text');
const path = '/channels/$channelType/$channelId/message';
when(() => client.post(
path,
data: {
'message': message,
'skip_push': true,
},
)).thenAnswer((_) async => successResponse(path, data: {
'message': message.toJson(),
}));
final res = await messageApi.sendMessage(
channelId,
channelType,
message,
skipPush: true,
);
expect(res, isNotNull);
expect(res.message.id, message.id);
verify(() => client.post(path, data: any(named: 'data'))).called(1);
verifyNoMoreInteractions(client);
});
test('getMessagesById', () async { test('getMessagesById', () async {
const channelId = 'test-channel-id'; const channelId = 'test-channel-id';
const channelType = 'test-channel-type'; const channelType = 'test-channel-type';
@@ -53,10 +89,12 @@ void main() {
(index) => Message(id: 'test-message-id-$index'), (index) => Message(id: 'test-message-id-$index'),
); );
when(() => client.get(path, queryParameters: any(named: 'queryParameters'))) when(() => client.get(
.thenAnswer((_) async => successResponse(path, data: { path,
'messages': [...messages.map((it) => it.toJson())], queryParameters: {'ids': messageIds.join(',')},
})); )).thenAnswer((_) async => successResponse(path, data: {
'messages': [...messages.map((it) => it.toJson())],
}));
final res = await messageApi.getMessagesById( final res = await messageApi.getMessagesById(
channelId, channelId,
@@ -97,7 +135,10 @@ void main() {
final path = '/messages/${message.id}'; final path = '/messages/${message.id}';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer( when(() => client.post(
path,
data: {'message': message},
)).thenAnswer(
(_) async => successResponse(path, data: {'message': message.toJson()}), (_) async => successResponse(path, data: {'message': message.toJson()}),
); );
@@ -169,8 +210,17 @@ void main() {
const path = '/messages/$messageId/action'; const path = '/messages/$messageId/action';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer( when(() => client.post(
(_) async => successResponse(path, data: <String, dynamic>{})); path,
data: {
'id': channelId,
'type': channelType,
'form_data': formData,
'message_id': messageId,
},
))
.thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
final res = await messageApi.sendAction( final res = await messageApi.sendAction(
channelId, channelId,
@@ -195,11 +245,17 @@ void main() {
final message = Message(id: messageId); final message = Message(id: messageId);
final reaction = Reaction(type: reactionType, messageId: messageId); final reaction = Reaction(type: reactionType, messageId: messageId);
when(() => client.post(path, data: any(named: 'data'))) when(() => client.post(
.thenAnswer((_) async => successResponse(path, data: { path,
'message': message.toJson(), data: {
'reaction': reaction.toJson(), 'reaction': Map<String, Object?>.from(extraData)
})); ..addAll({'type': reactionType}),
'enforce_unique': false,
},
)).thenAnswer((_) async => successResponse(path, data: {
'message': message.toJson(),
'reaction': reaction.toJson(),
}));
final res = await messageApi.sendReaction( final res = await messageApi.sendReaction(
messageId, messageId,
@@ -216,6 +272,44 @@ void main() {
verifyNoMoreInteractions(client); verifyNoMoreInteractions(client);
}); });
test('sendReaction with enforceUnique: true', () async {
const messageId = 'test-message-id';
const reactionType = 'test-reaction-type';
const extraData = {'test-key': 'test-data'};
const path = '/messages/$messageId/reaction';
final message = Message(id: messageId);
final reaction = Reaction(type: reactionType, messageId: messageId);
when(() => client.post(
path,
data: {
'reaction': Map<String, Object?>.from(extraData)
..addAll({'type': reactionType}),
'enforce_unique': true,
},
)).thenAnswer((_) async => successResponse(path, data: {
'message': message.toJson(),
'reaction': reaction.toJson(),
}));
final res = await messageApi.sendReaction(
messageId,
reactionType,
extraData: extraData,
enforceUnique: true,
);
expect(res, isNotNull);
expect(res.message.id, messageId);
expect(res.reaction.messageId, messageId);
expect(res.reaction.type, reactionType);
verify(() => client.post(path, data: any(named: 'data'))).called(1);
verifyNoMoreInteractions(client);
});
test('deleteReaction', () async { test('deleteReaction', () async {
const messageId = 'test-message-id'; const messageId = 'test-message-id';
const reactionType = 'test-reaction-type'; const reactionType = 'test-reaction-type';
@@ -247,12 +341,16 @@ void main() {
), ),
); );
when(() => client.get(path, queryParameters: any(named: 'queryParameters'))) when(() => client.get(
.thenAnswer((_) async => successResponse(path, data: { path,
'reactions': [...reactions.map((it) => it.toJson())] queryParameters: {
})); ...const PaginationParams().toJson(),
},
)).thenAnswer((_) async => successResponse(path, data: {
'reactions': [...reactions.map((it) => it.toJson())]
}));
final res = await messageApi.getReactions(messageId, options: options); final res = await messageApi.getReactions(messageId, pagination: options);
expect(res, isNotNull); expect(res, isNotNull);
expect(res.reactions.length, reactions.length); expect(res.reactions.length, reactions.length);
@@ -277,10 +375,12 @@ void main() {
language: translatedMessageText, language: translatedMessageText,
}); });
when(() => client.post(path, data: any(named: 'data'))) when(() => client.post(
.thenAnswer((_) async => successResponse(path, data: { path,
'message': translatedMessage.toJson(), data: {'language': language},
})); )).thenAnswer((_) async => successResponse(path, data: {
'message': translatedMessage.toJson(),
}));
final res = await messageApi.translateMessage(messageId, language); final res = await messageApi.translateMessage(messageId, language);
@@ -306,10 +406,14 @@ void main() {
), ),
); );
when(() => client.get(path, queryParameters: any(named: 'queryParameters'))) when(() => client.get(
.thenAnswer((_) async => successResponse(path, data: { path,
'messages': [...messages.map((it) => it.toJson())] queryParameters: {
})); ...options.toJson(),
},
)).thenAnswer((_) async => successResponse(path, data: {
'messages': [...messages.map((it) => it.toJson())]
}));
final res = await messageApi.getReplies(parentId, options: options); final res = await messageApi.getReplies(parentId, options: options);
@@ -24,8 +24,12 @@ void main() {
const path = '/moderation/mute'; const path = '/moderation/mute';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer( when(
(_) async => successResponse(path, data: <String, dynamic>{})); () => client.post(
path,
data: {'target_id': userId},
),
).thenAnswer((_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.muteUser(userId); final res = await moderationApi.muteUser(userId);
@@ -40,8 +44,12 @@ void main() {
const path = '/moderation/unmute'; const path = '/moderation/unmute';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer( when(
(_) async => successResponse(path, data: <String, dynamic>{})); () => client.post(
path,
data: {'target_id': userId},
),
).thenAnswer((_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.unmuteUser(userId); final res = await moderationApi.unmuteUser(userId);
@@ -57,8 +65,15 @@ void main() {
const path = '/moderation/mute/channel'; const path = '/moderation/mute/channel';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer( when(() => client.post(
(_) async => successResponse(path, data: <String, dynamic>{})); path,
data: {
'channel_cid': channelCid,
'expiration': expiration.inMilliseconds,
},
))
.thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.muteChannel( final res = await moderationApi.muteChannel(
channelCid, channelCid,
@@ -76,8 +91,12 @@ void main() {
const path = '/moderation/unmute/channel'; const path = '/moderation/unmute/channel';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer( when(() => client.post(
(_) async => successResponse(path, data: <String, dynamic>{})); path,
data: {'channel_cid': channelCid},
))
.thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.unmuteChannel(channelCid); final res = await moderationApi.unmuteChannel(channelCid);
@@ -92,8 +111,14 @@ void main() {
const path = '/moderation/flag'; const path = '/moderation/flag';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer( when(() => client.post(
(_) async => successResponse(path, data: <String, dynamic>{})); path,
data: {
'target_message_id': messageId,
},
))
.thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.flagMessage(messageId); final res = await moderationApi.flagMessage(messageId);
@@ -108,8 +133,14 @@ void main() {
const path = '/moderation/unflag'; const path = '/moderation/unflag';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer( when(() => client.post(
(_) async => successResponse(path, data: <String, dynamic>{})); path,
data: {
'target_message_id': messageId,
},
))
.thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.unflagMessage(messageId); final res = await moderationApi.unflagMessage(messageId);
@@ -124,8 +155,11 @@ void main() {
const path = '/moderation/flag'; const path = '/moderation/flag';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer( when(() => client.post(path, data: {
(_) async => successResponse(path, data: <String, dynamic>{})); 'target_user_id': userId,
}))
.thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.flagUser(userId); final res = await moderationApi.flagUser(userId);
@@ -140,8 +174,14 @@ void main() {
const path = '/moderation/unflag'; const path = '/moderation/unflag';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer( when(() => client.post(
(_) async => successResponse(path, data: <String, dynamic>{})); path,
data: {
'target_user_id': userId,
},
))
.thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.unflagUser(userId); final res = await moderationApi.unflagUser(userId);
@@ -157,8 +197,12 @@ void main() {
const path = '/moderation/ban'; const path = '/moderation/ban';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer( when(() => client.post(path, data: {
(_) async => successResponse(path, data: <String, dynamic>{})); 'target_user_id': targetUserId,
...options,
}))
.thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.banUser(targetUserId, options: options); final res = await moderationApi.banUser(targetUserId, options: options);
@@ -175,7 +219,13 @@ void main() {
const path = '/moderation/ban'; const path = '/moderation/ban';
when( when(
() => client.delete(path, queryParameters: any(named: 'queryParameters')), () => client.delete(
path,
queryParameters: {
'target_user_id': targetUserId,
...options,
},
),
).thenAnswer((_) async => successResponse(path, data: <String, dynamic>{})); ).thenAnswer((_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.unbanUser(targetUserId, options: options); final res = await moderationApi.unbanUser(targetUserId, options: options);
@@ -1,3 +1,5 @@
import 'dart:convert';
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:mocktail/mocktail.dart'; import 'package:mocktail/mocktail.dart';
import 'package:stream_chat/src/core/api/requests.dart'; import 'package:stream_chat/src/core/api/requests.dart';
@@ -32,10 +34,16 @@ void main() {
final users = List.generate(3, (index) => User(id: 'test-user-id-$index')); final users = List.generate(3, (index) => User(id: 'test-user-id-$index'));
when(() => client.get(path, queryParameters: any(named: 'queryParameters'))) when(() => client.get(path, queryParameters: {
.thenAnswer((_) async => successResponse(path, data: { 'payload': jsonEncode({
'users': [...users.map((it) => it.toJson())] 'presence': presence,
})); 'sort': sort,
'filter_conditions': filter,
...pagination.toJson(),
}),
})).thenAnswer((_) async => successResponse(path, data: {
'users': [...users.map((it) => it.toJson())]
}));
final res = await userApi.queryUsers( final res = await userApi.queryUsers(
presence: presence, presence: presence,
@@ -60,8 +68,10 @@ void main() {
final updatedUsers = {for (final user in users) user.id: user}; final updatedUsers = {for (final user in users) user.id: user};
when(() => client.post(path, data: any(named: 'data'))).thenAnswer( when(() => client.post(path, data: {
(_) async => successResponse(path, data: { 'users': updatedUsers,
})).thenAnswer((_) async => successResponse(path,
data: {
'users': updatedUsers 'users': updatedUsers
.map((key, value) => MapEntry(key, value.toJson())) .map((key, value) => MapEntry(key, value.toJson()))
})); }));