From da4fd16af7c38ebfd396b9d220dea8432909d6f9 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Thu, 14 Apr 2022 11:32:32 +0200 Subject: [PATCH] add test --- .../test/src/ws/websocket_test.dart | 43 ++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/packages/stream_chat/test/src/ws/websocket_test.dart b/packages/stream_chat/test/src/ws/websocket_test.dart index 5519b2b3d..68242333f 100644 --- a/packages/stream_chat/test/src/ws/websocket_test.dart +++ b/packages/stream_chat/test/src/ws/websocket_test.dart @@ -59,7 +59,10 @@ void main() { }); test('`connect` successfully with the provided user', () async { - final user = OwnUser(id: 'test-user'); + final user = OwnUser( + id: 'test-user', + name: 'test', + ); const connectionId = 'test-connection-id'; // Sends connect event to web-socket stream final timer = Timer(const Duration(milliseconds: 300), () { @@ -90,6 +93,44 @@ void main() { addTearDown(timer.cancel); }); + test('`connect` successfully without user details', () async { + final user = OwnUser( + id: 'test-user', + name: 'test', + ); + const connectionId = 'test-connection-id'; + // Sends connect event to web-socket stream + final timer = Timer(const Duration(milliseconds: 300), () { + final event = Event( + type: EventType.healthCheck, + connectionId: connectionId, + me: user, + ); + webSocketSink.add(json.encode(event)); + }); + + expectLater( + webSocket.connectionStatusStream, + emitsInOrder([ + ConnectionStatus.disconnected, + ConnectionStatus.connecting, + ConnectionStatus.connected, + ]), + ); + + final event = await webSocket.connect( + user, + includeUserDetails: true, + ); + + expect(event.type, EventType.healthCheck); + expect(event.connectionId, connectionId); + expect(event.me, isNotNull); + expect(event.me!.id, user.id); + + addTearDown(timer.cancel); + }); + test('`connect` should throw if already in connection attempt', () async { final user = OwnUser(id: 'test-user'); webSocket.connect(user);