pusher-fake 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/features/step_definitions/api_steps.rb +11 -9
- data/features/step_definitions/channel_steps.rb +6 -3
- data/features/step_definitions/client_steps.rb +4 -2
- data/features/step_definitions/event_steps.rb +4 -2
- data/features/step_definitions/presence_steps.rb +2 -2
- data/features/step_definitions/webhook_steps.rb +1 -1
- data/features/support/environment.rb +6 -0
- data/features/support/webhooks.rb +1 -1
- data/lib/pusher-fake.rb +8 -2
- data/lib/pusher-fake/channel/presence.rb +4 -2
- data/lib/pusher-fake/channel/public.rb +3 -3
- data/lib/pusher-fake/configuration.rb +10 -2
- data/lib/pusher-fake/connection.rb +10 -9
- data/lib/pusher-fake/server/application.rb +1 -1
- data/lib/pusher-fake/webhook.rb +6 -3
- data/spec/lib/pusher-fake/channel/presence_spec.rb +84 -27
- data/spec/lib/pusher-fake/channel/private_spec.rb +37 -20
- data/spec/lib/pusher-fake/channel/public_spec.rb +29 -18
- data/spec/lib/pusher-fake/channel_spec.rb +43 -15
- data/spec/lib/pusher-fake/configuration_spec.rb +11 -3
- data/spec/lib/pusher-fake/connection_spec.rb +74 -20
- data/spec/lib/pusher-fake/server/application_spec.rb +72 -36
- data/spec/lib/pusher-fake/server_spec.rb +46 -23
- data/spec/lib/pusher-fake/webhook_spec.rb +7 -3
- data/spec/lib/pusher_fake_spec.rb +41 -10
- data/spec/spec_helper.rb +4 -2
- data/spec/support/have_configuration_option_matcher.rb +12 -39
- metadata +4 -18
@@ -19,26 +19,32 @@ shared_examples_for "an API request" do
|
|
19
19
|
|
20
20
|
it "creates a request" do
|
21
21
|
subject.call(environment)
|
22
|
-
|
22
|
+
|
23
|
+
expect(Rack::Request).to have_received(:new).with(environment)
|
23
24
|
end
|
24
25
|
|
25
26
|
it "dumps the response hash to JSON" do
|
26
27
|
subject.call(environment)
|
27
|
-
|
28
|
+
|
29
|
+
expect(MultiJson).to have_received(:dump).with(hash)
|
28
30
|
end
|
29
31
|
|
30
32
|
it "creates a Rack response with the response JSON" do
|
31
33
|
subject.call(environment)
|
32
|
-
|
34
|
+
|
35
|
+
expect(Rack::Response).to have_received(:new).with(string)
|
33
36
|
end
|
34
37
|
|
35
38
|
it "finishes the response" do
|
36
39
|
subject.call(environment)
|
37
|
-
|
40
|
+
|
41
|
+
expect(response).to have_received(:finish).with()
|
38
42
|
end
|
39
43
|
|
40
44
|
it "returns the response" do
|
41
|
-
subject.call(environment)
|
45
|
+
result = subject.call(environment)
|
46
|
+
|
47
|
+
expect(result).to eq(response)
|
42
48
|
end
|
43
49
|
end
|
44
50
|
|
@@ -53,7 +59,8 @@ describe PusherFake::Server::Application, ".call, for triggering events" do
|
|
53
59
|
|
54
60
|
it "emits events" do
|
55
61
|
subject.call(environment)
|
56
|
-
|
62
|
+
|
63
|
+
expect(subject).to have_received(:events).with(request)
|
57
64
|
end
|
58
65
|
end
|
59
66
|
end
|
@@ -69,7 +76,8 @@ describe PusherFake::Server::Application, ".call, for retrieving occupied channe
|
|
69
76
|
|
70
77
|
it "filters the occupied channels" do
|
71
78
|
subject.call(environment)
|
72
|
-
|
79
|
+
|
80
|
+
expect(subject).to have_received(:channels).with(request)
|
73
81
|
end
|
74
82
|
end
|
75
83
|
end
|
@@ -92,21 +100,26 @@ describe PusherFake::Server::Application, ".call, with unknown path" do
|
|
92
100
|
|
93
101
|
it "creates a request" do
|
94
102
|
subject.call(environment)
|
95
|
-
|
103
|
+
|
104
|
+
expect(Rack::Request).to have_received(:new).with(environment)
|
96
105
|
end
|
97
106
|
|
98
107
|
it "creates a Rack response with the error message" do
|
99
108
|
subject.call(environment)
|
100
|
-
|
109
|
+
|
110
|
+
expect(Rack::Response).to have_received(:new).with(message, 400)
|
101
111
|
end
|
102
112
|
|
103
113
|
it "finishes the response" do
|
104
114
|
subject.call(environment)
|
105
|
-
|
115
|
+
|
116
|
+
expect(response).to have_received(:finish).with()
|
106
117
|
end
|
107
118
|
|
108
119
|
it "returns the response" do
|
109
|
-
subject.call(environment)
|
120
|
+
result = subject.call(environment)
|
121
|
+
|
122
|
+
expect(result).to eq(response)
|
110
123
|
end
|
111
124
|
end
|
112
125
|
|
@@ -131,21 +144,26 @@ describe PusherFake::Server::Application, ".call, raising an error" do
|
|
131
144
|
|
132
145
|
it "creates a request" do
|
133
146
|
subject.call(environment)
|
134
|
-
|
147
|
+
|
148
|
+
expect(Rack::Request).to have_received(:new).with(environment)
|
135
149
|
end
|
136
150
|
|
137
151
|
it "creates a Rack response with the error message" do
|
138
152
|
subject.call(environment)
|
139
|
-
|
153
|
+
|
154
|
+
expect(Rack::Response).to have_received(:new).with(message, 400)
|
140
155
|
end
|
141
156
|
|
142
157
|
it "finishes the response" do
|
143
158
|
subject.call(environment)
|
144
|
-
|
159
|
+
|
160
|
+
expect(response).to have_received(:finish).with()
|
145
161
|
end
|
146
162
|
|
147
163
|
it "returns the response" do
|
148
|
-
subject.call(environment)
|
164
|
+
result = subject.call(environment)
|
165
|
+
|
166
|
+
expect(result).to eq(response)
|
149
167
|
end
|
150
168
|
end
|
151
169
|
|
@@ -171,22 +189,23 @@ describe PusherFake::Server::Application, ".events" do
|
|
171
189
|
|
172
190
|
it "parses the request body as JSON" do
|
173
191
|
subject.events(request)
|
174
|
-
|
192
|
+
|
193
|
+
expect(MultiJson).to have_received(:load).with(json)
|
175
194
|
end
|
176
195
|
|
177
196
|
it "creates channels by name" do
|
178
197
|
subject.events(request)
|
179
198
|
|
180
199
|
channels.each do |channel|
|
181
|
-
PusherFake::Channel.
|
200
|
+
expect(PusherFake::Channel).to have_received(:factory).with(channel)
|
182
201
|
end
|
183
202
|
end
|
184
203
|
|
185
204
|
it "emits the event to the channels" do
|
186
205
|
subject.events(request)
|
187
206
|
|
188
|
-
channel_1.
|
189
|
-
channel_2.
|
207
|
+
expect(channel_1).to have_received(:emit).with(name, data, socket_id: socket_id)
|
208
|
+
expect(channel_2).to have_received(:emit).with(name, data, socket_id: socket_id)
|
190
209
|
end
|
191
210
|
end
|
192
211
|
|
@@ -201,12 +220,9 @@ describe PusherFake::Server::Application, ".channels, requesting all channels" d
|
|
201
220
|
end
|
202
221
|
|
203
222
|
it "returns a hash of all the channels" do
|
204
|
-
subject.channels(request)
|
205
|
-
|
206
|
-
|
207
|
-
"channel-2" => {}
|
208
|
-
}
|
209
|
-
}
|
223
|
+
hash = subject.channels(request)
|
224
|
+
|
225
|
+
expect(hash).to eq({ channels: { "channel-1" => {}, "channel-2" => {} } })
|
210
226
|
end
|
211
227
|
end
|
212
228
|
|
@@ -222,7 +238,9 @@ describe PusherFake::Server::Application, ".channels, requesting channels with a
|
|
222
238
|
end
|
223
239
|
|
224
240
|
it "returns a hash of the channels matching the filter" do
|
225
|
-
subject.channels(request)
|
241
|
+
hash = subject.channels(request)
|
242
|
+
|
243
|
+
expect(hash).to eq({ channels: { "public-1" => {} } })
|
226
244
|
end
|
227
245
|
end
|
228
246
|
|
@@ -239,7 +257,9 @@ describe PusherFake::Server::Application, ".channels, requesting user count for
|
|
239
257
|
end
|
240
258
|
|
241
259
|
it "returns a hash of the channels matching the filter and include the user count" do
|
242
|
-
subject.channels(request)
|
260
|
+
hash = subject.channels(request)
|
261
|
+
|
262
|
+
expect(hash).to eq({ channels: { "presence-1" => { user_count: 2 } } })
|
243
263
|
end
|
244
264
|
end
|
245
265
|
|
@@ -254,7 +274,9 @@ describe PusherFake::Server::Application, ".channels, requesting all channels wi
|
|
254
274
|
end
|
255
275
|
|
256
276
|
it "returns a hash of no channels" do
|
257
|
-
subject.channels(request)
|
277
|
+
hash = subject.channels(request)
|
278
|
+
|
279
|
+
expect(hash).to eq({ channels: {} })
|
258
280
|
end
|
259
281
|
end
|
260
282
|
|
@@ -284,7 +306,9 @@ describe PusherFake::Server::Application, ".channel, for an occupied channel" do
|
|
284
306
|
end
|
285
307
|
|
286
308
|
it "returns a hash with the occupied status" do
|
287
|
-
subject.channel(name, request)
|
309
|
+
hash = subject.channel(name, request)
|
310
|
+
|
311
|
+
expect(hash).to eq({ occupied: true })
|
288
312
|
end
|
289
313
|
end
|
290
314
|
|
@@ -301,7 +325,9 @@ describe PusherFake::Server::Application, ".channel, for an unoccupied channel"
|
|
301
325
|
end
|
302
326
|
|
303
327
|
it "returns a hash with the occupied status" do
|
304
|
-
subject.channel(name, request)
|
328
|
+
hash = subject.channel(name, request)
|
329
|
+
|
330
|
+
expect(hash).to eq({ occupied: false })
|
305
331
|
end
|
306
332
|
end
|
307
333
|
|
@@ -316,7 +342,9 @@ describe PusherFake::Server::Application, ".channel, for an unknown channel" do
|
|
316
342
|
end
|
317
343
|
|
318
344
|
it "returns a hash with the occupied status" do
|
319
|
-
subject.channel("fake", request)
|
345
|
+
hash = subject.channel("fake", request)
|
346
|
+
|
347
|
+
expect(hash).to eq({ occupied: false })
|
320
348
|
end
|
321
349
|
end
|
322
350
|
|
@@ -334,7 +362,9 @@ describe PusherFake::Server::Application, ".channel, request user count for a pr
|
|
334
362
|
end
|
335
363
|
|
336
364
|
it "returns a hash with the occupied status" do
|
337
|
-
subject.channel(name, request)
|
365
|
+
hash = subject.channel(name, request)
|
366
|
+
|
367
|
+
expect(hash).to eq({ occupied: true, user_count: 2 })
|
338
368
|
end
|
339
369
|
end
|
340
370
|
|
@@ -365,10 +395,12 @@ describe PusherFake::Server::Application, ".users, for an occupied channel" do
|
|
365
395
|
end
|
366
396
|
|
367
397
|
it "returns a hash with the occupied status" do
|
368
|
-
subject.users(name)
|
398
|
+
hash = subject.users(name)
|
399
|
+
|
400
|
+
expect(hash).to eq({ users: [
|
369
401
|
{ id: user_1.object_id },
|
370
402
|
{ id: user_2.object_id }
|
371
|
-
] }
|
403
|
+
] })
|
372
404
|
end
|
373
405
|
end
|
374
406
|
|
@@ -384,7 +416,9 @@ describe PusherFake::Server::Application, ".users, for an empty channel" do
|
|
384
416
|
end
|
385
417
|
|
386
418
|
it "returns a hash with the occupied status" do
|
387
|
-
subject.users(name)
|
419
|
+
hash = subject.users(name)
|
420
|
+
|
421
|
+
expect(hash).to eq({ users: [] })
|
388
422
|
end
|
389
423
|
end
|
390
424
|
|
@@ -398,6 +432,8 @@ describe PusherFake::Server::Application, ".users, for an unknown channel" do
|
|
398
432
|
end
|
399
433
|
|
400
434
|
it "returns a hash with the occupied status" do
|
401
|
-
subject.users("fake")
|
435
|
+
hash = subject.users("fake")
|
436
|
+
|
437
|
+
expect(hash).to eq({ users: [] })
|
402
438
|
end
|
403
439
|
end
|
@@ -10,27 +10,32 @@ describe PusherFake::Server, ".start" do
|
|
10
10
|
|
11
11
|
it "runs the event loop" do
|
12
12
|
subject.start
|
13
|
-
|
13
|
+
|
14
|
+
expect(EventMachine).to have_received(:run).with()
|
14
15
|
end
|
15
16
|
|
16
17
|
it "starts the socket web server when run yields" do
|
17
18
|
subject.start
|
18
|
-
|
19
|
+
|
20
|
+
expect(subject).to have_received(:start_web_server).never
|
19
21
|
|
20
22
|
EventMachine.stubs(:run).yields
|
21
23
|
|
22
24
|
subject.start
|
23
|
-
|
25
|
+
|
26
|
+
expect(subject).to have_received(:start_web_server).with()
|
24
27
|
end
|
25
28
|
|
26
29
|
it "starts the socket server when run yields" do
|
27
30
|
subject.start
|
28
|
-
|
31
|
+
|
32
|
+
expect(subject).to have_received(:start_socket_server).never
|
29
33
|
|
30
34
|
EventMachine.stubs(:run).yields
|
31
35
|
|
32
36
|
subject.start
|
33
|
-
|
37
|
+
|
38
|
+
expect(subject).to have_received(:start_socket_server).with()
|
34
39
|
end
|
35
40
|
end
|
36
41
|
|
@@ -52,76 +57,90 @@ describe PusherFake::Server, ".start_socket_server" do
|
|
52
57
|
|
53
58
|
it "creates a WebSocket server" do
|
54
59
|
subject.start_socket_server
|
55
|
-
|
60
|
+
|
61
|
+
expect(EventMachine::WebSocket).to have_received(:start).with(options)
|
56
62
|
end
|
57
63
|
|
58
64
|
it "defines an open callback on the socket" do
|
59
65
|
subject.start_socket_server
|
60
|
-
|
66
|
+
|
67
|
+
expect(socket).to have_received(:onopen).with()
|
61
68
|
end
|
62
69
|
|
63
70
|
it "creates a connection with the provided socket when onopen yields" do
|
64
71
|
subject.start_socket_server
|
65
|
-
|
72
|
+
|
73
|
+
expect(PusherFake::Connection).to have_received(:new).never
|
66
74
|
|
67
75
|
socket.stubs(:onopen).yields
|
68
76
|
|
69
77
|
subject.start_socket_server
|
70
|
-
|
78
|
+
|
79
|
+
expect(PusherFake::Connection).to have_received(:new).with(socket)
|
71
80
|
end
|
72
81
|
|
73
82
|
it "establishes the connection when onopen yields" do
|
74
83
|
subject.start_socket_server
|
75
|
-
|
84
|
+
|
85
|
+
expect(connection).to have_received(:establish).never
|
76
86
|
|
77
87
|
socket.stubs(:onopen).yields
|
78
88
|
|
79
89
|
subject.start_socket_server
|
80
|
-
|
90
|
+
|
91
|
+
expect(connection).to have_received(:establish).with()
|
81
92
|
end
|
82
93
|
|
83
94
|
it "defines a message callback on the socket when onopen yields" do
|
84
95
|
subject.start_socket_server
|
85
|
-
|
96
|
+
|
97
|
+
expect(socket).to have_received(:onmessage).never
|
86
98
|
|
87
99
|
socket.stubs(:onopen).yields
|
88
100
|
|
89
101
|
subject.start_socket_server
|
90
|
-
|
102
|
+
|
103
|
+
expect(socket).to have_received(:onmessage).with()
|
91
104
|
end
|
92
105
|
|
93
106
|
it "triggers process on the connection when onmessage yields" do
|
94
107
|
socket.stubs(:onopen).yields
|
95
108
|
|
96
109
|
subject.start_socket_server
|
97
|
-
|
110
|
+
|
111
|
+
expect(connection).to have_received(:process).never
|
98
112
|
|
99
113
|
socket.stubs(:onmessage).yields(data)
|
100
114
|
|
101
115
|
subject.start_socket_server
|
102
|
-
|
116
|
+
|
117
|
+
expect(connection).to have_received(:process).with(data)
|
103
118
|
end
|
104
119
|
|
105
120
|
it "defines a close callback on the socket when onopen yields" do
|
106
121
|
subject.start_socket_server
|
107
|
-
|
122
|
+
|
123
|
+
expect(socket).to have_received(:onclose).never
|
108
124
|
|
109
125
|
socket.stubs(:onopen).yields
|
110
126
|
|
111
127
|
subject.start_socket_server
|
112
|
-
|
128
|
+
|
129
|
+
expect(socket).to have_received(:onclose).with()
|
113
130
|
end
|
114
131
|
|
115
132
|
it "removes the connection from all channels when onclose yields" do
|
116
133
|
socket.stubs(:onopen).yields
|
117
134
|
|
118
135
|
subject.start_socket_server
|
119
|
-
|
136
|
+
|
137
|
+
expect(PusherFake::Channel).to have_received(:remove).never
|
120
138
|
|
121
139
|
socket.stubs(:onclose).yields
|
122
140
|
|
123
141
|
subject.start_socket_server
|
124
|
-
|
142
|
+
|
143
|
+
expect(PusherFake::Channel).to have_received(:remove).with(connection)
|
125
144
|
end
|
126
145
|
end
|
127
146
|
|
@@ -141,21 +160,25 @@ describe PusherFake::Server, ".start_web_server" do
|
|
141
160
|
|
142
161
|
it "silences the logging" do
|
143
162
|
subject.start_web_server
|
144
|
-
|
163
|
+
|
164
|
+
expect(Thin::Logging).to have_received(:silent=).with(true)
|
145
165
|
end
|
146
166
|
|
147
167
|
it "creates the web server" do
|
148
168
|
subject.start_web_server
|
149
|
-
|
169
|
+
|
170
|
+
expect(Thin::Server).to have_received(:new).with(host, port, PusherFake::Server::Application)
|
150
171
|
end
|
151
172
|
|
152
173
|
it "assigns custom options to the server" do
|
153
174
|
subject.start_web_server
|
154
|
-
|
175
|
+
|
176
|
+
expect(server).to have_received(:ssl=).with(true)
|
155
177
|
end
|
156
178
|
|
157
179
|
it "starts the web server" do
|
158
180
|
subject.start_web_server
|
159
|
-
|
181
|
+
|
182
|
+
expect(server).to have_received(:start!).with()
|
160
183
|
end
|
161
184
|
end
|
@@ -19,17 +19,21 @@ describe PusherFake::Webhook, ".trigger" do
|
|
19
19
|
|
20
20
|
it "generates a signature" do
|
21
21
|
subject.trigger(name, data)
|
22
|
-
|
22
|
+
|
23
|
+
expect(OpenSSL::HMAC).to have_received(:hexdigest)
|
24
|
+
.with(kind_of(OpenSSL::Digest::SHA256), configuration.secret, payload)
|
23
25
|
end
|
24
26
|
|
25
27
|
it "creates a HTTP request for each webhook URL" do
|
26
28
|
subject.trigger(name, data)
|
27
|
-
|
29
|
+
|
30
|
+
expect(EventMachine::HttpRequest).to have_received(:new).with(webhooks.first)
|
28
31
|
end
|
29
32
|
|
30
33
|
it "posts the payload to the webhook URL" do
|
31
34
|
subject.trigger(name, data)
|
32
|
-
|
35
|
+
|
36
|
+
expect(http).to have_received(:post).with(
|
33
37
|
body: payload,
|
34
38
|
head: {
|
35
39
|
"Content-Type" => "application/json",
|