From 297b3fa71d5675c0347b15c6359001b1c9e7a88b Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Tue, 7 May 2024 17:44:48 +0530 Subject: [PATCH] Updated recovery key context tests for decoding recovery key --- .../realtime/recovery_key_context_spec.rb | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/spec/unit/realtime/recovery_key_context_spec.rb b/spec/unit/realtime/recovery_key_context_spec.rb index 3415e8f8..c3261631 100644 --- a/spec/unit/realtime/recovery_key_context_spec.rb +++ b/spec/unit/realtime/recovery_key_context_spec.rb @@ -4,20 +4,26 @@ describe Ably::Realtime::RecoveryKeyContext do context 'recovery context' do - let(:recovery_context) do + + it 'should encode recovery key context' do connection_key = 'key' msg_serial = 123 channel_serials = { 'channel1' => 'serial1', 'channel2' => 'serial2' } - return Ably::Realtime::RecoveryKeyContext.new(connection_key, msg_serial, channel_serials) - end - - it 'should encode recovery key context' do + recovery_context = Ably::Realtime::RecoveryKeyContext.new(connection_key, msg_serial, channel_serials) encoded_recovery_key = recovery_context.to_json - expect(encoded_recovery_key).to eql "{\"connection_key\":\"key\",\"msg_serial\":123," << - "\"channel_serials\":{\"channel1\":\"serial1\",\"channel2\":\"serial2\"}}" + expect(encoded_recovery_key).to eq "{\"connection_key\":\"key\",\"msg_serial\":123," << + "\"channel_serials\":{\"channel1\":\"serial1\",\"channel2\":\"serial2\"}}" end end + + it 'should decode recovery key context' do + encoded_recovery_key = "{\"connection_key\":\"key\",\"msg_serial\":123," << + "\"channel_serials\":{\"channel1\":\"serial1\",\"channel2\":\"serial2\"}}" + decoded_recovery_key = Ably::Realtime::RecoveryKeyContext.from_json(encoded_recovery_key) + expect(decoded_recovery_key.connection_key).to eq("key") + expect(decoded_recovery_key.msg_serial).to eq(123) + end end