pusher-fake 4.1.0 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/lib/pusher-fake/server/chain_trap_handlers.rb +24 -0
  3. data/lib/pusher-fake/server.rb +10 -0
  4. data/lib/pusher-fake.rb +1 -1
  5. metadata +20 -81
  6. data/spec/features/api/channels_spec.rb +0 -86
  7. data/spec/features/api/users_spec.rb +0 -36
  8. data/spec/features/client/connect_spec.rb +0 -11
  9. data/spec/features/client/event_spec.rb +0 -49
  10. data/spec/features/client/presence_spec.rb +0 -58
  11. data/spec/features/client/subscribe_spec.rb +0 -84
  12. data/spec/features/server/event_spec.rb +0 -122
  13. data/spec/features/server/webhooks_spec.rb +0 -107
  14. data/spec/lib/pusher-fake/channel/presence_spec.rb +0 -249
  15. data/spec/lib/pusher-fake/channel/private_spec.rb +0 -180
  16. data/spec/lib/pusher-fake/channel/public_spec.rb +0 -206
  17. data/spec/lib/pusher-fake/channel_spec.rb +0 -122
  18. data/spec/lib/pusher-fake/configuration_spec.rb +0 -123
  19. data/spec/lib/pusher-fake/connection_spec.rb +0 -332
  20. data/spec/lib/pusher-fake/server/application_spec.rb +0 -604
  21. data/spec/lib/pusher-fake/server_spec.rb +0 -177
  22. data/spec/lib/pusher-fake/webhook_spec.rb +0 -67
  23. data/spec/lib/pusher_fake_spec.rb +0 -96
  24. data/spec/spec_helper.rb +0 -31
  25. data/spec/support/application/public/javascripts/vendor/polyfill.min.js +0 -1
  26. data/spec/support/application/public/javascripts/vendor/pusher-7.0.6.js +0 -4567
  27. data/spec/support/application/views/index.erb +0 -91
  28. data/spec/support/application.rb +0 -35
  29. data/spec/support/capybara.rb +0 -10
  30. data/spec/support/helpers/connect.rb +0 -21
  31. data/spec/support/helpers/event.rb +0 -11
  32. data/spec/support/helpers/subscription.rb +0 -31
  33. data/spec/support/helpers/user.rb +0 -13
  34. data/spec/support/matchers/have_configuration_option.rb +0 -19
  35. data/spec/support/pusher_fake.rb +0 -21
  36. data/spec/support/webhooks.rb +0 -40
@@ -1,206 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe PusherFake::Channel::Public do
6
- subject { described_class }
7
-
8
- let(:name) { "channel" }
9
-
10
- it "assigns the provided name" do
11
- channel = subject.new(name)
12
-
13
- expect(channel.name).to eq(name)
14
- end
15
-
16
- it "creates an empty connections array" do
17
- channel = subject.new(name)
18
-
19
- expect(channel.connections).to eq([])
20
- end
21
- end
22
-
23
- describe PusherFake::Channel, "#add" do
24
- subject { PusherFake::Channel::Public.new(name) }
25
-
26
- let(:name) { "name" }
27
- let(:connection) { instance_double(PusherFake::Connection, emit: nil) }
28
- let(:connections) { instance_double(Array, push: nil, length: 0) }
29
-
30
- before do
31
- allow(PusherFake::Webhook).to receive(:trigger)
32
- allow(subject).to receive(:connections).and_return(connections)
33
- end
34
-
35
- it "adds the connection" do
36
- subject.add(connection)
37
-
38
- expect(connections).to have_received(:push).with(connection)
39
- end
40
-
41
- it "successfully subscribes the connection" do
42
- subject.add(connection)
43
-
44
- expect(connection).to have_received(:emit)
45
- .with("pusher_internal:subscription_succeeded", {}, subject.name)
46
- end
47
-
48
- it "triggers channel occupied webhook for the first connection added" do
49
- allow(subject).to receive(:connections).and_call_original
50
-
51
- 2.times { subject.add(connection) }
52
-
53
- expect(PusherFake::Webhook).to have_received(:trigger)
54
- .with("channel_occupied", channel: name).once
55
- end
56
-
57
- context "when a cached channel" do
58
- let(:name) { "cache-name" }
59
-
60
- before do
61
- allow(subject).to receive(:connections).and_call_original
62
- end
63
-
64
- context "with a cached event" do
65
- before do
66
- subject.emit("example-cache-event", example: true)
67
- end
68
-
69
- it "triggers the cached event to the connection added" do
70
- subject.add(connection)
71
-
72
- expect(connection).to have_received(:emit)
73
- .with("example-cache-event", { example: true }, name).once
74
- end
75
-
76
- it "does not trigger cache miss event" do
77
- subject.add(connection)
78
-
79
- expect(connection).not_to have_received(:emit)
80
- .with("pusher:cache-miss", nil, name)
81
- end
82
-
83
- it "does not trigger cache miss webhook" do
84
- subject.add(connection)
85
-
86
- expect(PusherFake::Webhook).not_to have_received(:trigger)
87
- .with("cache_miss", channel: name)
88
- end
89
- end
90
-
91
- context "without a cached event" do
92
- it "triggers cache miss event" do
93
- subject.add(connection)
94
-
95
- expect(connection).to have_received(:emit)
96
- .with("pusher:cache_miss", nil, name).once
97
- end
98
-
99
- it "triggers cache miss webhook" do
100
- subject.add(connection)
101
-
102
- expect(PusherFake::Webhook).to have_received(:trigger)
103
- .with("cache_miss", channel: name).once
104
- end
105
-
106
- it "does not trigger event" do
107
- subject.add(connection)
108
-
109
- expect(connection).not_to have_received(:emit)
110
- .with("example-cache-event", { example: true }, name)
111
- end
112
- end
113
- end
114
- end
115
-
116
- describe PusherFake::Channel, "#emit" do
117
- subject { PusherFake::Channel::Public.new(name) }
118
-
119
- let(:data) { double }
120
- let(:name) { "name" }
121
- let(:event) { "event" }
122
- let(:connections) { [connection_1, connection_2] }
123
-
124
- let(:connection_1) do
125
- instance_double(PusherFake::Connection, emit: nil, id: "1")
126
- end
127
-
128
- let(:connection_2) do
129
- instance_double(PusherFake::Connection, emit: nil, id: "2")
130
- end
131
-
132
- before do
133
- allow(subject).to receive(:connections).and_return(connections)
134
- end
135
-
136
- it "emits the event for each connection in the channel" do
137
- subject.emit(event, data)
138
-
139
- expect(connection_1).to have_received(:emit).with(event, data, name)
140
- expect(connection_2).to have_received(:emit).with(event, data, name)
141
- end
142
-
143
- it "ignores connection if socket_id matches the connections ID" do
144
- subject.emit(event, data, socket_id: connection_2.id)
145
-
146
- expect(connection_1).to have_received(:emit).with(event, data, name)
147
- expect(connection_2).not_to have_received(:emit)
148
- end
149
- end
150
-
151
- describe PusherFake::Channel, "#includes?" do
152
- subject { PusherFake::Channel::Public.new("name") }
153
-
154
- let(:connection) { double }
155
-
156
- it "returns true if the connection is in the channel" do
157
- allow(subject).to receive(:connections).and_return([connection])
158
-
159
- expect(subject).to be_includes(connection)
160
- end
161
-
162
- it "returns false if the connection is not in the channel" do
163
- allow(subject).to receive(:connections).and_return([])
164
-
165
- expect(subject).not_to be_includes(connection)
166
- end
167
- end
168
-
169
- describe PusherFake::Channel, "#remove" do
170
- subject { PusherFake::Channel::Public.new(name) }
171
-
172
- let(:name) { "name" }
173
- let(:connection_1) { double }
174
- let(:connection_2) { double }
175
-
176
- before do
177
- allow(PusherFake::Webhook).to receive(:trigger)
178
- allow(subject).to receive(:connections)
179
- .and_return([connection_1, connection_2])
180
- end
181
-
182
- it "removes the connection from the channel" do
183
- subject.remove(connection_1)
184
-
185
- expect(subject.connections).not_to include(connection_1)
186
- end
187
-
188
- it "triggers channel vacated webhook when all connections are removed" do
189
- subject.remove(connection_1)
190
-
191
- expect(PusherFake::Webhook).not_to have_received(:trigger)
192
-
193
- subject.remove(connection_2)
194
-
195
- expect(PusherFake::Webhook).to have_received(:trigger)
196
- .with("channel_vacated", channel: name).once
197
- end
198
- end
199
-
200
- describe PusherFake::Channel::Public, "#subscription_data" do
201
- subject { described_class.new("name") }
202
-
203
- it "returns an empty hash" do
204
- expect(subject.subscription_data).to eq({})
205
- end
206
- end
@@ -1,122 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe PusherFake::Channel, ".factory" do
6
- shared_examples_for "a channel factory" do
7
- subject { described_class }
8
-
9
- let(:channel) { double }
10
-
11
- before do
12
- allow(channel_class).to receive(:new).and_return(channel)
13
- end
14
-
15
- after do
16
- subject.reset
17
- end
18
-
19
- it "caches the channel" do
20
- allow(channel_class).to receive(:new).and_call_original
21
-
22
- factory_one = subject.factory(name)
23
- factory_two = subject.factory(name)
24
-
25
- expect(factory_one).to eq(factory_two)
26
- end
27
-
28
- it "creates the channel by name" do
29
- subject.factory(name)
30
-
31
- expect(channel_class).to have_received(:new).with(name)
32
- end
33
-
34
- it "returns the channel instance" do
35
- factory = subject.factory(name)
36
-
37
- expect(factory).to eq(channel)
38
- end
39
- end
40
-
41
- context "with a public channel" do
42
- let(:name) { "channel" }
43
- let(:channel_class) { PusherFake::Channel::Public }
44
-
45
- it_behaves_like "a channel factory"
46
- end
47
-
48
- context "with a private channel" do
49
- let(:name) { "private-channel" }
50
- let(:channel_class) { PusherFake::Channel::Private }
51
-
52
- it_behaves_like "a channel factory"
53
- end
54
-
55
- context "with a presence channel" do
56
- let(:name) { "presence-channel" }
57
- let(:channel_class) { PusherFake::Channel::Presence }
58
-
59
- it_behaves_like "a channel factory"
60
- end
61
- end
62
-
63
- describe PusherFake::Channel, ".remove" do
64
- subject { described_class }
65
-
66
- let(:channels) { { channel_1: channel_1, channel_2: channel_2 } }
67
- let(:connection) { double }
68
-
69
- let(:channel_1) do
70
- instance_double(PusherFake::Channel::Public,
71
- remove: nil,
72
- connections: instance_double(Array, empty?: true))
73
- end
74
-
75
- let(:channel_2) do
76
- instance_double(PusherFake::Channel::Public,
77
- remove: nil,
78
- connections: instance_double(Array, empty?: false))
79
- end
80
-
81
- before do
82
- allow(subject).to receive(:channels).and_return(channels)
83
- end
84
-
85
- it "removes the connection from all channels" do
86
- subject.remove(connection)
87
-
88
- expect(channel_1).to have_received(:remove).with(connection)
89
- expect(channel_2).to have_received(:remove).with(connection)
90
- end
91
-
92
- it "deletes a channel with no connections remaining" do
93
- subject.remove(connection)
94
-
95
- expect(channels).not_to have_key(:channel_1)
96
- end
97
-
98
- it "does not delete a channel with connections remaining" do
99
- subject.remove(connection)
100
-
101
- expect(channels).to have_key(:channel_2)
102
- end
103
-
104
- it "handles channels not being defined" do
105
- allow(subject).to receive(:channels).and_return(nil)
106
-
107
- expect do
108
- subject.remove(connection)
109
- end.not_to raise_error
110
- end
111
- end
112
-
113
- describe PusherFake::Channel, ".reset" do
114
- subject { described_class }
115
-
116
- it "empties the channel cache" do
117
- subject.factory("example")
118
- subject.reset
119
-
120
- expect(subject.channels).to eq({})
121
- end
122
- end
@@ -1,123 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe PusherFake::Configuration do
6
- it do
7
- expect(subject).to have_configuration_option(:disable_stats)
8
- .with_default(true)
9
- end
10
-
11
- it do
12
- expect(subject).to have_configuration_option(:key)
13
- .with_default("PUSHER_API_KEY")
14
- end
15
-
16
- it do
17
- expect(subject).to have_configuration_option(:logger)
18
- .with_default($stdout.to_io)
19
- end
20
-
21
- it do
22
- expect(subject).to have_configuration_option(:verbose)
23
- .with_default(false)
24
- end
25
-
26
- it do
27
- expect(subject).to have_configuration_option(:webhooks)
28
- .with_default([])
29
- end
30
-
31
- it do
32
- expect(subject).to have_configuration_option(:app_id)
33
- .with_default("PUSHER_APP_ID")
34
- end
35
-
36
- it do
37
- expect(subject).to have_configuration_option(:secret)
38
- .with_default("PUSHER_API_SECRET")
39
- end
40
-
41
- it "has configuration option :socket_options" do
42
- expect(subject.socket_options).to be_a(Hash)
43
- expect(subject.socket_options[:host]).to eq("127.0.0.1")
44
- expect(subject.socket_options[:port]).to be_a(Integer)
45
- end
46
-
47
- it "has configuration option :web_options" do
48
- expect(subject.web_options).to be_a(Hash)
49
- expect(subject.web_options[:host]).to eq("127.0.0.1")
50
- expect(subject.web_options[:port]).to be_a(Integer)
51
- end
52
-
53
- it "defaults socket and web ports to different values" do
54
- expect(subject.socket_options[:port]).not_to eq(subject.web_options[:port])
55
- end
56
-
57
- context "with StringIO as standard out" do
58
- let(:io) { StringIO.new }
59
-
60
- around do |example|
61
- original = $stdout
62
- $stdout = io # rubocop:disable RSpec/ExpectOutput
63
-
64
- example.run
65
-
66
- $stdout = original # rubocop:disable RSpec/ExpectOutput
67
- end
68
-
69
- it "assigns standard out to the logger" do
70
- subject.reset!
71
-
72
- expect(subject.logger).to eq(io)
73
- end
74
- end
75
- end
76
-
77
- describe PusherFake::Configuration, "#app_id=" do
78
- subject { described_class.new }
79
-
80
- it "converts value to a string" do
81
- subject.app_id = 1_337
82
-
83
- expect(subject.app_id).to eq("1337")
84
- end
85
- end
86
-
87
- describe PusherFake::Configuration, "#to_options" do
88
- it "includes disable_stats as disableStats" do
89
- options = subject.to_options
90
-
91
- expect(options).to include(disableStats: subject.disable_stats)
92
- end
93
-
94
- it "includes the socket host as wsHost" do
95
- options = subject.to_options
96
-
97
- expect(options).to include(wsHost: subject.socket_options[:host])
98
- end
99
-
100
- it "includes the socket port as wsPort" do
101
- options = subject.to_options
102
-
103
- expect(options).to include(wsPort: subject.socket_options[:port])
104
- end
105
-
106
- it "includes the cluster by default" do
107
- options = subject.to_options
108
-
109
- expect(options).to include(cluster: "us-east-1")
110
- end
111
-
112
- it "disables the forceTLS option" do
113
- options = subject.to_options
114
-
115
- expect(options).to include(forceTLS: false)
116
- end
117
-
118
- it "supports passing custom options" do
119
- options = subject.to_options(custom: "option")
120
-
121
- expect(options).to include(custom: "option")
122
- end
123
- end