|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +RSpec.describe DataModels do |
| 4 | + include DataModels |
| 5 | + |
| 6 | + describe 'data_models' do |
| 7 | + context 'get_ack_object' do |
| 8 | + let(:error) { 'error' } |
| 9 | + let(:data) { { key: 'value' } } |
| 10 | + let(:cid) { [*1..6].sample } |
| 11 | + |
| 12 | + before(:each) do |
| 13 | + @ack_object = get_ack_object(error, data, cid) |
| 14 | + end |
| 15 | + |
| 16 | + it 'should return an ack object of type hash' do |
| 17 | + expect(@ack_object.class).to eq(Hash) |
| 18 | + end |
| 19 | + |
| 20 | + it 'should return an error, data and cid in ack object' do |
| 21 | + expect(@ack_object.keys.include?(:error)).to be(true) |
| 22 | + expect(@ack_object[:error]).to eq(error) |
| 23 | + expect(@ack_object.keys.include?(:data)).to be(true) |
| 24 | + expect(@ack_object[:data]).to eq(data) |
| 25 | + expect(@ack_object.keys.include?(:cid)).to be(true) |
| 26 | + expect(@ack_object[:cid]).to eq(cid) |
| 27 | + end |
| 28 | + end |
| 29 | + |
| 30 | + context 'get_emit_object' do |
| 31 | + let(:event) { 'event' } |
| 32 | + let(:data) { { key: 'value' } } |
| 33 | + |
| 34 | + before(:each) do |
| 35 | + @emit_object = get_emit_object(event, data) |
| 36 | + end |
| 37 | + |
| 38 | + it 'should return an emit object of type hash' do |
| 39 | + expect(@emit_object.class).to eq(Hash) |
| 40 | + end |
| 41 | + |
| 42 | + it 'should return an event and data in emit object' do |
| 43 | + expect(@emit_object.keys.include?(:event)).to be(true) |
| 44 | + expect(@emit_object[:event]).to eq(event) |
| 45 | + expect(@emit_object.keys.include?(:data)).to be(true) |
| 46 | + expect(@emit_object[:data]).to eq(data) |
| 47 | + end |
| 48 | + end |
| 49 | + |
| 50 | + context 'get_emit_ack_object' do |
| 51 | + let(:event) { 'event' } |
| 52 | + let(:data) { { key: 'value' } } |
| 53 | + let(:cid) { [*1..6].sample } |
| 54 | + |
| 55 | + before(:each) do |
| 56 | + @emit_ack_object = get_emit_ack_object(event, data, cid) |
| 57 | + end |
| 58 | + |
| 59 | + it 'should return an emit ack object of type hash' do |
| 60 | + expect(@emit_ack_object.class).to eq(Hash) |
| 61 | + end |
| 62 | + |
| 63 | + it 'should return an event, data and cid in emit ack object' do |
| 64 | + expect(@emit_ack_object.keys.include?(:event)).to be(true) |
| 65 | + expect(@emit_ack_object[:event]).to eq(event) |
| 66 | + expect(@emit_ack_object.keys.include?(:data)).to be(true) |
| 67 | + expect(@emit_ack_object[:data]).to eq(data) |
| 68 | + expect(@emit_ack_object.keys.include?(:cid)).to be(true) |
| 69 | + expect(@emit_ack_object[:cid]).to eq(cid) |
| 70 | + end |
| 71 | + end |
| 72 | + |
| 73 | + context 'get_handshake_object' do |
| 74 | + let(:cid) { [*1..6].sample } |
| 75 | + |
| 76 | + before(:each) do |
| 77 | + @handshake_object = get_handshake_object(cid) |
| 78 | + end |
| 79 | + |
| 80 | + it 'should return a handshake object of type hash' do |
| 81 | + expect(@handshake_object.class).to eq(Hash) |
| 82 | + end |
| 83 | + |
| 84 | + it 'should return an event, data and cid in handshake object' do |
| 85 | + expect(@handshake_object.keys.include?(:event)).to be(true) |
| 86 | + expect(@handshake_object[:event]).to eq('#handshake') |
| 87 | + expect(@handshake_object.keys.include?(:data)).to be(true) |
| 88 | + expect(@handshake_object[:data].keys.include?(:authToken)).to be(true) |
| 89 | + expect(@handshake_object.keys.include?(:cid)).to be(true) |
| 90 | + expect(@handshake_object[:cid]).to eq(cid) |
| 91 | + end |
| 92 | + end |
| 93 | + |
| 94 | + context 'get_publish_object' do |
| 95 | + let(:channel) { 'channel' } |
| 96 | + let(:data) { { key: 'value' } } |
| 97 | + let(:cid) { [*1..6].sample } |
| 98 | + |
| 99 | + before(:each) do |
| 100 | + @publish_object = get_publish_object(channel, data, cid) |
| 101 | + end |
| 102 | + |
| 103 | + it 'should return a publish object of type hash' do |
| 104 | + expect(@publish_object.class).to eq(Hash) |
| 105 | + end |
| 106 | + |
| 107 | + it 'should return an event, channel, data and cid in publish object' do |
| 108 | + expect(@publish_object.keys.include?(:event)).to be(true) |
| 109 | + expect(@publish_object[:event]).to eq('#publish') |
| 110 | + expect(@publish_object.keys.include?(:data)).to be(true) |
| 111 | + expect(@publish_object[:data].keys.include?(:channel)).to be(true) |
| 112 | + expect(@publish_object[:data].class).to eq(Hash) |
| 113 | + expect(@publish_object.keys.include?(:cid)).to be(true) |
| 114 | + expect(@publish_object[:cid]).to be(cid) |
| 115 | + end |
| 116 | + end |
| 117 | + |
| 118 | + context 'get_subscribe_object' do |
| 119 | + let(:channel) { 'channel' } |
| 120 | + let(:cid) { [*1..6].sample } |
| 121 | + |
| 122 | + before(:each) do |
| 123 | + @subscribe_object = get_subscribe_object(channel, cid) |
| 124 | + end |
| 125 | + |
| 126 | + it 'should return a subscribe object of type hash' do |
| 127 | + expect(@subscribe_object.class).to eq(Hash) |
| 128 | + end |
| 129 | + |
| 130 | + it 'should return an event, data, channel and cid in subscribe object' do |
| 131 | + expect(@subscribe_object.keys.include?(:event)).to be(true) |
| 132 | + expect(@subscribe_object[:event]).to eq('#subscribe') |
| 133 | + expect(@subscribe_object[:data].class).to eq(Hash) |
| 134 | + expect(@subscribe_object.keys.include?(:data)).to be(true) |
| 135 | + expect(@subscribe_object[:data].keys.include?(:channel)).to be(true) |
| 136 | + expect(@subscribe_object[:data][:channel]).to eq(channel) |
| 137 | + expect(@subscribe_object.keys.include?(:cid)).to be(true) |
| 138 | + expect(@subscribe_object[:cid]).to be(cid) |
| 139 | + end |
| 140 | + end |
| 141 | + |
| 142 | + context 'get_unsubscribe_object' do |
| 143 | + let(:channel) { 'channel' } |
| 144 | + let(:cid) { [*1..6].sample } |
| 145 | + |
| 146 | + before(:each) do |
| 147 | + @unsubscribe_object = get_unsubscribe_object(channel, cid) |
| 148 | + end |
| 149 | + |
| 150 | + it 'should return an unsubscribe object of type hash' do |
| 151 | + expect(@unsubscribe_object.class).to eq(Hash) |
| 152 | + end |
| 153 | + |
| 154 | + it 'should return an event, data and cid in unsubscribe object' do |
| 155 | + expect(@unsubscribe_object.keys.include?(:event)).to be(true) |
| 156 | + expect(@unsubscribe_object[:event]).to eq('#unsubscribe') |
| 157 | + expect(@unsubscribe_object.keys.include?(:data)).to be(true) |
| 158 | + expect(@unsubscribe_object[:data]).to eq(channel) |
| 159 | + expect(@unsubscribe_object.keys.include?(:cid)).to be(true) |
| 160 | + expect(@unsubscribe_object[:cid]).to be(cid) |
| 161 | + end |
| 162 | + end |
| 163 | + end |
| 164 | +end |
0 commit comments