-
Notifications
You must be signed in to change notification settings - Fork 370
/
handshake_spec.rb
139 lines (120 loc) · 4.6 KB
/
handshake_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
require "spec_helper"
describe "server handshake" do
let(:engine) { mock "engine" }
let(:server) { Faye::Server.new }
before do
Faye::Engine.stub(:get).and_return engine
end
describe :handshake do
let(:message) {{"channel" => "/meta/handshake",
"version" => "1.0",
"supportedConnectionTypes" => ["long-polling"]
}}
describe "with valid parameters" do
it "creates a client" do
engine.should_receive(:create_client)
server.handshake(message) {}
end
it "returns a successful response" do
engine.stub(:create_client).and_yield "clientid"
server.handshake(message) do |response|
response.should == {
"channel" => "/meta/handshake",
"successful" => true,
"version" => "1.0",
"supportedConnectionTypes" => ["long-polling","cross-origin-long-polling","callback-polling","websocket","in-process"],
"clientId" => "clientid"
}
end
end
describe "with a message id" do
before { message["id"] = "foo" }
it "returns the same id" do
engine.stub(:create_client).and_yield "clientid"
server.handshake(message) do |response|
response.should == {
"channel" => "/meta/handshake",
"successful" => true,
"version" => "1.0",
"supportedConnectionTypes" => ["long-polling","cross-origin-long-polling","callback-polling","websocket","in-process"],
"clientId" => "clientid",
"id" => "foo"
}
end
end
end
end
describe "missing version" do
before { message.delete "version" }
it "does not create a client" do
engine.should_not_receive(:create_client)
server.handshake(message) {}
end
it "returns an unsuccessful response" do
server.handshake(message) do |response|
response.should == {
"channel" => "/meta/handshake",
"successful" => false,
"error" => "402:version:Missing required parameter",
"version" => "1.0",
"supportedConnectionTypes" => ["long-polling","cross-origin-long-polling","callback-polling","websocket","in-process"]
}
end
end
end
describe "missing supportedConnectionTypes" do
before { message.delete "supportedConnectionTypes" }
it "does not create a client" do
engine.should_not_receive(:create_client)
server.handshake(message) {}
end
it "returns an unsuccessful response" do
server.handshake(message) do |response|
response.should == {
"channel" => "/meta/handshake",
"successful" => false,
"error" => "402:supportedConnectionTypes:Missing required parameter",
"version" => "1.0",
"supportedConnectionTypes" => ["long-polling","cross-origin-long-polling","callback-polling","websocket","in-process"]
}
end
end
end
describe "with no matching supportedConnectionTypes" do
before { message["supportedConnectionTypes"] = ["iframe", "flash"] }
it "does not create a client" do
engine.should_not_receive(:create_client)
server.handshake(message) {}
end
it "returns an unsuccessful response" do
server.handshake(message) do |response|
response.should == {
"channel" => "/meta/handshake",
"successful" => false,
"error" => "301:iframe,flash:Connection types not supported",
"version" => "1.0",
"supportedConnectionTypes" => ["long-polling","cross-origin-long-polling","callback-polling","websocket","in-process"]
}
end
end
end
describe "with an error" do
before { message["error"] = "invalid" }
it "does not createa a client" do
engine.should_not_receive(:create_client)
server.handshake(message) {}
end
it "returns an unsuccessful response" do
server.handshake(message) do |response|
response.should == {
"channel" => "/meta/handshake",
"successful" => false,
"error" => "invalid",
"version" => "1.0",
"supportedConnectionTypes" => ["long-polling","cross-origin-long-polling","callback-polling","websocket","in-process"]
}
end
end
end
end
end