Skip to content

Commit

Permalink
Replaces MockPhoenixSocketOptions with actual object
Browse files Browse the repository at this point in the history
  • Loading branch information
kpsroka committed Aug 27, 2024
1 parent f2aab67 commit bb46924
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions test/socket_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,24 @@ void main() {
test('socket connect does not create new socket if one is already connected',
() async {
final optionsCompleter = Completer<Map<String, String>>();
final mockPhoenixSocketOptions = MockPhoenixSocketOptions();
when(mockPhoenixSocketOptions.getParams())
.thenAnswer((_) => optionsCompleter.future);
when(mockPhoenixSocketOptions.heartbeat).thenReturn(Duration(days: 1));
when(mockPhoenixSocketOptions.reconnectDelays).thenReturn([Duration.zero]);

final sentRefs = <String>[];
when(mockPhoenixSocketOptions.serializer).thenReturn(MessageSerializer(
encoder: (object) {
if (object is List) {
final message = Message.fromJson(object);
sentRefs.add(message.ref!);
return message.ref!;
}
return 'ignored';
},
decoder: (ref) => Message.heartbeat(ref).encode(),
));

PhoenixSocketOptions socketOptions = PhoenixSocketOptions(
dynamicParams: () => optionsCompleter.future,
heartbeat: Duration(days: 1),
reconnectDelays: [Duration.zero],
serializer: MessageSerializer(
encoder: (object) {
if (object is List) {
final message = Message.fromJson(object);
sentRefs.add(message.ref!);
return message.ref!;
}
return 'ignored';
},
decoder: (ref) => Message.heartbeat(ref).encode(),
));

int factoryCalls = 0;
WebSocketChannel stubWebSocketChannelFactory(Uri uri) {
Expand All @@ -112,7 +112,7 @@ void main() {
final phoenixSocket = PhoenixSocket(
'ws://endpoint',
webSocketChannelFactory: stubWebSocketChannelFactory,
socketOptions: mockPhoenixSocketOptions,
socketOptions: socketOptions,
);

// Connect to the socket
Expand Down

0 comments on commit bb46924

Please sign in to comment.