spec/unit/models/protocol_message_spec.rb in ably-0.8.15 vs spec/unit/models/protocol_message_spec.rb in ably-1.0.0
- old
+ new
@@ -8,10 +8,11 @@
def new_protocol_message(options)
subject.new({ action: 1 }.merge(options))
end
+ # TR4n, TR4b, TR4c, TR4d, TR4e
it_behaves_like 'a model',
with_simple_attributes: %w(id channel channel_serial connection_id connection_key),
base_model_options: { action: 1 } do
let(:model_args) { [] }
@@ -132,11 +133,11 @@
expect(protocol_message.connection_serial).to be_a(Integer)
expect(protocol_message.connection_serial).to eql(55)
end
end
- context '#flags' do
+ context '#flags (#TR4i)' do
context 'when nil' do
let(:protocol_message) { new_protocol_message({}) }
it 'is zero' do
expect(protocol_message.flags).to eql(0)
@@ -149,24 +150,56 @@
it 'is an Integer' do
expect(protocol_message.flags).to eql(25)
end
end
- context 'when has_presence' do
+ context 'when presence flag present' do
let(:protocol_message) { new_protocol_message(flags: 1) }
it '#has_presence_flag? is true' do
expect(protocol_message.has_presence_flag?).to be_truthy
end
+
+ it '#has_channel_resumed_flag? is false' do
+ expect(protocol_message.has_channel_resumed_flag?).to be_falsey
+ end
end
+ context 'when channel resumed flag present' do
+ let(:protocol_message) { new_protocol_message(flags: 4) }
+
+ it '#has_channel_resumed_flag? is true' do
+ expect(protocol_message.has_channel_resumed_flag?).to be_truthy
+ end
+
+ it '#has_presence_flag? is false' do
+ expect(protocol_message.has_presence_flag?).to be_falsey
+ end
+ end
+
+ context 'when channel resumed and presence flags present' do
+ let(:protocol_message) { new_protocol_message(flags: 5) }
+
+ it '#has_channel_resumed_flag? is true' do
+ expect(protocol_message.has_channel_resumed_flag?).to be_truthy
+ end
+
+ it '#has_presence_flag? is true' do
+ expect(protocol_message.has_presence_flag?).to be_truthy
+ end
+ end
+
context 'when has another future flag' do
let(:protocol_message) { new_protocol_message(flags: 2) }
it '#has_presence_flag? is false' do
expect(protocol_message.has_presence_flag?).to be_falsey
end
+
+ it '#has_backlog_flag? is true' do
+ expect(protocol_message.has_backlog_flag?).to be_truthy
+ end
end
end
context '#has_connection_serial?' do
context 'without connection_serial' do
@@ -263,31 +296,31 @@
expect(protocol_message.error.message).to eql('test_error')
end
end
end
- context '#messages' do
+ context '#messages (#TR4k)' do
let(:protocol_message) { new_protocol_message(messages: [{ name: 'test' }]) }
it 'contains Message objects' do
expect(protocol_message.messages.count).to eql(1)
expect(protocol_message.messages.first).to be_a(Ably::Models::Message)
expect(protocol_message.messages.first.name).to eql('test')
end
end
- context '#presence' do
+ context '#presence (#TR4l)' do
let(:protocol_message) { new_protocol_message(presence: [{ action: 1, data: 'test' }]) }
it 'contains PresenceMessage objects' do
expect(protocol_message.presence.count).to eql(1)
expect(protocol_message.presence.first).to be_a(Ably::Models::PresenceMessage)
expect(protocol_message.presence.first.data).to eql('test')
end
end
- context '#connection_details' do
+ context '#connection_details (#TR4o)' do
let(:connection_details) { protocol_message.connection_details }
context 'with a JSON value' do
let(:protocol_message) { new_protocol_message(connectionDetails: { clientId: '1', connectionKey: 'key' }) }
@@ -310,10 +343,35 @@
expect(connection_details.connection_key).to eql(nil)
end
end
end
- context '#connection_key' do
+ context '#auth (#TR4p)' do
+ let(:auth) { protocol_message.auth }
+
+ context 'with a JSON value' do
+ let(:protocol_message) { new_protocol_message(auth: { accesstoken: 'foo' }) }
+
+ it 'contains a AuthDetails object' do
+ expect(auth).to be_a(Ably::Models::AuthDetails)
+ end
+
+ it 'contains the attributes from the JSON auth details' do
+ expect(auth.access_token).to eql('foo')
+ end
+ end
+
+ context 'without a JSON value' do
+ let(:protocol_message) { new_protocol_message({}) }
+
+ it 'contains an empty AuthDetails object' do
+ expect(auth).to be_a(Ably::Models::AuthDetails)
+ expect(auth.access_token).to eql(nil)
+ end
+ end
+ end
+
+ context '#connection_key (#TR4e)' do
context 'existing only in #connection_details.connection_key' do
let(:protocol_message) { new_protocol_message(connectionDetails: { connectionKey: 'key' }) }
it 'is returned' do
expect(protocol_message.connection_key).to eql('key')