-
Notifications
You must be signed in to change notification settings - Fork 370
/
handshake_spec.js
141 lines (124 loc) · 5.36 KB
/
handshake_spec.js
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
140
141
JS.ENV.Server.HandshakeSpec = JS.Test.describe("Server handshake", function() { with(this) {
before(function() { with(this) {
this.engine = {}
stub(Faye.Engine, "get").returns(engine)
this.server = new Faye.Server()
}})
describe("#handshake", function() { with(this) {
before(function() { with(this) {
this.message = {channel: "/meta/handshake",
version: "1.0",
supportedConnectionTypes: ["long-polling"]}
}})
describe("with valid parameters", function() { with(this) {
it("creates a client", function() { with(this) {
expect(engine, "createClient")
server.handshake(message, false, function() {})
}})
it("returns a successful response", function() { with(this) {
stub(engine, "createClient").yields(["clientid"])
server.handshake(message, false, function(response) {
assertEqual({
channel: "/meta/handshake",
successful: true,
version: "1.0",
supportedConnectionTypes: ["long-polling", "cross-origin-long-polling", "callback-polling", "websocket","in-process"],
clientId: "clientid"
}, response)
})
}})
describe("with a message id", function() { with(this) {
before(function() { this.message.id = "foo" })
it("returns the same id", function() { with(this) {
stub(engine, "createClient").yields(["clientid"])
server.handshake(message, false, function(response) {
assertEqual({
channel: "/meta/handshake",
successful: true,
version: "1.0",
supportedConnectionTypes: ["long-polling", "cross-origin-long-polling", "callback-polling", "websocket","in-process"],
clientId: "clientid",
id: "foo"
}, response)
})
}})
}})
}})
describe("missing version", function() { with(this) {
before(function() { delete this.message.version })
it("does not create a client", function() { with(this) {
expect(engine, "createClient").exactly(0)
server.handshake(message, false, function() {})
}})
it("returns an unsuccessful response", function() { with(this) {
server.handshake(message, false, function(response) {
assertEqual({
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"]
}, response)
})
}})
}})
describe("missing supportedConnectionTypes", function() { with(this) {
before(function() { delete this.message.supportedConnectionTypes })
it("does not create a client", function() { with(this) {
expect(engine, "createClient").exactly(0)
server.handshake(message, false, function() {})
}})
it("returns an unsuccessful response", function() { with(this) {
server.handshake(message, false, function(response) {
assertEqual({
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"]
}, response)
})
}})
}})
describe("with no matching supportedConnectionTypes", function() { with(this) {
before(function() { with(this) {
message.supportedConnectionTypes = ["iframe", "flash"]
}})
it("does not create a client", function() { with(this) {
expect(engine, "createClient").exactly(0)
server.handshake(message, false, function() {})
}})
it("returns an unsuccessful response", function() { with(this) {
server.handshake(message, false, function(response) {
assertEqual({
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"]
}, response)
})
}})
}})
describe("with an error", function() { with(this) {
before(function() { with(this) {
message.error = "invalid"
}})
it("does not create a client", function() { with(this) {
expect(engine, "createClient").exactly(0)
server.handshake(message, false, function() {})
}})
it("returns an unsuccessful response", function() { with(this) {
server.handshake(message, false, function(response) {
assertEqual({
channel: "/meta/handshake",
successful: false,
error: "invalid",
version: "1.0",
supportedConnectionTypes: ["long-polling", "cross-origin-long-polling", "callback-polling", "websocket","in-process"]
}, response)
})
}})
}})
}})
}})