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
Future<QueryReactionsResponse> getReactions(
String messageId, {
PaginationParams? options,
PaginationParams? pagination,
}) =>
_client.getReactions(
messageId,
options: options,
pagination: pagination,
);
/// Retrieves a list of messages by ID
@@ -1149,11 +1149,11 @@ class StreamChatClient {
/// Get all the reactions for a [messageId]
Future<QueryReactionsResponse> getReactions(
String messageId, {
PaginationParams? options,
PaginationParams? pagination,
}) =>
_chatApi.message.getReactions(
messageId,
options: options,
pagination: pagination,
);
/// Update the given message
@@ -76,7 +76,7 @@ class ChannelApi {
// pagination
...paginationParams.toJson()
})
}),
},
);
return QueryChannelsResponse.fromJson(response.data);
@@ -79,16 +79,17 @@ class GeneralApi {
queryParameters: {
'payload': jsonEncode({
'type': channelType,
'filter_conditions': filter ?? {},
if (channelId != null)
'id': channelId
else if (members != null)
'members': members,
if (sort != null) 'sort': sort,
if (filter != null) 'filter': filter,
if (pagination != null) ...pagination.toJson(),
}),
},
);
return QueryMembersResponse.fromJson(response.data);
}
}
@@ -143,12 +143,12 @@ class MessageApi {
/// Get all the reactions for a [messageId]
Future<QueryReactionsResponse> getReactions(
String messageId, {
PaginationParams? options,
PaginationParams? pagination,
}) async {
final response = await _client.get(
'/messages/$messageId/reactions',
queryParameters: {
if (options != null) ...options.toJson(),
if (pagination != null) ...pagination.toJson(),
},
);
return QueryReactionsResponse.fromJson(response.data);
@@ -3,18 +3,17 @@ import 'dart:async';
import 'package:dio/dio.dart';
import 'package:logging/logging.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/connection_id_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/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/location.dart';
import 'package:stream_chat/version.dart';
import 'package:stream_chat/src/core/http/connection_id_manager.dart';
part 'stream_http_client_options.dart';
/// This is where we configure the base url, headers,
@@ -1,3 +1,5 @@
import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:mocktail/mocktail.dart';
import 'package:stream_chat/src/core/api/channel_api.dart';
@@ -76,11 +78,24 @@ void main() {
const path = '$channelPath/query';
final channelState = _generateChannelState(channelId, channelType);
when(() => client.post(path, data: any(named: 'data')))
.thenAnswer((_) async => successResponse(
path,
data: channelState.toJson(),
));
final data = {
'state': true,
'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(
channelType,
@@ -115,13 +130,34 @@ void main() {
const path = '/channels';
final channelState = _generateChannelState(channelId, channelType);
when(() => client.get(path, queryParameters: any(named: 'queryParameters')))
.thenAnswer((_) async => successResponse(
path,
data: {
'channels': [channelState.toJson()]
},
));
final payload = jsonEncode({
// default options
'state': true,
'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(
filter: filter,
@@ -166,11 +202,18 @@ void main() {
extraData: data,
);
when(() => client.post(path, data: any(named: 'data')))
.thenAnswer((_) async => successResponse(path, data: {
'channel': channelModel.toJson(),
'message': message.toJson(),
}));
when(() => client.post(
path,
data: any(
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(
channelId,
@@ -235,11 +278,16 @@ void main() {
final path = _getChannelUrl(channelId, channelType);
when(() => client.post(path, data: any(named: 'data')))
.thenAnswer((_) async => successResponse(path, data: {
'channel': channelModel.toJson(),
'message': message.toJson(),
}));
when(() => client.post(
path,
data: {
'accept_invite': true,
'message': message,
},
)).thenAnswer((_) async => successResponse(path, data: {
'channel': channelModel.toJson(),
'message': message.toJson(),
}));
final res = await channelApi.acceptChannelInvite(
channelId,
@@ -264,11 +312,16 @@ void main() {
final path = _getChannelUrl(channelId, channelType);
when(() => client.post(path, data: any(named: 'data')))
.thenAnswer((_) async => successResponse(path, data: {
'channel': channelModel.toJson(),
'message': message.toJson(),
}));
when(() => client.post(
path,
data: {
'reject_invite': true,
'message': message,
},
)).thenAnswer((_) async => successResponse(path, data: {
'channel': channelModel.toJson(),
'message': message.toJson(),
}));
final res = await channelApi.rejectChannelInvite(
channelId,
@@ -293,11 +346,16 @@ void main() {
final path = _getChannelUrl(channelId, channelType);
when(() => client.post(path, data: any(named: 'data')))
.thenAnswer((_) async => successResponse(path, data: {
'channel': channelModel.toJson(),
'message': message.toJson(),
}));
when(() => client.post(
path,
data: {
'invites': memberIds,
'message': message,
},
)).thenAnswer((_) async => successResponse(path, data: {
'channel': channelModel.toJson(),
'message': message.toJson(),
}));
final res = await channelApi.inviteChannelMembers(
channelId,
@@ -323,11 +381,16 @@ void main() {
final path = _getChannelUrl(channelId, channelType);
when(() => client.post(path, data: any(named: 'data')))
.thenAnswer((_) async => successResponse(path, data: {
'channel': channelModel.toJson(),
'message': message.toJson(),
}));
when(() => client.post(
path,
data: {
'add_members': memberIds,
'message': message,
},
)).thenAnswer((_) async => successResponse(path, data: {
'channel': channelModel.toJson(),
'message': message.toJson(),
}));
final res = await channelApi.addMembers(
channelId,
@@ -353,11 +416,16 @@ void main() {
final path = _getChannelUrl(channelId, channelType);
when(() => client.post(path, data: any(named: 'data')))
.thenAnswer((_) async => successResponse(path, data: {
'channel': channelModel.toJson(),
'message': message.toJson(),
}));
when(() => client.post(
path,
data: {
'remove_members': memberIds,
'message': message,
},
)).thenAnswer((_) async => successResponse(path, data: {
'channel': channelModel.toJson(),
'message': message.toJson(),
}));
final res = await channelApi.removeMembers(
channelId,
@@ -381,7 +449,7 @@ void main() {
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>{}));
final res = await channelApi.sendEvent(channelId, channelType, event);
@@ -432,8 +500,14 @@ void main() {
final path = '${_getChannelUrl(channelId, channelType)}/hide';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
when(
() => client.post(
path,
data: {
'clear_history': false,
},
),
).thenAnswer((_) async => successResponse(path, data: <String, dynamic>{}));
final res = await channelApi.hideChannel(channelId, channelType);
@@ -443,6 +517,33 @@ void main() {
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 {
const channelId = 'test-channel-id';
const channelType = 'test-channel-type';
@@ -467,8 +568,14 @@ void main() {
final path = '${_getChannelUrl(channelId, channelType)}/read';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
when(() => client.post(
path,
data: {
'message_id': messageId,
},
))
.thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
final res = await channelApi.markRead(
channelId,
@@ -26,8 +26,15 @@ void main() {
const path = '/devices';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
when(() => client.post(
path,
data: {
'id': deviceId,
'push_provider': pushProvider.name,
},
))
.thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
final res = await deviceApi.addDevice(deviceId, pushProvider);
@@ -69,7 +76,10 @@ void main() {
const path = '/devices';
when(
() => client.delete(path, queryParameters: any(named: 'queryParameters')),
() => client.delete(
path,
queryParameters: {'id': deviceId},
),
).thenAnswer((_) async => successResponse(path, data: <String, dynamic>{}));
final res = await deviceApi.removeDevice(deviceId);
@@ -1,3 +1,5 @@
import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:mocktail/mocktail.dart';
import 'package:stream_chat/src/core/api/general_api.dart';
@@ -33,10 +35,17 @@ void main() {
final events =
List.generate(3, (index) => Event(type: 'test-event-type-$index'));
when(() => client.post(path, data: any(named: 'data')))
.thenAnswer((_) async => successResponse(path, data: {
'events': [...events.map((it) => it.toJson())]
}));
final data = {
'channel_cids': cids,
'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);
@@ -85,8 +94,20 @@ void main() {
const path = '/search';
final payload = jsonEncode({
'filter_conditions': filter,
'sort': sort,
'query': query,
...pagination.toJson(),
});
when(
() => client.get(path, queryParameters: any(named: 'queryParameters')),
() => client.get(
path,
queryParameters: {
'payload': payload,
},
),
).thenAnswer((_) async => successResponse(path, data: {'results': []}));
final res = await generalApi.searchMessages(
@@ -113,8 +134,20 @@ void main() {
const path = '/search';
final payload = jsonEncode({
'filter_conditions': filter,
'sort': sort,
'message_filter_conditions': messageFilter,
...pagination.toJson(),
});
when(
() => client.get(path, queryParameters: any(named: 'queryParameters')),
() => client.get(
path,
queryParameters: {
'payload': payload,
},
),
).thenAnswer((_) async => successResponse(path, data: {'results': []}));
final res = await generalApi.searchMessages(
@@ -149,11 +182,22 @@ void main() {
(index) => Member(userId: 'test-user-id=$index'),
);
when(() =>
client.get(path, queryParameters: any(named: 'queryParameters')))
.thenAnswer((_) async => successResponse(path, data: {
'members': [...members.map((it) => it.toJson())]
}));
final payload = jsonEncode({
'type': channelType,
'filter_conditions': filter,
'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(
channelType,
@@ -185,11 +229,22 @@ void main() {
(index) => Member(userId: 'test-user-id=$index'),
);
when(() =>
client.get(path, queryParameters: any(named: 'queryParameters')))
.thenAnswer((_) async => successResponse(path, data: {
'members': [...members.map((it) => it.toJson())]
}));
final payload = jsonEncode({
'type': channelType,
'filter_conditions': filter,
'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(
channelType,
@@ -26,11 +26,13 @@ void main() {
const path = '/guest';
when(() => client.post(path, data: any(named: 'data')))
.thenAnswer((_) async => successResponse(path, data: {
'access_token': accessToken,
'user': user.toJson(),
}));
when(() => client.post(
path,
data: {'user': user},
)).thenAnswer((_) async => successResponse(path, data: {
'access_token': accessToken,
'user': user.toJson(),
}));
final res = await guestApi.getGuestUser(user);
@@ -27,10 +27,15 @@ void main() {
const path = '/channels/$channelType/$channelId/message';
when(() => client.post(path, data: any(named: 'data')))
.thenAnswer((_) async => successResponse(path, data: {
'message': message.toJson(),
}));
when(() => client.post(
path,
data: {
'message': message,
'skip_push': false,
},
)).thenAnswer((_) async => successResponse(path, data: {
'message': message.toJson(),
}));
final res = await messageApi.sendMessage(channelId, channelType, message);
@@ -41,6 +46,37 @@ void main() {
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 {
const channelId = 'test-channel-id';
const channelType = 'test-channel-type';
@@ -53,10 +89,12 @@ void main() {
(index) => Message(id: 'test-message-id-$index'),
);
when(() => client.get(path, queryParameters: any(named: 'queryParameters')))
.thenAnswer((_) async => successResponse(path, data: {
'messages': [...messages.map((it) => it.toJson())],
}));
when(() => client.get(
path,
queryParameters: {'ids': messageIds.join(',')},
)).thenAnswer((_) async => successResponse(path, data: {
'messages': [...messages.map((it) => it.toJson())],
}));
final res = await messageApi.getMessagesById(
channelId,
@@ -97,7 +135,10 @@ void main() {
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()}),
);
@@ -169,8 +210,17 @@ void main() {
const path = '/messages/$messageId/action';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
when(() => client.post(
path,
data: {
'id': channelId,
'type': channelType,
'form_data': formData,
'message_id': messageId,
},
))
.thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
final res = await messageApi.sendAction(
channelId,
@@ -195,11 +245,17 @@ void main() {
final message = Message(id: messageId);
final reaction = Reaction(type: reactionType, messageId: messageId);
when(() => client.post(path, data: any(named: 'data')))
.thenAnswer((_) async => successResponse(path, data: {
'message': message.toJson(),
'reaction': reaction.toJson(),
}));
when(() => client.post(
path,
data: {
'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(
messageId,
@@ -216,6 +272,44 @@ void main() {
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 {
const messageId = 'test-message-id';
const reactionType = 'test-reaction-type';
@@ -247,12 +341,16 @@ void main() {
),
);
when(() => client.get(path, queryParameters: any(named: 'queryParameters')))
.thenAnswer((_) async => successResponse(path, data: {
'reactions': [...reactions.map((it) => it.toJson())]
}));
when(() => client.get(
path,
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.reactions.length, reactions.length);
@@ -277,10 +375,12 @@ void main() {
language: translatedMessageText,
});
when(() => client.post(path, data: any(named: 'data')))
.thenAnswer((_) async => successResponse(path, data: {
'message': translatedMessage.toJson(),
}));
when(() => client.post(
path,
data: {'language': language},
)).thenAnswer((_) async => successResponse(path, data: {
'message': translatedMessage.toJson(),
}));
final res = await messageApi.translateMessage(messageId, language);
@@ -306,10 +406,14 @@ void main() {
),
);
when(() => client.get(path, queryParameters: any(named: 'queryParameters')))
.thenAnswer((_) async => successResponse(path, data: {
'messages': [...messages.map((it) => it.toJson())]
}));
when(() => client.get(
path,
queryParameters: {
...options.toJson(),
},
)).thenAnswer((_) async => successResponse(path, data: {
'messages': [...messages.map((it) => it.toJson())]
}));
final res = await messageApi.getReplies(parentId, options: options);
@@ -24,8 +24,12 @@ void main() {
const path = '/moderation/mute';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
when(
() => client.post(
path,
data: {'target_id': userId},
),
).thenAnswer((_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.muteUser(userId);
@@ -40,8 +44,12 @@ void main() {
const path = '/moderation/unmute';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
when(
() => client.post(
path,
data: {'target_id': userId},
),
).thenAnswer((_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.unmuteUser(userId);
@@ -57,8 +65,15 @@ void main() {
const path = '/moderation/mute/channel';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
when(() => client.post(
path,
data: {
'channel_cid': channelCid,
'expiration': expiration.inMilliseconds,
},
))
.thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.muteChannel(
channelCid,
@@ -76,8 +91,12 @@ void main() {
const path = '/moderation/unmute/channel';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
when(() => client.post(
path,
data: {'channel_cid': channelCid},
))
.thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.unmuteChannel(channelCid);
@@ -92,8 +111,14 @@ void main() {
const path = '/moderation/flag';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
when(() => client.post(
path,
data: {
'target_message_id': messageId,
},
))
.thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.flagMessage(messageId);
@@ -108,8 +133,14 @@ void main() {
const path = '/moderation/unflag';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
when(() => client.post(
path,
data: {
'target_message_id': messageId,
},
))
.thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.unflagMessage(messageId);
@@ -124,8 +155,11 @@ void main() {
const path = '/moderation/flag';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
when(() => client.post(path, data: {
'target_user_id': userId,
}))
.thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.flagUser(userId);
@@ -140,8 +174,14 @@ void main() {
const path = '/moderation/unflag';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
when(() => client.post(
path,
data: {
'target_user_id': userId,
},
))
.thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.unflagUser(userId);
@@ -157,8 +197,12 @@ void main() {
const path = '/moderation/ban';
when(() => client.post(path, data: any(named: 'data'))).thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
when(() => client.post(path, data: {
'target_user_id': targetUserId,
...options,
}))
.thenAnswer(
(_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.banUser(targetUserId, options: options);
@@ -175,7 +219,13 @@ void main() {
const path = '/moderation/ban';
when(
() => client.delete(path, queryParameters: any(named: 'queryParameters')),
() => client.delete(
path,
queryParameters: {
'target_user_id': targetUserId,
...options,
},
),
).thenAnswer((_) async => successResponse(path, data: <String, dynamic>{}));
final res = await moderationApi.unbanUser(targetUserId, options: options);
@@ -1,3 +1,5 @@
import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:mocktail/mocktail.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'));
when(() => client.get(path, queryParameters: any(named: 'queryParameters')))
.thenAnswer((_) async => successResponse(path, data: {
'users': [...users.map((it) => it.toJson())]
}));
when(() => client.get(path, queryParameters: {
'payload': jsonEncode({
'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(
presence: presence,
@@ -60,8 +68,10 @@ void main() {
final updatedUsers = {for (final user in users) user.id: user};
when(() => client.post(path, data: any(named: 'data'))).thenAnswer(
(_) async => successResponse(path, data: {
when(() => client.post(path, data: {
'users': updatedUsers,
})).thenAnswer((_) async => successResponse(path,
data: {
'users': updatedUsers
.map((key, value) => MapEntry(key, value.toJson()))
}));