diff --git a/packages/stream_chat/test/src/api/channel_test.dart b/packages/stream_chat/test/src/api/channel_test.dart deleted file mode 100644 index 12e84fbc..00000000 --- a/packages/stream_chat/test/src/api/channel_test.dart +++ /dev/null @@ -1,2724 +0,0 @@ -import 'dart:convert'; - -import 'package:dio/dio.dart'; -import 'package:dio/native_imp.dart'; -import 'package:mocktail/mocktail.dart'; -import 'package:stream_chat/src/core/api/requests.dart'; -import 'package:stream_chat/src/client.dart'; -import 'package:stream_chat/src/event_type.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/own_user.dart'; -import 'package:stream_chat/src/core/models/reaction.dart'; -import 'package:stream_chat/stream_chat.dart'; -import 'package:test/test.dart'; - -class MockDio extends Mock implements DioForNative {} - -class FakeRequestOptions extends Fake implements RequestOptions {} - -class MockAttachmentUploader extends Mock implements AttachmentFileUploader {} - -class MockHttpClientAdapter extends Mock implements HttpClientAdapter {} - -void main() { - group('src/api/channel', () { - group('message', () { - test('sendMessage', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging', id: 'testid'); - final message = Message(text: 'hey', id: 'test'); - - when(() => mockDio.post( - any(), - data: any(named: 'data'), - )).thenAnswer((_) async => Response( - data: jsonEncode(ChannelState()), - statusCode: 200, - requestOptions: FakeRequestOptions(), - )); - - await channelClient.watch(); - - when( - () => mockDio.post( - '/channels/messaging/testid/message', - data: {'message': message.toJson()}, - ), - ).thenAnswer( - (_) async => Response( - data: jsonEncode({'message': message}), - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await channelClient.sendMessage(message); - - verify(() => - mockDio.post('/channels/messaging/testid/message', data: { - 'message': message.toJson(), - })).called(1); - }); - - test('markRead', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - - final channelClient = client.channel('messaging', id: 'testid'); - - when(() => mockDio.post( - any(), - data: any(named: 'data'), - )).thenAnswer((_) async => Response( - data: jsonEncode(ChannelState()), - statusCode: 200, - requestOptions: FakeRequestOptions(), - )); - await channelClient.watch(); - - when( - () => mockDio.post( - '/channels/messaging/testid/read', - data: {}, - ), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await channelClient.markRead(); - - verify(() => mockDio.post('/channels/messaging/testid/read', - data: {})).called(1); - }); - - test('getReplies', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging', id: 'testid'); - const pagination = PaginationParams(); - - when(() => mockDio.get('/messages/messageid/replies', - queryParameters: pagination.toJson())).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await channelClient.getReplies('messageid', pagination); - - verify(() => mockDio.get('/messages/messageid/replies', - queryParameters: pagination.toJson())).called(1); - }); - - test('sendAction', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging', id: 'testid'); - - when(() => mockDio.post( - any(), - data: any(named: 'data'), - )).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - await channelClient.watch(); - - final data = {'test': true}; - - when(() => mockDio.post('/messages/messageid/action', data: { - 'id': 'testid', - 'type': 'messaging', - 'form_data': data, - 'message_id': 'messageid', - })).thenAnswer((_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - )); - - await channelClient.sendAction(Message(id: 'messageid'), data); - - verify(() => mockDio.post('/messages/messageid/action', data: { - 'id': 'testid', - 'type': 'messaging', - 'form_data': data, - 'message_id': 'messageid', - })).called(1); - }); - - test('getMessagesById', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging', id: 'testid'); - final messageIds = ['a', 'b']; - - when(() => mockDio.get('/channels/messaging/testid/messages', - queryParameters: {'ids': messageIds.join(',')})).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await channelClient.getMessagesById(messageIds); - - verify(() => mockDio.get('/channels/messaging/testid/messages', - queryParameters: {'ids': messageIds.join(',')})).called(1); - }); - - test('sendFile', () async { - final mockDio = MockDio(); - final mockUploader = MockAttachmentUploader(); - - const file = AttachmentFile( - path: 'filePath/fileName.pdf', - size: 100, - ); - const channelId = 'testId'; - const channelType = 'messaging'; - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - attachmentFileUploader: mockUploader, - ); - final channelClient = client.channel(channelType, id: channelId); - - when(() => mockDio.post( - any(), - data: any(named: 'data'), - )).thenAnswer((_) async => Response( - data: jsonEncode(ChannelState()), - statusCode: 200, - requestOptions: FakeRequestOptions(), - )); - - await channelClient.watch(); - - when(() => mockUploader.sendFile(file, channelId, channelType)) - .thenAnswer((_) async => SendFileResponse()); - - await channelClient.sendFile(file); - - verify(() => mockUploader.sendFile(file, channelId, channelType)) - .called(1); - }); - - test('sendImage', () async { - final mockDio = MockDio(); - final mockUploader = MockAttachmentUploader(); - - const image = AttachmentFile( - path: 'imagePath/imageName.jpeg', - size: 100, - ); - const channelId = 'testId'; - const channelType = 'messaging'; - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - attachmentFileUploader: mockUploader, - ); - final channelClient = client.channel(channelType, id: channelId); - - when(() => mockDio.post( - any(), - data: any(named: 'data'), - )).thenAnswer((_) async => Response( - data: jsonEncode(ChannelState()), - statusCode: 200, - requestOptions: FakeRequestOptions(), - )); - - await channelClient.watch(); - - when(() => mockUploader.sendImage(image, channelId, channelType)) - .thenAnswer((_) async => SendImageResponse()); - - await channelClient.sendImage(image); - - verify(() => mockUploader.sendImage(image, channelId, channelType)) - .called(1); - }); - - test('deleteFile', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging', id: 'testid'); - const url = 'url'; - - when(() => mockDio.post( - any(), - data: any(named: 'data'), - )).thenAnswer((_) async => Response( - data: jsonEncode(ChannelState()), - statusCode: 200, - requestOptions: FakeRequestOptions(), - )); - - await channelClient.watch(); - - when( - () => mockDio.delete( - '/channels/messaging/testid/file', - queryParameters: {'url': url}, - ), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await channelClient.deleteFile(url); - - verify(() => mockDio.delete('/channels/messaging/testid/file', - queryParameters: {'url': url})).called(1); - }); - - test('deleteImage', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging', id: 'testid'); - const url = 'url'; - - when(() => mockDio.post( - any(), - data: any(named: 'data'), - )).thenAnswer((_) async => Response( - data: jsonEncode(ChannelState()), - statusCode: 200, - requestOptions: FakeRequestOptions(), - )); - - await channelClient.watch(); - - when( - () => mockDio.delete( - '/channels/messaging/testid/image', - queryParameters: {'url': url}, - ), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await channelClient.deleteImage(url); - - verify(() => mockDio.delete('/channels/messaging/testid/image', - queryParameters: {'url': url})).called(1); - }); - - test('pinMessage should throw argument error', () { - final client = StreamChatClient('api-key'); - - final channelClient = client.channel('messaging', id: 'testid'); - - final message = Message(text: 'Hello'); - - expect( - () => channelClient.pinMessage(message, 'InvalidType'), - throwsArgumentError, - ); - }); - - test('should be pinned successfully', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging', id: 'testid'); - final message = Message(text: 'Hello', id: 'test'); - - when(() => mockDio.post( - any(), - data: any(named: 'data'), - )).thenAnswer((_) async => Response( - data: jsonEncode(ChannelState()), - statusCode: 200, - requestOptions: FakeRequestOptions(), - )); - - await channelClient.watch(); - - when( - () => mockDio.post( - '/messages/${message.id}', - data: anything, - ), - ).thenAnswer( - (_) async => Response( - data: jsonEncode({'message': message}), - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await channelClient.pinMessage(message, 30); - - verify(() => - mockDio.post('/messages/${message.id}', data: anything)) - .called(1); - }); - - test('should be pinned successfully with null timeout', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging', id: 'testid'); - final message = Message(text: 'Hello', id: 'test'); - - when(() => mockDio.post( - any(), - data: any(named: 'data'), - )).thenAnswer((_) async => Response( - data: jsonEncode(ChannelState()), - statusCode: 200, - requestOptions: FakeRequestOptions(), - )); - - await channelClient.watch(); - - when( - () => mockDio.post( - '/messages/${message.id}', - data: anything, - ), - ).thenAnswer( - (_) async => Response( - data: jsonEncode({'message': message}), - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await channelClient.pinMessage(message); - - verify(() => - mockDio.post('/messages/${message.id}', data: anything)) - .called(1); - }); - - test('should be unpinned successfully', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging', id: 'testid'); - final message = Message(text: 'Hello', id: 'test'); - - when(() => mockDio.post( - any(), - data: any(named: 'data'), - )).thenAnswer((_) async => Response( - data: jsonEncode(ChannelState()), - statusCode: 200, - requestOptions: FakeRequestOptions(), - )); - - await channelClient.watch(); - - when( - () => mockDio.post( - '/messages/${message.id}', - data: anything, - ), - ).thenAnswer( - (_) async => Response( - data: jsonEncode({'message': message}), - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await channelClient.unpinMessage(message); - - verify(() => - mockDio.post('/messages/${message.id}', data: anything)) - .called(1); - }); - }); - - test('sendEvent', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging', id: 'testid'); - - when( - () => mockDio.post( - any(), - data: any(named: 'data'), - ), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - await channelClient.watch(); - - const event = Event(type: EventType.any); - - when( - () => mockDio.post( - '/channels/messaging/testid/event', - data: {'event': event.toJson()}, - ), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await channelClient.sendEvent(event); - - verify(() => mockDio.post('/channels/messaging/testid/event', - data: {'event': event.toJson()})).called(1); - }); - - test('keyStroke', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging', id: 'testid'); - - when( - () => mockDio.post( - any(), - data: any(named: 'data'), - ), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - await channelClient.watch(); - - const event = Event(type: EventType.typingStart); - - when( - () => mockDio.post( - '/channels/messaging/testid/event', - data: {'event': event.toJson()}, - ), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await channelClient.keyStroke(); - - verify(() => mockDio.post('/channels/messaging/testid/event', - data: {'event': event.toJson()})).called(1); - }); - - test('stopTyping', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging', id: 'testid'); - - when(() => mockDio.post( - any(), - data: any(named: 'data'), - )).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - await channelClient.watch(); - - const event = Event(type: EventType.typingStop); - - when( - () => mockDio.post( - '/channels/messaging/testid/event', - data: {'event': event.toJson()}, - ), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await channelClient.stopTyping(); - - verify(() => mockDio.post('/channels/messaging/testid/event', - data: {'event': event.toJson()})).called(1); - }); - - group('reactions', () { - test('sendReaction', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - - final user = OwnUser(id: 'test-id'); - - client.state.user = user; - - final message = Message(id: 'messageid'); - const reactionType = 'test'; - final reaction = Reaction(type: reactionType); - final channelClient = client.channel('messaging', id: 'testid'); - - when(() => mockDio.post( - any(), - data: any(named: 'data'), - )).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - await channelClient.watch(); - - when( - () => mockDio.post( - '/messages/${message.id}/reaction', - data: { - 'reaction': { - 'type': reactionType, - }, - 'enforce_unique': false, - }, - ), - ).thenAnswer( - (_) async => Response( - data: jsonEncode({ - 'message': message, - 'reaction': reaction, - }), - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await channelClient.sendReaction( - message, - reactionType, - ); - - verify( - () => mockDio.post('/messages/messageid/reaction', data: { - 'reaction': { - 'type': reactionType, - }, - 'enforce_unique': false, - })).called(1); - }); - - test('deleteReaction', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - - client.state.user = OwnUser(id: 'test-id'); - - final channelClient = client.channel('messaging', id: 'testid'); - - when( - () => mockDio.delete('/messages/messageid/reaction/test'), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await channelClient.deleteReaction( - Message( - id: 'messageid', - ), - Reaction( - type: 'test', - createdAt: DateTime.now(), - user: User( - id: client.state.user?.id ?? '', - ), - ), - ); - - verify(() => - mockDio.delete('/messages/messageid/reaction/test')) - .called(1); - }); - - test('getReactions', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging', id: 'testid'); - const pagination = PaginationParams(); - - when( - () => mockDio.get( - '/messages/messageid/reactions', - queryParameters: pagination.toJson(), - ), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await channelClient.getReactions('messageid', pagination); - - verify(() => mockDio.get('/messages/messageid/reactions', - queryParameters: pagination.toJson())).called(1); - }); - }); - - group('channel', () { - test('addMembers', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging', id: 'testid'); - final channelModel = ChannelModel(cid: 'messaging:testid'); - - when(() => mockDio.post( - any(), - data: any(named: 'data'), - )).thenAnswer((_) async => Response( - data: jsonEncode(ChannelState(channel: channelModel)), - statusCode: 200, - requestOptions: FakeRequestOptions(), - )); - - await channelClient.watch(); - - final members = [Member(userId: 'vishal')]; - final memberIds = members.map((e) => e.userId!).toList(); - final message = Message(text: 'test'); - - when( - () => mockDio.post( - '/channels/messaging/testid', - data: {'add_members': memberIds, 'message': message.toJson()}, - ), - ).thenAnswer( - (_) async => Response( - data: jsonEncode({ - 'members': members, - 'message': message, - 'channel': channelModel, - }), - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await channelClient.addMembers(memberIds, message); - - verify(() => mockDio.post('/channels/messaging/testid', - data: {'add_members': memberIds, 'message': message.toJson()})) - .called(1); - }); - - test('acceptInvite', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging', id: 'testid'); - final channelModel = ChannelModel(cid: 'messaging:testid'); - - when(() => mockDio.post( - any(), - data: any(named: 'data'), - )).thenAnswer((_) async => Response( - data: jsonEncode(ChannelState(channel: channelModel)), - statusCode: 200, - requestOptions: FakeRequestOptions(), - )); - - await channelClient.watch(); - - final message = Message(text: 'test'); - - when( - () => mockDio.post( - '/channels/messaging/testid', - data: {'accept_invite': true, 'message': message.toJson()}, - ), - ).thenAnswer( - (_) async => Response( - data: jsonEncode({ - 'message': message, - 'channel': channelModel, - }), - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await channelClient.acceptInvite(message); - - verify(() => mockDio.post('/channels/messaging/testid', - data: {'accept_invite': true, 'message': message.toJson()})) - .called(1); - }); - - group('query', () { - test('without id', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging'); - final options = { - 'watch': true, - 'state': false, - 'presence': true, - }; - - when(() => mockDio.post( - '/channels/messaging/query', - data: options, - )).thenAnswer( - (_) async => Response( - data: r''' - { - "channel": { - "id": "!members-0LOcD0mZtTan60zHobLmELjdndXsonnBVNzZnB5mTt0", - "type": "messaging", - "cid": "messaging:!members-0LOcD0mZtTan60zHobLmELjdndXsonnBVNzZnB5mTt0", - "last_message_at": "2020-01-28T22:17:31.204287Z", - "created_at": "2020-01-28T22:17:31.00187Z", - "updated_at": "2020-01-28T22:17:31.00187Z", - "created_by": { - "id": "spring-voice-7", - "role": "user", - "created_at": "2020-01-28T22:17:30.834135Z", - "updated_at": "2020-01-28T22:17:31.186771Z", - "banned": false, - "online": false, - "image": "https://getstream.io/random_svg/?id=spring-voice-7\u0026name=Spring+voice", - "name": "Spring voice" - }, - "frozen": false, - "member_count": 2, - "config": { - "created_at": "2020-01-29T12:59:14.291912835Z", - "updated_at": "2020-01-29T12:59:14.291912991Z", - "name": "messaging", - "typing_events": true, - "read_events": true, - "connect_events": true, - "search": true, - "reactions": true, - "replies": true, - "mutes": true, - "uploads": true, - "url_enrichment": true, - "message_retention": "infinite", - "max_message_length": 5000, - "automod": "disabled", - "automod_behavior": "flag", - "commands": [ - { - "name": "giphy", - "description": "Post a random gif to the channel", - "args": "[text]", - "set": "fun_set" - } - ] - }, - "name": "Mia Denys", - "image": "https://randomuser.me/api/portraits/women/2.jpg" - }, - "messages": [ - { - "id": "4637f7e4-a06b-42db-ba5a-8d8270dd926f", - "text": "https://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA", - "html": "\u003cp\u003e\u003ca href=\"https://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA\" rel=\"nofollow\"\u003ehttps://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA\u003c/a\u003e\u003c/p\u003e\n", - "type": "regular", - "user": { - "id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", - "role": "user", - "created_at": "2020-01-28T22:17:30.83015Z", - "updated_at": "2020-01-28T22:17:31.19435Z", - "banned": false, - "online": false, - "image": "https://randomuser.me/api/portraits/women/2.jpg", - "name": "Mia Denys" - }, - "attachments": [ - { - "type": "video", - "author_name": "GIPHY", - "title": "The Lion King Disney GIF - Find \u0026 Share on GIPHY", - "title_link": "https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.gif", - "text": "Discover \u0026 share this Lion King Live Action GIF with everyone you know. GIPHY is how you search, share, discover, and create GIFs.", - "image_url": "https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.gif", - "thumb_url": "https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.gif", - "asset_url": "https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.mp4", - "og_scrape_url": "https://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA" - } - ], - "latest_reactions": [ - { - "message_id": "4637f7e4-a06b-42db-ba5a-8d8270dd926f", - "user_id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", - "user": { - "id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", - "role": "user", - "created_at": "2020-01-28T22:17:30.83015Z", - "updated_at": "2020-01-28T22:17:31.19435Z", - "banned": false, - "online": false, - "image": "https://randomuser.me/api/portraits/women/2.jpg", - "name": "Mia Denys" - }, - "type": "love", - "score": 1, - "created_at": "2020-01-28T22:17:31.128376Z", - "updated_at": "2020-01-28T22:17:31.128376Z" - } - ], - "own_reactions": [], - "reaction_counts": { - "love": 1 - }, - "reaction_scores": { - "love": 1 - }, - "reply_count": 0, - "created_at": "2020-01-28T22:17:31.107978Z", - "updated_at": "2020-01-28T22:17:31.130506Z", - "mentioned_users": [] - }, - { - "id": "16e19c46-fb96-4f89-8031-d5bd2ce3bd64", - "text": "Few can name a topfull mother that isn't a breezeless damage.", - "html": "\u003cp\u003eFew can name a topfull mother that isn’t a breezeless damage.\u003c/p\u003e\n", - "type": "regular", - "user": { - "id": "spring-voice-7", - "role": "user", - "created_at": "2020-01-28T22:17:30.834135Z", - "updated_at": "2020-01-28T22:17:31.186771Z", - "banned": false, - "online": false, - "image": "https://getstream.io/random_svg/?id=spring-voice-7\u0026name=Spring+voice", - "name": "Spring voice" - }, - "attachments": [], - "latest_reactions": [], - "own_reactions": [], - "reaction_counts": {}, - "reaction_scores": {}, - "reply_count": 0, - "created_at": "2020-01-28T22:17:31.153518Z", - "updated_at": "2020-01-28T22:17:31.153518Z", - "mentioned_users": [] - }, - { - "id": "38b1b252-c9a6-4aea-a39e-8de3b7f7604b", - "text": "https://giphy.com/gifs/beard-muscle-73Sjhw0N4hyog", - "html": "\u003cp\u003e\u003ca href=\"https://giphy.com/gifs/beard-muscle-73Sjhw0N4hyog\" rel=\"nofollow\"\u003ehttps://giphy.com/gifs/beard-muscle-73Sjhw0N4hyog\u003c/a\u003e\u003c/p\u003e\n", - "type": "regular", - "user": { - "id": "spring-voice-7", - "role": "user", - "created_at": "2020-01-28T22:17:30.834135Z", - "updated_at": "2020-01-28T22:17:31.186771Z", - "banned": false, - "online": false, - "image": "https://getstream.io/random_svg/?id=spring-voice-7\u0026name=Spring+voice", - "name": "Spring voice" - }, - "attachments": [ - { - "type": "video", - "author_name": "GIPHY", - "title": "Moustache Thumbs Up GIF - Find \u0026 Share on GIPHY", - "title_link": "https://media.giphy.com/media/73Sjhw0N4hyog/giphy.gif", - "text": "Discover \u0026 share this Pouce Leve GIF with everyone you know. GIPHY is how you search, share, discover, and create GIFs.", - "image_url": "https://media.giphy.com/media/73Sjhw0N4hyog/giphy.gif", - "thumb_url": "https://media.giphy.com/media/73Sjhw0N4hyog/giphy.gif", - "asset_url": "https://media.giphy.com/media/73Sjhw0N4hyog/giphy.mp4", - "og_scrape_url": "https://giphy.com/gifs/beard-muscle-73Sjhw0N4hyog" - } - ], - "latest_reactions": [], - "own_reactions": [], - "reaction_counts": {}, - "reaction_scores": {}, - "reply_count": 0, - "created_at": "2020-01-28T22:17:31.155428Z", - "updated_at": "2020-01-28T22:17:31.155428Z", - "mentioned_users": [] - }, - { - "id": "5c7d0c68-72d5-4027-b6b7-711b342d0fc4", - "text": "The carbons could be said to resemble smartish hoods.", - "html": "\u003cp\u003eThe carbons could be said to resemble smartish hoods.\u003c/p\u003e\n", - "type": "regular", - "user": { - "id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", - "role": "user", - "created_at": "2020-01-28T22:17:30.83015Z", - "updated_at": "2020-01-28T22:17:31.19435Z", - "banned": false, - "online": false, - "image": "https://randomuser.me/api/portraits/women/2.jpg", - "name": "Mia Denys" - }, - "attachments": [], - "latest_reactions": [], - "own_reactions": [], - "reaction_counts": {}, - "reaction_scores": {}, - "reply_count": 1, - "created_at": "2020-01-28T22:17:31.157811Z", - "updated_at": "2020-01-28T22:17:31.157811Z", - "mentioned_users": [] - }, - { - "id": "5b02535a-0c3c-45fa-9cf8-16f840c5123f", - "text": "Their software was, in this moment, a prolix feature.", - "html": "\u003cp\u003eTheir software was, in this moment, a prolix feature.\u003c/p\u003e\n", - "type": "regular", - "user": { - "id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", - "role": "user", - "created_at": "2020-01-28T22:17:30.83015Z", - "updated_at": "2020-01-28T22:17:31.19435Z", - "banned": false, - "online": false, - "image": "https://randomuser.me/api/portraits/women/2.jpg", - "name": "Mia Denys" - }, - "attachments": [], - "latest_reactions": [], - "own_reactions": [], - "reaction_counts": {}, - "reaction_scores": {}, - "reply_count": 1, - "created_at": "2020-01-28T22:17:31.158391Z", - "updated_at": "2020-01-28T22:17:31.158391Z", - "mentioned_users": [] - } - ], - "watcher_count": 1, - "read": [ - { - "user": { - "id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", - "role": "user", - "created_at": "2020-01-28T22:17:30.83015Z", - "updated_at": "2020-01-28T22:17:31.19435Z", - "banned": false, - "online": false, - "image": "https://randomuser.me/api/portraits/women/2.jpg", - "name": "Mia Denys" - }, - "last_read": "2020-01-28T22:17:31.016937728Z" - }, - { - "user": { - "id": "spring-voice-7", - "role": "user", - "created_at": "2020-01-28T22:17:30.834135Z", - "updated_at": "2020-01-28T22:17:31.186771Z", - "banned": false, - "online": false, - "image": "https://getstream.io/random_svg/?id=spring-voice-7\u0026name=Spring+voice", - "name": "Spring voice" - }, - "last_read": "2020-01-28T22:17:31.018856448Z" - } - ], - "members": [ - { - "user": { - "id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", - "role": "user", - "created_at": "2020-01-28T22:17:30.83015Z", - "updated_at": "2020-01-28T22:17:31.19435Z", - "banned": false, - "online": false, - "image": "https://randomuser.me/api/portraits/women/2.jpg", - "name": "Mia Denys" - }, - "role": "member", - "created_at": "2020-01-28T22:17:31.005135Z", - "updated_at": "2020-01-28T22:17:31.005135Z" - }, - { - "user": { - "id": "spring-voice-7", - "role": "user", - "created_at": "2020-01-28T22:17:30.834135Z", - "updated_at": "2020-01-28T22:17:31.186771Z", - "banned": false, - "online": false, - "image": "https://getstream.io/random_svg/?id=spring-voice-7\u0026name=Spring+voice", - "name": "Spring voice" - }, - "role": "owner", - "created_at": "2020-01-28T22:17:31.005135Z", - "updated_at": "2020-01-28T22:17:31.005135Z" - } - ] - } - ''', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - final response = await channelClient.query(options: options); - - verify(() => mockDio.post( - '/channels/messaging/query', - data: options, - )).called(1); - expect(channelClient.id, response.channel?.id); - expect(channelClient.cid, response.channel?.cid); - }); - - test('with id', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging', id: 'testid'); - final options = {'state': false}; - - when(() => mockDio.post('/channels/messaging/testid/query', - data: options)).thenAnswer( - (_) async => Response( - data: r''' - { - "channel": { - "id": "!members-0LOcD0mZtTan60zHobLmELjdndXsonnBVNzZnB5mTt0", - "type": "messaging", - "cid": "messaging:!members-0LOcD0mZtTan60zHobLmELjdndXsonnBVNzZnB5mTt0", - "last_message_at": "2020-01-28T22:17:31.204287Z", - "created_at": "2020-01-28T22:17:31.00187Z", - "updated_at": "2020-01-28T22:17:31.00187Z", - "created_by": { - "id": "spring-voice-7", - "role": "user", - "created_at": "2020-01-28T22:17:30.834135Z", - "updated_at": "2020-01-28T22:17:31.186771Z", - "banned": false, - "online": false, - "image": "https://getstream.io/random_svg/?id=spring-voice-7\u0026name=Spring+voice", - "name": "Spring voice" - }, - "frozen": false, - "member_count": 2, - "config": { - "created_at": "2020-01-29T12:59:14.291912835Z", - "updated_at": "2020-01-29T12:59:14.291912991Z", - "name": "messaging", - "typing_events": true, - "read_events": true, - "connect_events": true, - "search": true, - "reactions": true, - "replies": true, - "mutes": true, - "uploads": true, - "url_enrichment": true, - "message_retention": "infinite", - "max_message_length": 5000, - "automod": "disabled", - "automod_behavior": "flag", - "commands": [ - { - "name": "giphy", - "description": "Post a random gif to the channel", - "args": "[text]", - "set": "fun_set" - } - ] - }, - "name": "Mia Denys", - "image": "https://randomuser.me/api/portraits/women/2.jpg" - }, - "messages": [ - { - "id": "4637f7e4-a06b-42db-ba5a-8d8270dd926f", - "text": "https://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA", - "html": "\u003cp\u003e\u003ca href=\"https://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA\" rel=\"nofollow\"\u003ehttps://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA\u003c/a\u003e\u003c/p\u003e\n", - "type": "regular", - "user": { - "id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", - "role": "user", - "created_at": "2020-01-28T22:17:30.83015Z", - "updated_at": "2020-01-28T22:17:31.19435Z", - "banned": false, - "online": false, - "image": "https://randomuser.me/api/portraits/women/2.jpg", - "name": "Mia Denys" - }, - "attachments": [ - { - "type": "video", - "author_name": "GIPHY", - "title": "The Lion King Disney GIF - Find \u0026 Share on GIPHY", - "title_link": "https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.gif", - "text": "Discover \u0026 share this Lion King Live Action GIF with everyone you know. GIPHY is how you search, share, discover, and create GIFs.", - "image_url": "https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.gif", - "thumb_url": "https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.gif", - "asset_url": "https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.mp4", - "og_scrape_url": "https://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA" - } - ], - "latest_reactions": [ - { - "message_id": "4637f7e4-a06b-42db-ba5a-8d8270dd926f", - "user_id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", - "user": { - "id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", - "role": "user", - "created_at": "2020-01-28T22:17:30.83015Z", - "updated_at": "2020-01-28T22:17:31.19435Z", - "banned": false, - "online": false, - "image": "https://randomuser.me/api/portraits/women/2.jpg", - "name": "Mia Denys" - }, - "type": "love", - "score": 1, - "created_at": "2020-01-28T22:17:31.128376Z", - "updated_at": "2020-01-28T22:17:31.128376Z" - } - ], - "own_reactions": [], - "reaction_counts": { - "love": 1 - }, - "reaction_scores": { - "love": 1 - }, - "reply_count": 0, - "created_at": "2020-01-28T22:17:31.107978Z", - "updated_at": "2020-01-28T22:17:31.130506Z", - "mentioned_users": [] - }, - { - "id": "16e19c46-fb96-4f89-8031-d5bd2ce3bd64", - "text": "Few can name a topfull mother that isn't a breezeless damage.", - "html": "\u003cp\u003eFew can name a topfull mother that isn’t a breezeless damage.\u003c/p\u003e\n", - "type": "regular", - "user": { - "id": "spring-voice-7", - "role": "user", - "created_at": "2020-01-28T22:17:30.834135Z", - "updated_at": "2020-01-28T22:17:31.186771Z", - "banned": false, - "online": false, - "image": "https://getstream.io/random_svg/?id=spring-voice-7\u0026name=Spring+voice", - "name": "Spring voice" - }, - "attachments": [], - "latest_reactions": [], - "own_reactions": [], - "reaction_counts": {}, - "reaction_scores": {}, - "reply_count": 0, - "created_at": "2020-01-28T22:17:31.153518Z", - "updated_at": "2020-01-28T22:17:31.153518Z", - "mentioned_users": [] - }, - { - "id": "38b1b252-c9a6-4aea-a39e-8de3b7f7604b", - "text": "https://giphy.com/gifs/beard-muscle-73Sjhw0N4hyog", - "html": "\u003cp\u003e\u003ca href=\"https://giphy.com/gifs/beard-muscle-73Sjhw0N4hyog\" rel=\"nofollow\"\u003ehttps://giphy.com/gifs/beard-muscle-73Sjhw0N4hyog\u003c/a\u003e\u003c/p\u003e\n", - "type": "regular", - "user": { - "id": "spring-voice-7", - "role": "user", - "created_at": "2020-01-28T22:17:30.834135Z", - "updated_at": "2020-01-28T22:17:31.186771Z", - "banned": false, - "online": false, - "image": "https://getstream.io/random_svg/?id=spring-voice-7\u0026name=Spring+voice", - "name": "Spring voice" - }, - "attachments": [ - { - "type": "video", - "author_name": "GIPHY", - "title": "Moustache Thumbs Up GIF - Find \u0026 Share on GIPHY", - "title_link": "https://media.giphy.com/media/73Sjhw0N4hyog/giphy.gif", - "text": "Discover \u0026 share this Pouce Leve GIF with everyone you know. GIPHY is how you search, share, discover, and create GIFs.", - "image_url": "https://media.giphy.com/media/73Sjhw0N4hyog/giphy.gif", - "thumb_url": "https://media.giphy.com/media/73Sjhw0N4hyog/giphy.gif", - "asset_url": "https://media.giphy.com/media/73Sjhw0N4hyog/giphy.mp4", - "og_scrape_url": "https://giphy.com/gifs/beard-muscle-73Sjhw0N4hyog" - } - ], - "latest_reactions": [], - "own_reactions": [], - "reaction_counts": {}, - "reaction_scores": {}, - "reply_count": 0, - "created_at": "2020-01-28T22:17:31.155428Z", - "updated_at": "2020-01-28T22:17:31.155428Z", - "mentioned_users": [] - }, - { - "id": "5c7d0c68-72d5-4027-b6b7-711b342d0fc4", - "text": "The carbons could be said to resemble smartish hoods.", - "html": "\u003cp\u003eThe carbons could be said to resemble smartish hoods.\u003c/p\u003e\n", - "type": "regular", - "user": { - "id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", - "role": "user", - "created_at": "2020-01-28T22:17:30.83015Z", - "updated_at": "2020-01-28T22:17:31.19435Z", - "banned": false, - "online": false, - "image": "https://randomuser.me/api/portraits/women/2.jpg", - "name": "Mia Denys" - }, - "attachments": [], - "latest_reactions": [], - "own_reactions": [], - "reaction_counts": {}, - "reaction_scores": {}, - "reply_count": 1, - "created_at": "2020-01-28T22:17:31.157811Z", - "updated_at": "2020-01-28T22:17:31.157811Z", - "mentioned_users": [] - }, - { - "id": "5b02535a-0c3c-45fa-9cf8-16f840c5123f", - "text": "Their software was, in this moment, a prolix feature.", - "html": "\u003cp\u003eTheir software was, in this moment, a prolix feature.\u003c/p\u003e\n", - "type": "regular", - "user": { - "id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", - "role": "user", - "created_at": "2020-01-28T22:17:30.83015Z", - "updated_at": "2020-01-28T22:17:31.19435Z", - "banned": false, - "online": false, - "image": "https://randomuser.me/api/portraits/women/2.jpg", - "name": "Mia Denys" - }, - "attachments": [], - "latest_reactions": [], - "own_reactions": [], - "reaction_counts": {}, - "reaction_scores": {}, - "reply_count": 1, - "created_at": "2020-01-28T22:17:31.158391Z", - "updated_at": "2020-01-28T22:17:31.158391Z", - "mentioned_users": [] - } - ], - "watcher_count": 1, - "read": [ - { - "user": { - "id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", - "role": "user", - "created_at": "2020-01-28T22:17:30.83015Z", - "updated_at": "2020-01-28T22:17:31.19435Z", - "banned": false, - "online": false, - "image": "https://randomuser.me/api/portraits/women/2.jpg", - "name": "Mia Denys" - }, - "last_read": "2020-01-28T22:17:31.016937728Z" - }, - { - "user": { - "id": "spring-voice-7", - "role": "user", - "created_at": "2020-01-28T22:17:30.834135Z", - "updated_at": "2020-01-28T22:17:31.186771Z", - "banned": false, - "online": false, - "image": "https://getstream.io/random_svg/?id=spring-voice-7\u0026name=Spring+voice", - "name": "Spring voice" - }, - "last_read": "2020-01-28T22:17:31.018856448Z" - } - ], - "members": [ - { - "user": { - "id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", - "role": "user", - "created_at": "2020-01-28T22:17:30.83015Z", - "updated_at": "2020-01-28T22:17:31.19435Z", - "banned": false, - "online": false, - "image": "https://randomuser.me/api/portraits/women/2.jpg", - "name": "Mia Denys" - }, - "role": "member", - "created_at": "2020-01-28T22:17:31.005135Z", - "updated_at": "2020-01-28T22:17:31.005135Z" - }, - { - "user": { - "id": "spring-voice-7", - "role": "user", - "created_at": "2020-01-28T22:17:30.834135Z", - "updated_at": "2020-01-28T22:17:31.186771Z", - "banned": false, - "online": false, - "image": "https://getstream.io/random_svg/?id=spring-voice-7\u0026name=Spring+voice", - "name": "Spring voice" - }, - "role": "owner", - "created_at": "2020-01-28T22:17:31.005135Z", - "updated_at": "2020-01-28T22:17:31.005135Z" - } - ] - } - ''', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await channelClient.query(options: options); - - verify(() => mockDio.post('/channels/messaging/testid/query', - data: options)).called(1); - }); - }); - - test('create', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging'); - final options = { - 'watch': false, - 'state': false, - 'presence': false, - }; - - when(() => mockDio.post('/channels/messaging/query', - data: options)).thenAnswer( - (_) async => Response( - data: r''' - { - "channel": { - "id": "!members-0LOcD0mZtTan60zHobLmELjdndXsonnBVNzZnB5mTt0", - "type": "messaging", - "cid": "messaging:!members-0LOcD0mZtTan60zHobLmELjdndXsonnBVNzZnB5mTt0", - "last_message_at": "2020-01-28T22:17:31.204287Z", - "created_at": "2020-01-28T22:17:31.00187Z", - "updated_at": "2020-01-28T22:17:31.00187Z", - "created_by": { - "id": "spring-voice-7", - "role": "user", - "created_at": "2020-01-28T22:17:30.834135Z", - "updated_at": "2020-01-28T22:17:31.186771Z", - "banned": false, - "online": false, - "image": "https://getstream.io/random_svg/?id=spring-voice-7\u0026name=Spring+voice", - "name": "Spring voice" - }, - "frozen": false, - "member_count": 2, - "config": { - "created_at": "2020-01-29T12:59:14.291912835Z", - "updated_at": "2020-01-29T12:59:14.291912991Z", - "name": "messaging", - "typing_events": true, - "read_events": true, - "connect_events": true, - "search": true, - "reactions": true, - "replies": true, - "mutes": true, - "uploads": true, - "url_enrichment": true, - "message_retention": "infinite", - "max_message_length": 5000, - "automod": "disabled", - "automod_behavior": "flag", - "commands": [ - { - "name": "giphy", - "description": "Post a random gif to the channel", - "args": "[text]", - "set": "fun_set" - } - ] - }, - "name": "Mia Denys", - "image": "https://randomuser.me/api/portraits/women/2.jpg" - }, - "messages": [ - { - "id": "4637f7e4-a06b-42db-ba5a-8d8270dd926f", - "text": "https://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA", - "html": "\u003cp\u003e\u003ca href=\"https://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA\" rel=\"nofollow\"\u003ehttps://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA\u003c/a\u003e\u003c/p\u003e\n", - "type": "regular", - "user": { - "id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", - "role": "user", - "created_at": "2020-01-28T22:17:30.83015Z", - "updated_at": "2020-01-28T22:17:31.19435Z", - "banned": false, - "online": false, - "image": "https://randomuser.me/api/portraits/women/2.jpg", - "name": "Mia Denys" - }, - "attachments": [ - { - "type": "video", - "author_name": "GIPHY", - "title": "The Lion King Disney GIF - Find \u0026 Share on GIPHY", - "title_link": "https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.gif", - "text": "Discover \u0026 share this Lion King Live Action GIF with everyone you know. GIPHY is how you search, share, discover, and create GIFs.", - "image_url": "https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.gif", - "thumb_url": "https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.gif", - "asset_url": "https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.mp4", - "og_scrape_url": "https://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA" - } - ], - "latest_reactions": [ - { - "message_id": "4637f7e4-a06b-42db-ba5a-8d8270dd926f", - "user_id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", - "user": { - "id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", - "role": "user", - "created_at": "2020-01-28T22:17:30.83015Z", - "updated_at": "2020-01-28T22:17:31.19435Z", - "banned": false, - "online": false, - "image": "https://randomuser.me/api/portraits/women/2.jpg", - "name": "Mia Denys" - }, - "type": "love", - "score": 1, - "created_at": "2020-01-28T22:17:31.128376Z", - "updated_at": "2020-01-28T22:17:31.128376Z" - } - ], - "own_reactions": [], - "reaction_counts": { - "love": 1 - }, - "reaction_scores": { - "love": 1 - }, - "reply_count": 0, - "created_at": "2020-01-28T22:17:31.107978Z", - "updated_at": "2020-01-28T22:17:31.130506Z", - "mentioned_users": [] - }, - { - "id": "16e19c46-fb96-4f89-8031-d5bd2ce3bd64", - "text": "Few can name a topfull mother that isn't a breezeless damage.", - "html": "\u003cp\u003eFew can name a topfull mother that isn’t a breezeless damage.\u003c/p\u003e\n", - "type": "regular", - "user": { - "id": "spring-voice-7", - "role": "user", - "created_at": "2020-01-28T22:17:30.834135Z", - "updated_at": "2020-01-28T22:17:31.186771Z", - "banned": false, - "online": false, - "image": "https://getstream.io/random_svg/?id=spring-voice-7\u0026name=Spring+voice", - "name": "Spring voice" - }, - "attachments": [], - "latest_reactions": [], - "own_reactions": [], - "reaction_counts": {}, - "reaction_scores": {}, - "reply_count": 0, - "created_at": "2020-01-28T22:17:31.153518Z", - "updated_at": "2020-01-28T22:17:31.153518Z", - "mentioned_users": [] - }, - { - "id": "38b1b252-c9a6-4aea-a39e-8de3b7f7604b", - "text": "https://giphy.com/gifs/beard-muscle-73Sjhw0N4hyog", - "html": "\u003cp\u003e\u003ca href=\"https://giphy.com/gifs/beard-muscle-73Sjhw0N4hyog\" rel=\"nofollow\"\u003ehttps://giphy.com/gifs/beard-muscle-73Sjhw0N4hyog\u003c/a\u003e\u003c/p\u003e\n", - "type": "regular", - "user": { - "id": "spring-voice-7", - "role": "user", - "created_at": "2020-01-28T22:17:30.834135Z", - "updated_at": "2020-01-28T22:17:31.186771Z", - "banned": false, - "online": false, - "image": "https://getstream.io/random_svg/?id=spring-voice-7\u0026name=Spring+voice", - "name": "Spring voice" - }, - "attachments": [ - { - "type": "video", - "author_name": "GIPHY", - "title": "Moustache Thumbs Up GIF - Find \u0026 Share on GIPHY", - "title_link": "https://media.giphy.com/media/73Sjhw0N4hyog/giphy.gif", - "text": "Discover \u0026 share this Pouce Leve GIF with everyone you know. GIPHY is how you search, share, discover, and create GIFs.", - "image_url": "https://media.giphy.com/media/73Sjhw0N4hyog/giphy.gif", - "thumb_url": "https://media.giphy.com/media/73Sjhw0N4hyog/giphy.gif", - "asset_url": "https://media.giphy.com/media/73Sjhw0N4hyog/giphy.mp4", - "og_scrape_url": "https://giphy.com/gifs/beard-muscle-73Sjhw0N4hyog" - } - ], - "latest_reactions": [], - "own_reactions": [], - "reaction_counts": {}, - "reaction_scores": {}, - "reply_count": 0, - "created_at": "2020-01-28T22:17:31.155428Z", - "updated_at": "2020-01-28T22:17:31.155428Z", - "mentioned_users": [] - }, - { - "id": "5c7d0c68-72d5-4027-b6b7-711b342d0fc4", - "text": "The carbons could be said to resemble smartish hoods.", - "html": "\u003cp\u003eThe carbons could be said to resemble smartish hoods.\u003c/p\u003e\n", - "type": "regular", - "user": { - "id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", - "role": "user", - "created_at": "2020-01-28T22:17:30.83015Z", - "updated_at": "2020-01-28T22:17:31.19435Z", - "banned": false, - "online": false, - "image": "https://randomuser.me/api/portraits/women/2.jpg", - "name": "Mia Denys" - }, - "attachments": [], - "latest_reactions": [], - "own_reactions": [], - "reaction_counts": {}, - "reaction_scores": {}, - "reply_count": 1, - "created_at": "2020-01-28T22:17:31.157811Z", - "updated_at": "2020-01-28T22:17:31.157811Z", - "mentioned_users": [] - }, - { - "id": "5b02535a-0c3c-45fa-9cf8-16f840c5123f", - "text": "Their software was, in this moment, a prolix feature.", - "html": "\u003cp\u003eTheir software was, in this moment, a prolix feature.\u003c/p\u003e\n", - "type": "regular", - "user": { - "id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", - "role": "user", - "created_at": "2020-01-28T22:17:30.83015Z", - "updated_at": "2020-01-28T22:17:31.19435Z", - "banned": false, - "online": false, - "image": "https://randomuser.me/api/portraits/women/2.jpg", - "name": "Mia Denys" - }, - "attachments": [], - "latest_reactions": [], - "own_reactions": [], - "reaction_counts": {}, - "reaction_scores": {}, - "reply_count": 1, - "created_at": "2020-01-28T22:17:31.158391Z", - "updated_at": "2020-01-28T22:17:31.158391Z", - "mentioned_users": [] - } - ], - "watcher_count": 1, - "read": [ - { - "user": { - "id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", - "role": "user", - "created_at": "2020-01-28T22:17:30.83015Z", - "updated_at": "2020-01-28T22:17:31.19435Z", - "banned": false, - "online": false, - "image": "https://randomuser.me/api/portraits/women/2.jpg", - "name": "Mia Denys" - }, - "last_read": "2020-01-28T22:17:31.016937728Z" - }, - { - "user": { - "id": "spring-voice-7", - "role": "user", - "created_at": "2020-01-28T22:17:30.834135Z", - "updated_at": "2020-01-28T22:17:31.186771Z", - "banned": false, - "online": false, - "image": "https://getstream.io/random_svg/?id=spring-voice-7\u0026name=Spring+voice", - "name": "Spring voice" - }, - "last_read": "2020-01-28T22:17:31.018856448Z" - } - ], - "members": [ - { - "user": { - "id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", - "role": "user", - "created_at": "2020-01-28T22:17:30.83015Z", - "updated_at": "2020-01-28T22:17:31.19435Z", - "banned": false, - "online": false, - "image": "https://randomuser.me/api/portraits/women/2.jpg", - "name": "Mia Denys" - }, - "role": "member", - "created_at": "2020-01-28T22:17:31.005135Z", - "updated_at": "2020-01-28T22:17:31.005135Z" - }, - { - "user": { - "id": "spring-voice-7", - "role": "user", - "created_at": "2020-01-28T22:17:30.834135Z", - "updated_at": "2020-01-28T22:17:31.186771Z", - "banned": false, - "online": false, - "image": "https://getstream.io/random_svg/?id=spring-voice-7\u0026name=Spring+voice", - "name": "Spring voice" - }, - "role": "owner", - "created_at": "2020-01-28T22:17:31.005135Z", - "updated_at": "2020-01-28T22:17:31.005135Z" - } - ] - } - ''', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - final response = await channelClient.create(); - - verify(() => mockDio.post('/channels/messaging/query', - data: options)).called(1); - expect(channelClient.id, response.channel?.id); - expect(channelClient.cid, response.channel?.cid); - }); - - test('watch', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging'); - final options = { - 'watch': true, - 'state': true, - 'presence': true, - }; - - when(() => mockDio.post('/channels/messaging/query', - data: options)).thenAnswer( - (_) async => Response( - data: r''' - { - "channel": { - "id": "!members-0LOcD0mZtTan60zHobLmELjdndXsonnBVNzZnB5mTt0", - "type": "messaging", - "cid": "messaging:!members-0LOcD0mZtTan60zHobLmELjdndXsonnBVNzZnB5mTt0", - "last_message_at": "2020-01-28T22:17:31.204287Z", - "created_at": "2020-01-28T22:17:31.00187Z", - "updated_at": "2020-01-28T22:17:31.00187Z", - "created_by": { - "id": "spring-voice-7", - "role": "user", - "created_at": "2020-01-28T22:17:30.834135Z", - "updated_at": "2020-01-28T22:17:31.186771Z", - "banned": false, - "online": false, - "image": "https://getstream.io/random_svg/?id=spring-voice-7\u0026name=Spring+voice", - "name": "Spring voice" - }, - "frozen": false, - "member_count": 2, - "config": { - "created_at": "2020-01-29T12:59:14.291912835Z", - "updated_at": "2020-01-29T12:59:14.291912991Z", - "name": "messaging", - "typing_events": true, - "read_events": true, - "connect_events": true, - "search": true, - "reactions": true, - "replies": true, - "mutes": true, - "uploads": true, - "url_enrichment": true, - "message_retention": "infinite", - "max_message_length": 5000, - "automod": "disabled", - "automod_behavior": "flag", - "commands": [ - { - "name": "giphy", - "description": "Post a random gif to the channel", - "args": "[text]", - "set": "fun_set" - } - ] - }, - "name": "Mia Denys", - "image": "https://randomuser.me/api/portraits/women/2.jpg" - }, - "messages": [ - { - "id": "4637f7e4-a06b-42db-ba5a-8d8270dd926f", - "text": "https://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA", - "html": "\u003cp\u003e\u003ca href=\"https://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA\" rel=\"nofollow\"\u003ehttps://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA\u003c/a\u003e\u003c/p\u003e\n", - "type": "regular", - "user": { - "id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", - "role": "user", - "created_at": "2020-01-28T22:17:30.83015Z", - "updated_at": "2020-01-28T22:17:31.19435Z", - "banned": false, - "online": false, - "image": "https://randomuser.me/api/portraits/women/2.jpg", - "name": "Mia Denys" - }, - "attachments": [ - { - "type": "video", - "author_name": "GIPHY", - "title": "The Lion King Disney GIF - Find \u0026 Share on GIPHY", - "title_link": "https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.gif", - "text": "Discover \u0026 share this Lion King Live Action GIF with everyone you know. GIPHY is how you search, share, discover, and create GIFs.", - "image_url": "https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.gif", - "thumb_url": "https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.gif", - "asset_url": "https://media.giphy.com/media/5zvN79uTGfLMOVfQaA/giphy.mp4", - "og_scrape_url": "https://giphy.com/gifs/the-lion-king-live-action-5zvN79uTGfLMOVfQaA" - } - ], - "latest_reactions": [ - { - "message_id": "4637f7e4-a06b-42db-ba5a-8d8270dd926f", - "user_id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", - "user": { - "id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", - "role": "user", - "created_at": "2020-01-28T22:17:30.83015Z", - "updated_at": "2020-01-28T22:17:31.19435Z", - "banned": false, - "online": false, - "image": "https://randomuser.me/api/portraits/women/2.jpg", - "name": "Mia Denys" - }, - "type": "love", - "score": 1, - "created_at": "2020-01-28T22:17:31.128376Z", - "updated_at": "2020-01-28T22:17:31.128376Z" - } - ], - "own_reactions": [], - "reaction_counts": { - "love": 1 - }, - "reaction_scores": { - "love": 1 - }, - "reply_count": 0, - "created_at": "2020-01-28T22:17:31.107978Z", - "updated_at": "2020-01-28T22:17:31.130506Z", - "mentioned_users": [] - }, - { - "id": "16e19c46-fb96-4f89-8031-d5bd2ce3bd64", - "text": "Few can name a topfull mother that isn't a breezeless damage.", - "html": "\u003cp\u003eFew can name a topfull mother that isn’t a breezeless damage.\u003c/p\u003e\n", - "type": "regular", - "user": { - "id": "spring-voice-7", - "role": "user", - "created_at": "2020-01-28T22:17:30.834135Z", - "updated_at": "2020-01-28T22:17:31.186771Z", - "banned": false, - "online": false, - "image": "https://getstream.io/random_svg/?id=spring-voice-7\u0026name=Spring+voice", - "name": "Spring voice" - }, - "attachments": [], - "latest_reactions": [], - "own_reactions": [], - "reaction_counts": {}, - "reaction_scores": {}, - "reply_count": 0, - "created_at": "2020-01-28T22:17:31.153518Z", - "updated_at": "2020-01-28T22:17:31.153518Z", - "mentioned_users": [] - }, - { - "id": "38b1b252-c9a6-4aea-a39e-8de3b7f7604b", - "text": "https://giphy.com/gifs/beard-muscle-73Sjhw0N4hyog", - "html": "\u003cp\u003e\u003ca href=\"https://giphy.com/gifs/beard-muscle-73Sjhw0N4hyog\" rel=\"nofollow\"\u003ehttps://giphy.com/gifs/beard-muscle-73Sjhw0N4hyog\u003c/a\u003e\u003c/p\u003e\n", - "type": "regular", - "user": { - "id": "spring-voice-7", - "role": "user", - "created_at": "2020-01-28T22:17:30.834135Z", - "updated_at": "2020-01-28T22:17:31.186771Z", - "banned": false, - "online": false, - "image": "https://getstream.io/random_svg/?id=spring-voice-7\u0026name=Spring+voice", - "name": "Spring voice" - }, - "attachments": [ - { - "type": "video", - "author_name": "GIPHY", - "title": "Moustache Thumbs Up GIF - Find \u0026 Share on GIPHY", - "title_link": "https://media.giphy.com/media/73Sjhw0N4hyog/giphy.gif", - "text": "Discover \u0026 share this Pouce Leve GIF with everyone you know. GIPHY is how you search, share, discover, and create GIFs.", - "image_url": "https://media.giphy.com/media/73Sjhw0N4hyog/giphy.gif", - "thumb_url": "https://media.giphy.com/media/73Sjhw0N4hyog/giphy.gif", - "asset_url": "https://media.giphy.com/media/73Sjhw0N4hyog/giphy.mp4", - "og_scrape_url": "https://giphy.com/gifs/beard-muscle-73Sjhw0N4hyog" - } - ], - "latest_reactions": [], - "own_reactions": [], - "reaction_counts": {}, - "reaction_scores": {}, - "reply_count": 0, - "created_at": "2020-01-28T22:17:31.155428Z", - "updated_at": "2020-01-28T22:17:31.155428Z", - "mentioned_users": [] - }, - { - "id": "5c7d0c68-72d5-4027-b6b7-711b342d0fc4", - "text": "The carbons could be said to resemble smartish hoods.", - "html": "\u003cp\u003eThe carbons could be said to resemble smartish hoods.\u003c/p\u003e\n", - "type": "regular", - "user": { - "id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", - "role": "user", - "created_at": "2020-01-28T22:17:30.83015Z", - "updated_at": "2020-01-28T22:17:31.19435Z", - "banned": false, - "online": false, - "image": "https://randomuser.me/api/portraits/women/2.jpg", - "name": "Mia Denys" - }, - "attachments": [], - "latest_reactions": [], - "own_reactions": [], - "reaction_counts": {}, - "reaction_scores": {}, - "reply_count": 1, - "created_at": "2020-01-28T22:17:31.157811Z", - "updated_at": "2020-01-28T22:17:31.157811Z", - "mentioned_users": [] - }, - { - "id": "5b02535a-0c3c-45fa-9cf8-16f840c5123f", - "text": "Their software was, in this moment, a prolix feature.", - "html": "\u003cp\u003eTheir software was, in this moment, a prolix feature.\u003c/p\u003e\n", - "type": "regular", - "user": { - "id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", - "role": "user", - "created_at": "2020-01-28T22:17:30.83015Z", - "updated_at": "2020-01-28T22:17:31.19435Z", - "banned": false, - "online": false, - "image": "https://randomuser.me/api/portraits/women/2.jpg", - "name": "Mia Denys" - }, - "attachments": [], - "latest_reactions": [], - "own_reactions": [], - "reaction_counts": {}, - "reaction_scores": {}, - "reply_count": 1, - "created_at": "2020-01-28T22:17:31.158391Z", - "updated_at": "2020-01-28T22:17:31.158391Z", - "mentioned_users": [] - } - ], - "watcher_count": 1, - "read": [ - { - "user": { - "id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", - "role": "user", - "created_at": "2020-01-28T22:17:30.83015Z", - "updated_at": "2020-01-28T22:17:31.19435Z", - "banned": false, - "online": false, - "image": "https://randomuser.me/api/portraits/women/2.jpg", - "name": "Mia Denys" - }, - "last_read": "2020-01-28T22:17:31.016937728Z" - }, - { - "user": { - "id": "spring-voice-7", - "role": "user", - "created_at": "2020-01-28T22:17:30.834135Z", - "updated_at": "2020-01-28T22:17:31.186771Z", - "banned": false, - "online": false, - "image": "https://getstream.io/random_svg/?id=spring-voice-7\u0026name=Spring+voice", - "name": "Spring voice" - }, - "last_read": "2020-01-28T22:17:31.018856448Z" - } - ], - "members": [ - { - "user": { - "id": "c1c9b454-2bcc-402d-8bb0-2f3706ce1680", - "role": "user", - "created_at": "2020-01-28T22:17:30.83015Z", - "updated_at": "2020-01-28T22:17:31.19435Z", - "banned": false, - "online": false, - "image": "https://randomuser.me/api/portraits/women/2.jpg", - "name": "Mia Denys" - }, - "role": "member", - "created_at": "2020-01-28T22:17:31.005135Z", - "updated_at": "2020-01-28T22:17:31.005135Z" - }, - { - "user": { - "id": "spring-voice-7", - "role": "user", - "created_at": "2020-01-28T22:17:30.834135Z", - "updated_at": "2020-01-28T22:17:31.186771Z", - "banned": false, - "online": false, - "image": "https://getstream.io/random_svg/?id=spring-voice-7\u0026name=Spring+voice", - "name": "Spring voice" - }, - "role": "owner", - "created_at": "2020-01-28T22:17:31.005135Z", - "updated_at": "2020-01-28T22:17:31.005135Z" - } - ] - } - ''', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - final response = await channelClient.watch({'presence': true}); - - verify(() => mockDio.post('/channels/messaging/query', - data: options)).called(1); - expect(channelClient.id, response.channel?.id); - expect(channelClient.cid, response.channel?.cid); - }); - - test('stopWatching', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging', id: 'testid'); - - when( - () => mockDio.post( - '/channels/messaging/testid/stop-watching', - data: {}, - ), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await channelClient.stopWatching(); - - verify(() => mockDio.post( - '/channels/messaging/testid/stop-watching', - data: {}, - )).called(1); - }); - - test('update', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging', id: 'testid'); - final channelModel = ChannelModel(cid: 'messaging:testid'); - - when(() => mockDio.post( - any(), - data: any(named: 'data'), - )).thenAnswer((_) async => Response( - data: jsonEncode(ChannelState(channel: channelModel)), - statusCode: 200, - requestOptions: FakeRequestOptions(), - )); - - await channelClient.watch(); - - final message = Message(text: 'test'); - - when( - () => mockDio.post( - '/channels/messaging/testid', - data: { - 'message': message.toJson(), - 'data': {'test': true}, - }, - ), - ).thenAnswer( - (_) async => Response( - data: jsonEncode({ - 'channel': channelModel, - 'message': message, - }), - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await channelClient.update({'test': true}, message); - - verify( - () => mockDio.post('/channels/messaging/testid', data: { - 'message': message.toJson(), - 'data': {'test': true}, - }), - ).called(1); - }); - - test('delete', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging', id: 'testid'); - - when( - () => mockDio.delete('/channels/messaging/testid'), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await channelClient.delete(); - - verify(() => mockDio.delete('/channels/messaging/testid')) - .called(1); - }); - - test('truncate', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging', id: 'testid'); - - when( - () => mockDio.post('/channels/messaging/testid/truncate'), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await channelClient.truncate(); - - verify(() => - mockDio.post('/channels/messaging/testid/truncate')) - .called(1); - }); - - test('rejectInvite', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging', id: 'testid'); - final channelModel = ChannelModel(cid: 'messaging:testid'); - - when(() => mockDio.post( - any(), - data: any(named: 'data'), - )).thenAnswer((_) async => Response( - data: jsonEncode(ChannelState(channel: channelModel)), - statusCode: 200, - requestOptions: FakeRequestOptions(), - )); - - await channelClient.watch(); - - final message = Message(text: 'test'); - - when( - () => mockDio.post( - '/channels/messaging/testid', - data: {'reject_invite': true, 'message': message.toJson()}, - ), - ).thenAnswer( - (_) async => Response( - data: jsonEncode({ - 'message': message, - 'channel': channelModel, - }), - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await channelClient.rejectInvite(message); - - verify(() => mockDio.post('/channels/messaging/testid', - data: {'reject_invite': true, 'message': message.toJson()})) - .called(1); - }); - - test('inviteMembers', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging', id: 'testid'); - final channelModel = ChannelModel(cid: 'messaging:testid'); - - when(() => mockDio.post( - any(), - data: any(named: 'data'), - )).thenAnswer((_) async => Response( - data: jsonEncode(ChannelState(channel: channelModel)), - statusCode: 200, - requestOptions: FakeRequestOptions(), - )); - - await channelClient.watch(); - - final members = [Member(userId: 'vishal')]; - final memberIds = members.map((e) => e.userId!).toList(); - final message = Message(text: 'test'); - - when( - () => mockDio.post( - '/channels/messaging/testid', - data: {'invites': memberIds, 'message': message.toJson()}, - ), - ).thenAnswer( - (_) async => Response( - data: jsonEncode({ - 'members': members, - 'message': message, - 'channel': channelModel, - }), - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await channelClient.inviteMembers(memberIds, message); - - verify(() => mockDio.post('/channels/messaging/testid', - data: {'invites': memberIds, 'message': message.toJson()})) - .called(1); - }); - - test('removeMembers', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging', id: 'testid'); - final channelModel = ChannelModel(cid: 'messaging:testid'); - - when(() => mockDio.post( - any(), - data: any(named: 'data'), - )).thenAnswer((_) async => Response( - data: jsonEncode(ChannelState(channel: channelModel)), - statusCode: 200, - requestOptions: FakeRequestOptions(), - )); - - await channelClient.watch(); - - final members = [Member(userId: 'vishal')]; - final memberIds = members.map((e) => e.userId!).toList(); - final message = Message(text: 'test'); - - when( - () => mockDio.post( - '/channels/messaging/testid', - data: {'remove_members': memberIds, 'message': message.toJson()}, - ), - ).thenAnswer( - (_) async => Response( - data: jsonEncode({ - 'members': members, - 'message': message, - 'channel': channelModel, - }), - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await channelClient.removeMembers(memberIds, message); - - verify(() => mockDio.post('/channels/messaging/testid', data: { - 'remove_members': memberIds, - 'message': message.toJson() - })).called(1); - }); - - test('hide', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging', id: 'testid'); - - when( - () => mockDio.post( - any(), - data: any(named: 'data'), - ), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - await channelClient.watch(); - - when( - () => mockDio.post( - '/channels/messaging/testid/hide', - data: {'clear_history': true}, - ), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await channelClient.hide(clearHistory: true); - - verify(() => mockDio.post('/channels/messaging/testid/hide', - data: {'clear_history': true})).called(1); - }); - - test('show', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging', id: 'testid'); - - when( - () => mockDio.post( - any(), - data: any(named: 'data'), - ), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - await channelClient.watch(); - - when( - () => mockDio.post('/channels/messaging/testid/show'), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await channelClient.show(); - - verify(() => mockDio.post('/channels/messaging/testid/show')) - .called(1); - }); - - test('banUser', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging', id: 'testid'); - - when( - () => mockDio.post( - any(), - data: any(named: 'data'), - ), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - await channelClient.watch(); - - when( - () => mockDio.post('/moderation/ban', data: { - 'test': true, - 'target_user_id': 'test-id', - 'type': 'messaging', - 'id': 'testid', - }), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - final options = {'test': true}; - await channelClient.banUser('test-id', options); - - verify(() => mockDio.post('/moderation/ban', data: { - 'test': true, - 'target_user_id': 'test-id', - 'type': 'messaging', - 'id': 'testid', - })).called(1); - }); - - test('unbanUser', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - tokenProvider: (_) async => '', - ); - final channelClient = client.channel('messaging', id: 'testid'); - - when( - () => mockDio.post( - any(), - data: any(named: 'data'), - ), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - await channelClient.watch(); - - when( - () => mockDio.delete( - '/moderation/ban', - queryParameters: { - 'target_user_id': 'test-id', - 'type': 'messaging', - 'id': 'testid', - }, - ), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await channelClient.unbanUser('test-id'); - - verify( - () => mockDio.delete('/moderation/ban', queryParameters: { - 'target_user_id': 'test-id', - 'type': 'messaging', - 'id': 'testid', - }), - ).called(1); - }); - }); - }); -} diff --git a/packages/stream_chat/test/src/api/web_socket_stub_test.dart b/packages/stream_chat/test/src/api/web_socket_stub_test.dart deleted file mode 100644 index 77a67421..00000000 --- a/packages/stream_chat/test/src/api/web_socket_stub_test.dart +++ /dev/null @@ -1,11 +0,0 @@ -import 'package:test/test.dart'; -import 'package:stream_chat/src/api/web_socket_channel_stub.dart'; - -void main() { - test('src/api/web_socket_stub_test', () { - expect( - () => openConnection('fakeurl'), - throwsA(isA()), - ); - }); -} diff --git a/packages/stream_chat/test/src/api/websocket_test.dart b/packages/stream_chat/test/src/api/websocket_test.dart deleted file mode 100644 index 11270a9e..00000000 --- a/packages/stream_chat/test/src/api/websocket_test.dart +++ /dev/null @@ -1,348 +0,0 @@ -import 'dart:async'; - -import 'package:logging/logging.dart'; -import 'package:mocktail/mocktail.dart'; -import 'package:stream_chat/src/ws/connection_status.dart'; -import 'package:stream_chat/src/ws/websocket.dart'; -import 'package:stream_chat/src/core/models/event.dart'; -import 'package:stream_chat/src/core/models/user.dart'; -import 'package:stream_chat/stream_chat.dart'; -import 'package:test/test.dart'; -import 'package:web_socket_channel/web_socket_channel.dart'; - -class Functions { - WebSocketChannel connectFunc( - String? url, { - Iterable? protocols, - }) => - WebSocketChannel.connect(Uri()); - - void handleFunc(Event event) {} -} - -class MockFunctions extends Mock implements Functions {} - -class MockWSChannel extends Mock implements WebSocketChannel {} - -class MockWSSink extends Mock implements WebSocketSink {} - -class FakeEvent extends Fake implements Event {} - -void main() { - group('src/api/websocket', () { - setUpAll(() { - registerFallbackValue(FakeEvent()); - }); - - test('should connect with correct parameters', () async { - final connectFunc = MockFunctions().connectFunc; - final ws = WebSocket( - baseUrl: 'baseurl', - user: User(id: 'testid'), - _logger: Logger('ws'), - connectParams: {'test': 'true'}, - connectPayload: {'payload': 'test'}, - handler: print, - connectFunc: connectFunc, - ); - final mockWSChannel = MockWSChannel(); - final streamController = StreamController.broadcast(); - const computedUrl = - 'wss://baseurl/connect?test=true&json=%7B%22payload%22%3A%22test%22%2C%22user_details%22%3A%7B%22id%22%3A%22testid%22%7D%7D'; - - when(() => connectFunc(computedUrl)).thenAnswer((_) => mockWSChannel); - when(() => mockWSChannel.sink).thenAnswer((_) => MockWSSink()); - when(() => mockWSChannel.stream).thenAnswer( - (_) => streamController.stream, - ); - - final timer = Timer.periodic( - const Duration(milliseconds: 100), - (_) => streamController.sink.add('{}'), - ); - - await ws.connect(); - - verify(() => connectFunc(computedUrl)).called(1); - expect(ws.connectionStatus, ConnectionStatus.connected); - - await streamController.close(); - timer.cancel(); - }); - }); - - test('should connect with correct parameters and handle events', () async { - final handleFunc = MockFunctions().handleFunc; - final connectFunc = MockFunctions().connectFunc; - final ws = WebSocket( - baseUrl: 'baseurl', - user: User(id: 'testid'), - _logger: Logger('ws'), - connectParams: {'test': 'true'}, - connectPayload: {'payload': 'test'}, - handler: handleFunc, - connectFunc: connectFunc, - ); - final mockWSChannel = MockWSChannel(); - final streamController = StreamController.broadcast(); - const computedUrl = - 'wss://baseurl/connect?test=true&json=%7B%22payload%22%3A%22test%22%2C%22user_details%22%3A%7B%22id%22%3A%22testid%22%7D%7D'; - - when(() => connectFunc(computedUrl)).thenAnswer((_) => mockWSChannel); - when(() => mockWSChannel.sink).thenAnswer((_) => MockWSSink()); - when(() => mockWSChannel.stream).thenAnswer((_) => streamController.stream); - - final connect = ws.connect().then((_) { - streamController.sink.add('{}'); - return Future.delayed(const Duration(milliseconds: 200)); - }).then((value) { - verify(() => connectFunc(computedUrl)).called(1); - verify(() => handleFunc(any())).called(greaterThan(0)); - - return streamController.close(); - }); - - streamController.sink.add('{}'); - - return connect; - }); - - test('should close correctly the controller', () async { - final handleFunc = MockFunctions().handleFunc; - final connectFunc = MockFunctions().connectFunc; - final ws = WebSocket( - baseUrl: 'baseurl', - user: User(id: 'testid'), - _logger: Logger('ws'), - connectParams: {'test': 'true'}, - connectPayload: {'payload': 'test'}, - handler: handleFunc, - connectFunc: connectFunc, - ); - final mockWSChannel = MockWSChannel(); - final streamController = StreamController.broadcast(); - const computedUrl = - 'wss://baseurl/connect?test=true&json=%7B%22payload%22%3A%22test%22%2C%22user_details%22%3A%7B%22id%22%3A%22testid%22%7D%7D'; - - final mockWSSink = MockWSSink(); - when(() => mockWSChannel.sink).thenAnswer((_) => mockWSSink); - when(() => mockWSSink.close(any(), any())).thenAnswer((_) async => null); - when(() => connectFunc(computedUrl)).thenAnswer((_) => mockWSChannel); - when(() => mockWSChannel.stream).thenAnswer((_) => streamController.stream); - - final connect = ws.connect().then((_) { - streamController.sink.add('{}'); - return Future.delayed(const Duration(milliseconds: 200)); - }).then((value) { - verify(() => connectFunc(computedUrl)).called(1); - verify(() => handleFunc(any())).called(greaterThan(0)); - - return streamController.close(); - }); - - streamController.sink.add('{}'); - - return connect; - }); - - test('should close correctly the controller while connecting', () async { - final handleFunc = MockFunctions().handleFunc; - - final connectFunc = MockFunctions().connectFunc; - - final ws = WebSocket( - baseUrl: 'baseurl', - user: User(id: 'testid'), - _logger: Logger('ws'), - connectParams: {'test': 'true'}, - connectPayload: {'payload': 'test'}, - handler: handleFunc, - connectFunc: connectFunc, - ); - - final mockWSChannel = MockWSChannel(); - - final streamController = StreamController.broadcast(); - - const computedUrl = - 'wss://baseurl/connect?test=true&json=%7B%22payload%22%3A%22test%22%2C%22user_details%22%3A%7B%22id%22%3A%22testid%22%7D%7D'; - - final mockWSSink = MockWSSink(); - when(() => mockWSChannel.sink).thenAnswer((_) => mockWSSink); - when(() => mockWSSink.close(any(), any())).thenAnswer((_) async => null); - when(() => connectFunc(computedUrl)).thenAnswer((_) => mockWSChannel); - when(() => mockWSChannel.stream).thenAnswer((_) => streamController.stream); - - ws.connect(); - await ws.disconnect(); - streamController.add('{}'); - - verify(() => connectFunc(computedUrl)).called(1); - verifyNever(() => handleFunc(any())); - - addTearDown(streamController.close); - }); - - test('should run correctly health check', () async { - final handleFunc = MockFunctions().handleFunc; - final connectFunc = MockFunctions().connectFunc; - final ws = WebSocket( - baseUrl: 'baseurl', - user: User(id: 'testid'), - _logger: Logger('ws'), - connectParams: {'test': 'true'}, - connectPayload: {'payload': 'test'}, - handler: handleFunc, - connectFunc: connectFunc, - ); - final mockWSChannel = MockWSChannel(); - final mockWSSink = MockWSSink(); - final streamController = StreamController.broadcast(); - const computedUrl = - 'wss://baseurl/connect?test=true&json=%7B%22payload%22%3A%22test%22%2C%22user_details%22%3A%7B%22id%22%3A%22testid%22%7D%7D'; - - when(() => connectFunc(computedUrl)).thenAnswer((_) => mockWSChannel); - when(() => mockWSChannel.stream).thenAnswer((_) => streamController.stream); - when(() => mockWSChannel.sink).thenAnswer((_) => mockWSSink); - when(() => mockWSSink.close(any(), any())).thenAnswer((_) async => null); - - final timer = Timer.periodic( - const Duration(milliseconds: 1000), - (_) => streamController.sink.add('{}'), - ); - - final connect = ws.connect().then((_) { - streamController.sink.add('{}'); - return Future.delayed(const Duration(milliseconds: 200)); - }).then((value) async { - verify(() => mockWSSink.add("{'type': 'health.check'}")) - .called(greaterThan(0)); - - timer.cancel(); - await streamController.close(); - return mockWSSink.close(); - }); - - streamController.sink.add('{}'); - - return connect; - }); - - test('should run correctly reconnection check', () async { - final handleFunc = MockFunctions().handleFunc; - final connectFunc = MockFunctions().connectFunc; - Logger.root.level = Level.ALL; - final ws = WebSocket( - baseUrl: 'baseurl', - user: User(id: 'testid'), - _logger: Logger('ws'), - connectParams: {'test': 'true'}, - connectPayload: {'payload': 'test'}, - handler: handleFunc, - connectFunc: connectFunc, - reconnectionMonitorTimeout: 1, - ); - final mockWSChannel = MockWSChannel(); - final mockWSSink = MockWSSink(); - var streamController = StreamController.broadcast(); - const computedUrl = - 'wss://baseurl/connect?test=true&json=%7B%22payload%22%3A%22test%22%2C%22user_details%22%3A%7B%22id%22%3A%22testid%22%7D%7D'; - - when(() => connectFunc(computedUrl)).thenAnswer((_) => mockWSChannel); - when(() => mockWSChannel.stream).thenAnswer((_) => streamController.stream); - when(() => mockWSChannel.sink).thenAnswer((_) => mockWSSink); - when(() => mockWSSink.close(any(), any())).thenAnswer((_) async => null); - - final connect = ws.connect().then((_) { - streamController.sink.add('{}'); - streamController.close(); - streamController = StreamController.broadcast(); - streamController.sink.add('{}'); - return Future.delayed(const Duration(milliseconds: 200)); - }).then((value) async { - verify(() => mockWSSink.add("{'type': 'health.check'}")) - .called(greaterThan(0)); - - verify(() => connectFunc(computedUrl)).called(2); - - await streamController.close(); - return mockWSSink.close(); - }); - - streamController.sink.add('{}'); - - return connect; - }); - - test('should close correctly the controller', () async { - final handleFunc = MockFunctions().handleFunc; - final connectFunc = MockFunctions().connectFunc; - final ws = WebSocket( - baseUrl: 'baseurl', - user: User(id: 'testid'), - _logger: Logger('ws'), - connectParams: {'test': 'true'}, - connectPayload: {'payload': 'test'}, - handler: handleFunc, - connectFunc: connectFunc, - ); - final mockWSChannel = MockWSChannel(); - final mockWSSink = MockWSSink(); - final streamController = StreamController.broadcast(); - const computedUrl = - 'wss://baseurl/connect?test=true&json=%7B%22payload%22%3A%22test%22%2C%22user_details%22%3A%7B%22id%22%3A%22testid%22%7D%7D'; - - when(() => connectFunc(computedUrl)).thenAnswer((_) => mockWSChannel); - when(() => mockWSChannel.stream).thenAnswer((_) => streamController.stream); - when(() => mockWSChannel.sink).thenAnswer((_) => mockWSSink); - when(() => mockWSSink.close(any(), any())).thenAnswer((_) async => null); - - final connect = ws.connect().then((_) { - streamController.sink.add('{}'); - return Future.delayed(const Duration(milliseconds: 200)); - }).then((value) async { - await ws.disconnect(); - verify(mockWSSink.close).called(greaterThan(0)); - - await streamController.close(); - await mockWSSink.close(); - }); - - streamController.sink.add('{}'); - - return connect; - }); - - test('should throw an error', () async { - final connectFunc = MockFunctions().connectFunc; - final ws = WebSocket( - baseUrl: 'baseurl', - user: User(id: 'testid'), - _logger: Logger('ws'), - connectParams: {'test': 'true'}, - connectPayload: {'payload': 'test'}, - handler: print, - connectFunc: connectFunc, - ); - final mockWSChannel = MockWSChannel(); - final streamController = StreamController.broadcast(); - const computedUrl = - 'wss://baseurl/connect?test=true&json=%7B%22payload%22%3A%22test%22%2C%22user_details%22%3A%7B%22id%22%3A%22testid%22%7D%7D'; - - when(() => connectFunc(computedUrl)).thenAnswer((_) => mockWSChannel); - when(() => mockWSChannel.sink).thenAnswer((_) => MockWSSink()); - when(() => mockWSChannel.stream).thenAnswer((_) => streamController.stream); - - Future.delayed( - const Duration(milliseconds: 1000), - () => streamController.sink.addError('test error'), - ); - - try { - expect(await ws.connect(), throwsA(isA())); - } catch (e) { - verify(() => connectFunc(computedUrl)).called(greaterThanOrEqualTo(1)); - streamController.close(); - } - }); -} diff --git a/packages/stream_chat/test/src/client_test.dart b/packages/stream_chat/test/src/client_test.dart deleted file mode 100644 index 13506f66..00000000 --- a/packages/stream_chat/test/src/client_test.dart +++ /dev/null @@ -1,1205 +0,0 @@ -import 'dart:async'; -import 'dart:convert'; -import 'dart:typed_data'; - -import 'package:dio/dio.dart'; -import 'package:dio/native_imp.dart'; -import 'package:logging/logging.dart'; -import 'package:mocktail/mocktail.dart'; -import 'package:stream_chat/src/core/api/requests.dart'; -import 'package:stream_chat/src/client.dart'; -import 'package:stream_chat/src/core/models/channel_model.dart'; -import 'package:stream_chat/src/core/models/filter.dart'; -import 'package:stream_chat/src/core/models/message.dart'; -import 'package:stream_chat/src/core/models/user.dart'; -import 'package:test/test.dart'; - -class MockDio extends Mock implements DioForNative {} - -class FakeRequestOptions extends Fake implements RequestOptions {} - -class MockHttpClientAdapter extends Mock implements HttpClientAdapter {} - -class Functions { - Future tokenProvider(String userId) async => ''; -} - -class MockFunctions extends Mock implements Functions {} - -void main() { - group('src/client', () { - setUpAll(() { - registerFallbackValue(FakeRequestOptions()); - registerFallbackValue>(const Stream.empty()); - registerFallbackValue>(Future.value()); - }); - - group('constructor', () { - final log = []; - - dynamic overridePrint(testFn()) => () { - log.clear(); - final spec = ZoneSpecification(print: (_, __, ___, String msg) { - // Add to log instead of printing to stdout - log.add(msg); - }); - return Zone.current.fork(specification: spec).run(testFn); - }; - - tearDown(log.clear); - - test('should create the object correctly', () { - final client = StreamChatClient('api-key'); - - expect(client.baseURL, 'chat-us-east-1.stream-io-api.com'); - expect(client.apiKey, 'api-key'); - expect(client.logLevel, Level.WARNING); - expect(client.httpClient._options.connectTimeout, 6000); - expect(client.httpClient._options.receiveTimeout, 6000); - }); - - test('should create the object correctly', overridePrint(() { - void logHandler(LogRecord record) { - print(record.message); - } - - final client = StreamChatClient( - 'api-key', - connectTimeout: const Duration(seconds: 10), - receiveTimeout: const Duration(seconds: 12), - logLevel: Level.INFO, - baseURL: 'test.com', - logHandlerFunction: logHandler, - ); - - expect(client.baseURL, 'test.com'); - expect(client.apiKey, 'api-key'); - expect(Logger.root.level, Level.INFO); - expect(client.httpClient._options.connectTimeout, 10000); - expect(client.httpClient._options.receiveTimeout, 12000); - - client.logger.warning('test'); - client.logger.config('test config'); - - expect( - [log[log.length - 2], log[log.length - 1]], - ['instantiating new client', 'test'], - ); - })); - - test('Channel', () { - final client = StreamChatClient('test'); - final data = {'test': 1}; - final channelClient = client.channel('type', id: 'id', extraData: data); - expect(channelClient.type, 'type'); - expect(channelClient.id, 'id'); - }); - }); - - group('queryChannelsOnline', () { - test('should pass right default parameters', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - final queryParams = { - 'payload': json.encode({ - 'filter_conditions': null, - 'sort': null, - 'state': true, - 'watch': true, - 'presence': false, - 'limit': 10, - 'offset': 0, - }), - }; - - when( - () => mockDio.get('/channels', queryParameters: queryParams), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.queryChannelsOnline(waitForConnect: false); - - verify(() => - mockDio.get('/channels', queryParameters: queryParams)) - .called(1); - }); - - test('should pass right parameters', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - final queryFilter = Filter.in_('id', const ['test']); - final sortOptions = >[]; - final options = {'state': false, 'watch': false, 'presence': true}; - const paginationParams = PaginationParams(offset: 2); - - final queryParams = { - 'payload': json.encode({ - 'filter_conditions': queryFilter, - 'sort': sortOptions, - } - ..addAll(options) - ..addAll(paginationParams - .toJson() - .map((key, value) => MapEntry(key, value as Object)))), - }; - - when( - () => mockDio.get('/channels', queryParameters: queryParams), - ).thenAnswer( - (_) async => Response( - data: '{"channels":[]}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.queryChannelsOnline( - filter: queryFilter, - sort: sortOptions, - _options: options, - paginationParams: paginationParams, - waitForConnect: false, - ); - - verify(() => - mockDio.get('/channels', queryParameters: queryParams)) - .called(1); - }); - }); - - group('search', () { - test('should pass right default parameters', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - final filter = Filter.in_('cid', const ['messaging:testId']); - const query = 'hello'; - final queryParams = { - 'payload': json.encode({ - 'filter_conditions': filter, - 'query': query, - }), - }; - - when( - () => mockDio.get('/search', queryParameters: queryParams), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.search(filter, query: query); - - verify(() => - mockDio.get('/search', queryParameters: queryParams)) - .called(1); - }); - - test('should pass right parameters', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - final filters = Filter.in_('id', const ['test']); - const sortOptions = [SortOption('name')]; - const query = 'query'; - final queryParams = { - 'payload': json.encode({ - 'filter_conditions': filters, - 'query': query, - 'sort': sortOptions, - 'limit': 10, - 'offset': 0, - }), - }; - - when( - () => mockDio.get('/search', queryParameters: queryParams), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.search( - filters, - sort: sortOptions, - query: query, - paginationParams: const PaginationParams(), - ); - - verify( - () => mockDio.get('/search', queryParameters: queryParams), - ).called(1); - }); - }); - - group('devices', () { - test('addDevice', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - - when( - () => mockDio.post('/devices', data: { - 'id': 'test-id', - 'push_provider': 'firebase', - }), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.addDevice('test-id', PushProvider.firebase); - - verify( - () => mockDio.post( - '/devices', - data: {'id': 'test-id', 'push_provider': 'firebase'}, - ), - ).called(1); - }); - - test('getDevices', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - - when(() => mockDio.get('/devices')).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.getDevices(); - - verify(() => mockDio.get('/devices')).called(1); - }); - - test('removeDevice', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - - when( - () => mockDio.delete( - '/devices', - queryParameters: {'id': 'test-id'}, - ), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.removeDevice('test-id'); - - verify( - () => mockDio.delete( - '/devices', - queryParameters: {'id': 'test-id'}, - ), - ).called(1); - }); - }); - - test('devToken', () { - final client = StreamChatClient('api-key'); - final token = client.devToken('test'); - - expect( - token, - '''eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoidGVzdCJ9.devtoken''', - ); - }); - - group('queryUsers', () { - test('should pass right default parameters', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - final queryParams = { - 'payload': json.encode({ - 'filter_conditions': null, - 'sort': null, - 'presence': false, - }), - }; - - when( - () => mockDio.get('/users', queryParameters: queryParams), - ).thenAnswer( - (_) async => Response( - data: '{"users":[]}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.queryUsers(); - - verify( - () => mockDio.get( - '/users', - queryParameters: queryParams, - ), - ).called(1); - }); - - test('should pass right parameters', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - final queryFilter = Filter.in_('id', const ['test']); - const sortOptions = []; - final options = {'presence': true}; - final queryParams = { - 'payload': json.encode({ - 'filter_conditions': queryFilter, - 'sort': sortOptions, - }..addAll(options)), - }; - - when( - () => mockDio.get('/users', queryParameters: queryParams), - ).thenAnswer( - (_) async => Response( - data: '{"users":[]}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.queryUsers( - filter: queryFilter, - sort: sortOptions, - _options: options, - ); - - verify(() => - mockDio.get('/users', queryParameters: queryParams)) - .called(1); - }); - }); - - group('user', () { - test('connectUser should throw exception', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - - when( - () => mockDio.post( - '/moderation/flag', - data: {'target_user_id': 'test-id'}, - ), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.flagUser('test-id'); - - verify(() => mockDio.post('/moderation/flag', - data: {'target_user_id': 'test-id'})).called(1); - }); - - test('flagUser', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - - expect(() => client.connectUserWithProvider(User(id: 'test-id')), - throwsA(isA())); - }); - - test('unflagUser', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - - when( - () => mockDio.post( - '/moderation/unflag', - data: {'target_user_id': 'test-id'}, - ), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.unflagUser('test-id'); - - verify(() => mockDio.post('/moderation/unflag', - data: {'target_user_id': 'test-id'})).called(1); - }); - - test('updateUser', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - final user = User(id: 'test-id'); - final data = { - 'users': {user.id: user.toJson()}, - }; - - when(() => mockDio.post('/users', data: data)).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.updateUser(user); - - verify(() => mockDio.post('/users', data: data)).called(1); - }); - - test('updateUsers', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - final user = User(id: 'test-id'); - final user2 = User(id: 'test-id2'); - - final data = { - 'users': { - user.id: user.toJson(), - user2.id: user2.toJson(), - }, - }; - - when(() => mockDio.post('/users', data: data)).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.updateUsers([user, user2]); - - verify(() => mockDio.post('/users', data: data)).called(1); - }); - - test('banUser', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - - when( - () => mockDio.post( - '/moderation/ban', - data: {'test': true, 'target_user_id': 'test-id'}, - ), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.banUser('test-id', {'test': true}); - - verify(() => mockDio.post('/moderation/ban', - data: {'test': true, 'target_user_id': 'test-id'})).called(1); - }); - - test('unbanUser', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - - when( - () => mockDio.delete( - '/moderation/ban', - queryParameters: {'test': true, 'target_user_id': 'test-id'}, - ), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.unbanUser('test-id', {'test': true}); - - verify(() => mockDio.delete('/moderation/ban', - queryParameters: {'test': true, 'target_user_id': 'test-id'})) - .called(1); - }); - - test('muteUser', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - - when( - () => mockDio.post( - '/moderation/mute', - data: {'target_id': 'test-id'}, - ), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.muteUser('test-id'); - - verify(() => mockDio.post('/moderation/mute', - data: {'target_id': 'test-id'})).called(1); - }); - - test('unmuteUser', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - - when( - () => mockDio.post( - '/moderation/unmute', - data: {'target_id': 'test-id'}, - ), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.unmuteUser('test-id'); - - verify(() => mockDio.post('/moderation/unmute', - data: {'target_id': 'test-id'})).called(1); - }); - }); - - group('message', () { - test('flagMessage', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - - when( - () => mockDio.post( - '/moderation/flag', - data: {'target_message_id': 'test-id'}, - ), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.flagMessage('test-id'); - - verify(() => mockDio.post('/moderation/flag', - data: {'target_message_id': 'test-id'})).called(1); - }); - - test('unflagMessage', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - - when( - () => mockDio.post( - '/moderation/unflag', - data: {'target_message_id': 'test-id'}, - ), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.unflagMessage('test-id'); - - verify(() => mockDio.post('/moderation/unflag', - data: {'target_message_id': 'test-id'})).called(1); - }); - - test('updateMessage', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - final message = Message( - id: 'test', - ); - - when( - () => mockDio.post( - '/messages/${message.id}', - data: {'message': anything}, - ), - ).thenAnswer( - (_) async => Response( - data: jsonEncode({'message': message}), - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.updateMessage(message); - - verify(() => mockDio.post('/messages/${message.id}', - data: {'message': anything})).called(1); - }); - - test('deleteMessage', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - const messageId = 'test'; - - when(() => mockDio.delete('/messages/$messageId')).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.deleteMessage(Message(id: messageId)); - - verify(() => mockDio.delete('/messages/$messageId')).called(1); - }); - - test('getMessage', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - const messageId = 'test'; - - when(() => mockDio.get('/messages/$messageId')).thenAnswer( - (_) async => Response( - data: jsonEncode({'message': Message(id: messageId)}), - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.getMessage(messageId); - - verify(() => mockDio.get('/messages/$messageId')).called(1); - }); - - test('markAllRead', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - - when(() => mockDio.post('/channels/read')).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.markAllRead(); - - verify(() => mockDio.post('/channels/read')).called(1); - }); - }); - - group('api methods', () { - group('get', () { - test('should put the correct parameters', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - final queryParams = {'test': 1}; - - when( - () => mockDio.get('/test', queryParameters: queryParams), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.get('/test', queryParameters: queryParams); - - verify(() => - mockDio.get('/test', queryParameters: queryParams)) - .called(1); - }); - - test('should catch the error', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - - when(() => mockDio.get(any())).thenThrow( - DioError( - type: DioErrorType.response, - response: Response( - data: 'test error', - statusCode: 400, - requestOptions: FakeRequestOptions(), - ), - requestOptions: FakeRequestOptions(), - ), - ); - - expect( - client.get('/test'), - throwsA(ApiError('test error', 400)), - ); - }); - }); - - group('post', () { - test('should put the correct parameters', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - final data = {'test': 1}; - - when(() => mockDio.post('/test', data: data)).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.post('/test', data: data); - - verify(() => mockDio.post('/test', data: data)).called(1); - }); - - test('should catch the error', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - ); - - when(() => mockDio.post(any())).thenThrow( - DioError( - type: DioErrorType.response, - response: Response( - data: 'test error', - statusCode: 400, - requestOptions: FakeRequestOptions(), - ), - requestOptions: FakeRequestOptions(), - ), - ); - - expect(client.post('/test'), throwsA(ApiError('test error', 400))); - }); - }); - - group('put', () { - test('should put the correct parameters', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - final data = {'test': 1}; - - when(() => mockDio.put('/test', data: data)).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.put('/test', data: data); - - verify(() => mockDio.put('/test', data: data)).called(1); - }); - - test('should catch the error', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - - when(() => mockDio.put(any())).thenThrow( - DioError( - type: DioErrorType.response, - response: Response( - data: 'test error', - statusCode: 400, - requestOptions: FakeRequestOptions(), - ), - requestOptions: FakeRequestOptions(), - ), - ); - - expect(client.put('/test'), throwsA(ApiError('test error', 400))); - }); - }); - - group('patch', () { - test('should put the correct parameters', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - - final data = { - 'test': 1, - }; - - when(() => mockDio.patch('/test', data: data)).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.patch('/test', data: data); - - verify(() => mockDio.patch('/test', data: data)).called(1); - }); - - test('should catch the error', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - - when(() => mockDio.patch(any())).thenThrow( - DioError( - type: DioErrorType.response, - response: Response( - data: 'test error', - statusCode: 400, - requestOptions: FakeRequestOptions(), - ), - requestOptions: FakeRequestOptions(), - ), - ); - - expect(client.patch('/test'), throwsA(ApiError('test error', 400))); - }); - }); - - group('delete', () { - test('should put the correct parameters', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - ); - - final queryParams = { - 'test': 1, - }; - - when( - () => mockDio.delete('/test', queryParameters: queryParams), - ).thenAnswer( - (_) async => Response( - data: '{}', - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.delete('/test', queryParameters: queryParams); - - verify(() => - mockDio.delete('/test', queryParameters: queryParams)) - .called(1); - }); - - test('should catch the error', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient('api-key', httpClient: mockDio); - - when(() => mockDio.delete(any())).thenThrow( - DioError( - type: DioErrorType.response, - response: Response( - data: 'test error', - statusCode: 400, - requestOptions: FakeRequestOptions(), - ), - requestOptions: FakeRequestOptions(), - ), - ); - - expect(client.delete('/test'), throwsA(ApiError('test error', 400))); - }); - }); - - group('pin message', () { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - ); - - test('should throw argument error', () { - final message = Message(text: 'Hello'); - expect( - () => client.pinMessage(message, 'InvalidType'), - throwsArgumentError, - ); - }); - - test('should complete successfully', () async { - const timeout = 30; - final message = Message(text: 'Hello'); - - when( - () => mockDio.post( - '/messages/${message.id}', - data: anything, - ), - ).thenAnswer( - (_) async => Response( - data: jsonEncode({'message': message}), - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.pinMessage(message, timeout); - - verify(() => mockDio.post('/messages/${message.id}', - data: {'message': anything})).called(1); - }); - - test('should complete successfully with a null value', () async { - final message = Message(text: 'Hello'); - - when( - () => mockDio.post( - '/messages/${message.id}', - data: anything, - ), - ).thenAnswer( - (_) async => Response( - data: jsonEncode({'message': message}), - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.pinMessage(message); - - verify(() => mockDio.post('/messages/${message.id}', - data: {'message': anything})).called(1); - }); - - test('should unpin message successfully', () async { - final message = Message(text: 'Hello'); - - when( - () => mockDio.post( - '/messages/${message.id}', - data: anything, - ), - ).thenAnswer( - (_) async => Response( - data: jsonEncode({'message': message}), - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await client.unpinMessage(message); - - verify(() => mockDio.post('/messages/${message.id}', - data: anything)).called(1); - }); - }); - }); - - group('channel', () { - test('should update channel', () async { - final mockDio = MockDio(); - - when(() => mockDio.options).thenReturn(BaseOptions()); - when(() => mockDio.interceptors).thenReturn(Interceptors()); - - final client = StreamChatClient( - 'api-key', - httpClient: mockDio, - ); - - final channelClient = client.channel( - 'type', - id: 'id', - extraData: {'name': 'init'}, - ); - - const update = { - 'set': {'name': 'demo'} - }; - - when( - () => mockDio.patch( - '/channels/${channelClient.type}/${channelClient.id}', - data: update, - ), - ).thenAnswer( - (_) async => Response( - data: jsonEncode({'channel': ChannelModel(cid: 'messaging:test')}), - statusCode: 200, - requestOptions: FakeRequestOptions(), - ), - ); - - await channelClient.updatePartial(update); - verify( - () => mockDio.patch( - '/channels/${channelClient.type}/${channelClient.id}', - data: update, - ), - ).called(1); - }); - }); - }); -} diff --git a/packages/stream_chat/test/src/models/action_test.dart b/packages/stream_chat/test/src/models/action_test.dart index 22e66078..d0108948 100644 --- a/packages/stream_chat/test/src/models/action_test.dart +++ b/packages/stream_chat/test/src/models/action_test.dart @@ -1,7 +1,7 @@ import 'dart:convert'; import 'package:test/test.dart'; -import 'package:stream_chat/src/models/action.dart'; +import 'package:stream_chat/src/core/models/action.dart'; void main() { group('src/models/action', () { diff --git a/packages/stream_chat/test/src/models/attachment_test.dart b/packages/stream_chat/test/src/models/attachment_test.dart index 1342e72e..a433bedd 100644 --- a/packages/stream_chat/test/src/models/attachment_test.dart +++ b/packages/stream_chat/test/src/models/attachment_test.dart @@ -1,7 +1,7 @@ import 'dart:convert'; -import 'package:stream_chat/src/models/action.dart'; -import 'package:stream_chat/src/models/attachment.dart'; +import 'package:stream_chat/src/core/models/action.dart'; +import 'package:stream_chat/src/core/models/attachment.dart'; import 'package:test/test.dart'; void main() { diff --git a/packages/stream_chat/test/src/models/channel_state_test.dart b/packages/stream_chat/test/src/models/channel_state_test.dart index a93166b4..8f8bdf45 100644 --- a/packages/stream_chat/test/src/models/channel_state_test.dart +++ b/packages/stream_chat/test/src/models/channel_state_test.dart @@ -1,10 +1,10 @@ import 'dart:convert'; -import 'package:stream_chat/src/models/channel_config.dart'; -import 'package:stream_chat/src/models/channel_state.dart'; -import 'package:stream_chat/src/models/command.dart'; -import 'package:stream_chat/src/models/message.dart'; -import 'package:stream_chat/src/models/user.dart'; +import 'package:stream_chat/src/core/models/channel_config.dart'; +import 'package:stream_chat/src/core/models/channel_state.dart'; +import 'package:stream_chat/src/core/models/command.dart'; +import 'package:stream_chat/src/core/models/message.dart'; +import 'package:stream_chat/src/core/models/user.dart'; import 'package:stream_chat/stream_chat.dart'; import 'package:test/test.dart'; diff --git a/packages/stream_chat/test/src/models/channel_test.dart b/packages/stream_chat/test/src/models/channel_test.dart index 1e69565c..1bb400a6 100644 --- a/packages/stream_chat/test/src/models/channel_test.dart +++ b/packages/stream_chat/test/src/models/channel_test.dart @@ -1,6 +1,6 @@ import 'dart:convert'; -import 'package:stream_chat/src/models/channel_model.dart'; +import 'package:stream_chat/src/core/models/channel_model.dart'; import 'package:test/test.dart'; void main() { diff --git a/packages/stream_chat/test/src/models/command_test.dart b/packages/stream_chat/test/src/models/command_test.dart index 8fafd192..3306fd0f 100644 --- a/packages/stream_chat/test/src/models/command_test.dart +++ b/packages/stream_chat/test/src/models/command_test.dart @@ -1,6 +1,6 @@ import 'dart:convert'; -import 'package:stream_chat/src/models/command.dart'; +import 'package:stream_chat/src/core/models/command.dart'; import 'package:test/test.dart'; void main() { diff --git a/packages/stream_chat/test/src/models/device_test.dart b/packages/stream_chat/test/src/models/device_test.dart index 5cbf015d..f4700b7e 100644 --- a/packages/stream_chat/test/src/models/device_test.dart +++ b/packages/stream_chat/test/src/models/device_test.dart @@ -1,7 +1,7 @@ import 'dart:convert'; import 'package:test/test.dart'; -import 'package:stream_chat/src/models/device.dart'; +import 'package:stream_chat/src/core/models/device.dart'; void main() { group('src/models/device', () { diff --git a/packages/stream_chat/test/src/models/event_test.dart b/packages/stream_chat/test/src/models/event_test.dart index 96efa844..b05da962 100644 --- a/packages/stream_chat/test/src/models/event_test.dart +++ b/packages/stream_chat/test/src/models/event_test.dart @@ -1,7 +1,7 @@ import 'dart:convert'; -import 'package:stream_chat/src/models/event.dart'; -import 'package:stream_chat/src/models/own_user.dart'; +import 'package:stream_chat/src/core/models/event.dart'; +import 'package:stream_chat/src/core/models/own_user.dart'; import 'package:stream_chat/stream_chat.dart'; import 'package:test/test.dart'; diff --git a/packages/stream_chat/test/src/models/member_test.dart b/packages/stream_chat/test/src/models/member_test.dart index 25e1d78e..54c258e1 100644 --- a/packages/stream_chat/test/src/models/member_test.dart +++ b/packages/stream_chat/test/src/models/member_test.dart @@ -1,8 +1,8 @@ import 'dart:convert'; import 'package:test/test.dart'; -import 'package:stream_chat/src/models/member.dart'; -import 'package:stream_chat/src/models/user.dart'; +import 'package:stream_chat/src/core/models/member.dart'; +import 'package:stream_chat/src/core/models/user.dart'; void main() { group('src/models/member', () { diff --git a/packages/stream_chat/test/src/models/message_test.dart b/packages/stream_chat/test/src/models/message_test.dart index 1219e137..b3f28ff0 100644 --- a/packages/stream_chat/test/src/models/message_test.dart +++ b/packages/stream_chat/test/src/models/message_test.dart @@ -1,9 +1,9 @@ import 'dart:convert'; -import 'package:stream_chat/src/models/attachment.dart'; -import 'package:stream_chat/src/models/message.dart'; -import 'package:stream_chat/src/models/reaction.dart'; -import 'package:stream_chat/src/models/user.dart'; +import 'package:stream_chat/src/core/models/attachment.dart'; +import 'package:stream_chat/src/core/models/message.dart'; +import 'package:stream_chat/src/core/models/reaction.dart'; +import 'package:stream_chat/src/core/models/user.dart'; import 'package:test/test.dart'; void main() { diff --git a/packages/stream_chat/test/src/models/reaction_test.dart b/packages/stream_chat/test/src/models/reaction_test.dart index 795e2967..b69bd986 100644 --- a/packages/stream_chat/test/src/models/reaction_test.dart +++ b/packages/stream_chat/test/src/models/reaction_test.dart @@ -1,7 +1,7 @@ import 'dart:convert'; -import 'package:stream_chat/src/models/reaction.dart'; -import 'package:stream_chat/src/models/user.dart'; +import 'package:stream_chat/src/core/models/reaction.dart'; +import 'package:stream_chat/src/core/models/user.dart'; import 'package:test/test.dart'; void main() { diff --git a/packages/stream_chat/test/src/models/read_test.dart b/packages/stream_chat/test/src/models/read_test.dart index 66efe809..47c252ac 100644 --- a/packages/stream_chat/test/src/models/read_test.dart +++ b/packages/stream_chat/test/src/models/read_test.dart @@ -1,8 +1,8 @@ import 'dart:convert'; import 'package:test/test.dart'; -import 'package:stream_chat/src/models/read.dart'; -import 'package:stream_chat/src/models/user.dart'; +import 'package:stream_chat/src/core/models/read.dart'; +import 'package:stream_chat/src/core/models/user.dart'; void main() { group('src/models/read', () { diff --git a/packages/stream_chat/test/src/models/serialization_test.dart b/packages/stream_chat/test/src/models/serialization_test.dart index 9e64caad..605b5b58 100644 --- a/packages/stream_chat/test/src/models/serialization_test.dart +++ b/packages/stream_chat/test/src/models/serialization_test.dart @@ -1,5 +1,5 @@ import 'package:test/test.dart'; -import 'package:stream_chat/src/models/serialization.dart'; +import 'package:stream_chat/src/core/util/serializer.dart'; void main() { group('src/models/serialization', () { @@ -9,7 +9,7 @@ void main() { 'prop2': 123, 'prop3': true, }; - final result = Serialization.moveToExtraDataFromRoot(json, [ + final result = Serializer.moveToExtraDataFromRoot(json, [ 'prop1', 'prop2', ]); @@ -30,7 +30,7 @@ void main() { }); test('should have empty extraData', () { - final result = Serialization.moveToExtraDataFromRoot({ + final result = Serializer.moveToExtraDataFromRoot({ 'prop1': 'test', 'prop2': 123, 'prop3': true, @@ -49,7 +49,7 @@ void main() { }); test('should return null', () { - final result = Serialization.moveToExtraDataFromRoot({}, [ + final result = Serializer.moveToExtraDataFromRoot({}, [ 'prop1', 'prop2', ]); diff --git a/packages/stream_chat/test/src/models/user_test.dart b/packages/stream_chat/test/src/models/user_test.dart index 8f56f7e1..f4ff5ee0 100644 --- a/packages/stream_chat/test/src/models/user_test.dart +++ b/packages/stream_chat/test/src/models/user_test.dart @@ -1,6 +1,6 @@ import 'dart:convert'; -import 'package:stream_chat/src/models/user.dart'; +import 'package:stream_chat/src/core/models/user.dart'; import 'package:test/test.dart'; void main() {