From 2044c8b556754194eb5bdaf1381dd5b6ac899e00 Mon Sep 17 00:00:00 2001 From: Plague Fox Date: Fri, 10 May 2024 23:31:27 +0400 Subject: [PATCH] Refactor ProtobufReplyDecoder to handle different reply types --- lib/src/protobuf/protobuf_codec.dart | 10 +++------- test/smoke/smoke_test.dart | 12 ++++++++++++ 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/lib/src/protobuf/protobuf_codec.dart b/lib/src/protobuf/protobuf_codec.dart index bef5941..3c4a8c3 100644 --- a/lib/src/protobuf/protobuf_codec.dart +++ b/lib/src/protobuf/protobuf_codec.dart @@ -134,11 +134,8 @@ final class ProtobufReplyDecoder extends Converter, SpinifyReply> { //} if (reply.hasPush()) { return _decodePush(reply.push); - } else if (reply.hasPing()) { - return SpinifyPingResult( - id: reply.id, - timestamp: DateTime.now(), - ); + } else if (reply.hasId() && reply.id > 0) { + return _decodeReply(reply); } else if (reply.hasError()) { final error = reply.error; return SpinifyError( @@ -148,9 +145,8 @@ final class ProtobufReplyDecoder extends Converter, SpinifyReply> { message: error.message, temporary: error.temporary, ); - } else if (reply.hasId() && reply.id > 0) { - return _decodeReply(reply); } else { + // TODO(plugfox): Implement ping reply throw UnimplementedError('Unsupported reply type'); } } diff --git a/test/smoke/smoke_test.dart b/test/smoke/smoke_test.dart index 1de96af..02af00d 100644 --- a/test/smoke/smoke_test.dart +++ b/test/smoke/smoke_test.dart @@ -17,5 +17,17 @@ void main() { await client.close(); expect(client.state, isA()); }); + + test('Connect_and_refresh', () async { + final client = Spinify(); + await client.connect(url); + expect(client.state, isA()); + //await client.ping(); + await Future.delayed(const Duration(seconds: 360)); + await client.disconnect(); + expect(client.state, isA()); + await client.close(); + expect(client.state, isA()); + }); }); }