diff --git a/packages/stream_chat/lib/src/client/channel.dart b/packages/stream_chat/lib/src/client/channel.dart index e173c703..eee18356 100644 --- a/packages/stream_chat/lib/src/client/channel.dart +++ b/packages/stream_chat/lib/src/client/channel.dart @@ -989,11 +989,11 @@ class Channel { /// List the reactions for a message in the channel Future getReactions( String messageId, { - PaginationParams? options, + PaginationParams? pagination, }) => _client.getReactions( messageId, - options: options, + pagination: pagination, ); /// Retrieves a list of messages by ID diff --git a/packages/stream_chat/lib/src/client/client.dart b/packages/stream_chat/lib/src/client/client.dart index b579f030..93949df3 100644 --- a/packages/stream_chat/lib/src/client/client.dart +++ b/packages/stream_chat/lib/src/client/client.dart @@ -1149,11 +1149,11 @@ class StreamChatClient { /// Get all the reactions for a [messageId] Future getReactions( String messageId, { - PaginationParams? options, + PaginationParams? pagination, }) => _chatApi.message.getReactions( messageId, - options: options, + pagination: pagination, ); /// Update the given message diff --git a/packages/stream_chat/lib/src/core/api/message_api.dart b/packages/stream_chat/lib/src/core/api/message_api.dart index f50cb4a1..17269820 100644 --- a/packages/stream_chat/lib/src/core/api/message_api.dart +++ b/packages/stream_chat/lib/src/core/api/message_api.dart @@ -143,12 +143,12 @@ class MessageApi { /// Get all the reactions for a [messageId] Future 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); diff --git a/packages/stream_chat/test/src/core/api/message_api_test.dart b/packages/stream_chat/test/src/core/api/message_api_test.dart index d7fa93cd..1aacb6d2 100644 --- a/packages/stream_chat/test/src/core/api/message_api_test.dart +++ b/packages/stream_chat/test/src/core/api/message_api_test.dart @@ -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: {})); + when(() => client.post( + path, + data: { + 'id': channelId, + 'type': channelType, + 'form_data': formData, + 'message_id': messageId, + }, + )) + .thenAnswer( + (_) async => successResponse(path, data: {})); 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.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.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);