Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
imtoori committed Apr 14, 2022
1 parent a2f1981 commit da4fd16
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion packages/stream_chat/test/src/ws/websocket_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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), () {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit da4fd16

Please sign in to comment.