spec/acceptance/realtime/message_spec.rb in ably-0.8.1 vs spec/acceptance/realtime/message_spec.rb in ably-0.8.2

- old
+ new

@@ -30,10 +30,91 @@ stop_reactor end end end + context 'with supported data payload content type' do + def publish_and_check_data(data) + channel.attach + channel.publish 'event', data + channel.subscribe do |message| + expect(message.data).to eql(data) + stop_reactor + end + end + + context 'JSON Object (Hash)' do + let(:data) { { 'Hash' => 'true' } } + + it 'is encoded and decoded to the same hash' do + publish_and_check_data data + end + end + + context 'JSON Array' do + let(:data) { [ nil, true, false, 55, 'string', { 'Hash' => true }, ['array'] ] } + + it 'is encoded and decoded to the same Array' do + publish_and_check_data data + end + end + + context 'String' do + let(:data) { random_str } + + it 'is encoded and decoded to the same Array' do + publish_and_check_data data + end + end + + context 'Binary' do + let(:data) { Base64.encode64(random_str) } + + it 'is encoded and decoded to the same Array' do + publish_and_check_data data + end + end + end + + context 'with unsupported data payload content type' do + context 'Integer' do + let(:data) { 1 } + + it 'is raises an UnsupportedDataTypeError 40011 exception' do + expect { channel.publish 'event', data }.to raise_error(Ably::Exceptions::UnsupportedDataTypeError) + stop_reactor + end + end + + context 'Float' do + let(:data) { 1.1 } + + it 'is raises an UnsupportedDataTypeError 40011 exception' do + expect { channel.publish 'event', data }.to raise_error(Ably::Exceptions::UnsupportedDataTypeError) + stop_reactor + end + end + + context 'Boolean' do + let(:data) { true } + + it 'is raises an UnsupportedDataTypeError 40011 exception' do + expect { channel.publish 'event', data }.to raise_error(Ably::Exceptions::UnsupportedDataTypeError) + stop_reactor + end + end + + context 'False' do + let(:data) { false } + + it 'is raises an UnsupportedDataTypeError 40011 exception' do + expect { channel.publish 'event', data }.to raise_error(Ably::Exceptions::UnsupportedDataTypeError) + stop_reactor + end + end + end + context 'with ASCII_8BIT message name' do let(:message_name) { random_str.encode(Encoding::ASCII_8BIT) } it 'is converted into UTF_8' do channel.attach do channel.publish message_name, payload @@ -408,11 +489,11 @@ expect(message.encoding).to match(/^cipher\+aes-256-cbc/) stop_reactor end end - it 'triggers a Cipher error on the channel' do + it 'emits a Cipher error on the channel' do unencrypted_channel_client2.attach do encrypted_channel_client1.publish 'example', payload unencrypted_channel_client2.on(:error) do |error| expect(error).to be_a(Ably::Exceptions::CipherError) expect(error.code).to eql(92001) @@ -439,11 +520,11 @@ expect(message.encoding).to match(/^cipher\+aes-256-cbc/) stop_reactor end end - it 'triggers a Cipher error on the channel' do + it 'emits a Cipher error on the channel' do encrypted_channel_client2.attach do encrypted_channel_client1.publish 'example', payload encrypted_channel_client2.on(:error) do |error| expect(error).to be_a(Ably::Exceptions::CipherError) expect(error.code).to eql(92002) @@ -462,18 +543,20 @@ let(:encrypted_channel_client2) { other_client.channel(channel_name, encrypted: true, cipher_params: cipher_options_client2) } let(:payload) { MessagePack.pack({ 'key' => random_str }) } it 'delivers the message but still encrypted with the cipher details in the #encoding attribute' do - encrypted_channel_client1.publish 'example', payload - encrypted_channel_client2.subscribe do |message| - expect(message.data).to_not eql(payload) - expect(message.encoding).to match(/^cipher\+aes-256-cbc/) - stop_reactor + encrypted_channel_client2.attach do + encrypted_channel_client1.publish 'example', payload + encrypted_channel_client2.subscribe do |message| + expect(message.data).to_not eql(payload) + expect(message.encoding).to match(/^cipher\+aes-256-cbc/) + stop_reactor + end end end - it 'triggers a Cipher error on the channel' do + it 'emits a Cipher error on the channel' do encrypted_channel_client2.attach do encrypted_channel_client1.publish 'example', payload encrypted_channel_client2.on(:error) do |error| expect(error).to be_a(Ably::Exceptions::CipherError) expect(error.code).to eql(92003)