Skip to content

Commit 853567f

Browse files
committed
Add tests for setting host and port
1 parent 6c81892 commit 853567f

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

Source/PusherSwift.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,15 @@ public struct PusherClientOptions {
101101
}
102102

103103
let defaults: [String:AnyObject?] = [
104-
"host": "ws.pusherapp.com",
105104
"encrypted": true,
106105
"attemptToReturnJSONObject": true,
107106
"authEndpoint": nil,
108107
"secret": nil,
109108
"userDataFetcher": nil,
110109
"autoReconnect": true,
111-
"authRequestCustomizer": nil
110+
"authRequestCustomizer": nil,
111+
"host": "ws.pusherapp.com",
112+
"port": nil
112113
]
113114

114115
var optionsMergedWithDefaults: [String:Any] = [:]

Tests/PusherSwiftTests.swift

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class MockWebSocket: WebSocket {
4040
}
4141
)
4242
}
43-
43+
4444
override public func disconnect(forceTimeout: Int = 0) {
4545
stubber.stub(
4646
"disconnect",
@@ -223,7 +223,7 @@ class PusherClientInitializationSpec: QuickSpec {
223223

224224
context("with default config") {
225225
it("has the correct conection url") {
226-
expect(pusher.connection.url).to(equal("wss://ws.pusherapp.com:443/app/testKey123?client=pusher-swift&version=0.1.4&protocol=7"))
226+
expect(pusher.connection.url).to(equal("wss://ws.pusherapp.com:443/app/testKey123?client=pusher-websocket-swift&version=0.1.4&protocol=7"))
227227
}
228228

229229
it("has auth endpoint as nil") {
@@ -245,17 +245,25 @@ class PusherClientInitializationSpec: QuickSpec {
245245
it("has auth method of none") {
246246
expect(pusher.connection.options.authMethod).to(equal(AuthMethod.NoMethod))
247247
}
248-
248+
249249
it("has authRequestCustomizer as nil") {
250250
expect(pusher.connection.options.authRequestCustomizer).to(beNil())
251251
}
252+
253+
it("has the host set correctly") {
254+
expect(pusher.connection.options.host).to(equal("ws.pusherapp.com"))
255+
}
256+
257+
it("has the port set as nil") {
258+
expect(pusher.connection.options.port).to(beNil())
259+
}
252260
}
253261

254262
context("passing in configuration options") {
255263
context("unencrypted") {
256264
it("has the correct conection url") {
257265
pusher = Pusher(key: key, options: ["encrypted": false])
258-
expect(pusher.connection.url).to(equal("ws://ws.pusherapp.com:80/app/testKey123?client=pusher-swift&version=0.1.4&protocol=7"))
266+
expect(pusher.connection.url).to(equal("ws://ws.pusherapp.com:80/app/testKey123?client=pusher-websocket-swift&version=0.1.4&protocol=7"))
259267
}
260268
}
261269

@@ -289,7 +297,7 @@ class PusherClientInitializationSpec: QuickSpec {
289297
expect(pusher.connection.options.attemptToReturnJSONObject).to(beFalsy())
290298
}
291299
}
292-
300+
293301
context("an authRequestCustomizer") {
294302
it("has one set") {
295303
func customizer(request: NSMutableURLRequest) -> NSMutableURLRequest {
@@ -299,6 +307,20 @@ class PusherClientInitializationSpec: QuickSpec {
299307
expect(pusher.connection.options.authRequestCustomizer).toNot(beNil())
300308
}
301309
}
310+
311+
context("a host") {
312+
it("has one set") {
313+
pusher = Pusher(key: key, options: ["host": "test.test.test"])
314+
expect(pusher.connection.options.host).to(equal("test.test.test"))
315+
}
316+
}
317+
318+
context("a port") {
319+
it("sets the URL with it") {
320+
pusher = Pusher(key: key, options: ["port": 123])
321+
expect(pusher.connection.options.port).to(equal(123))
322+
}
323+
}
302324
}
303325
}
304326
}
@@ -682,7 +704,7 @@ class MockSession: NSURLSession {
682704
override class func sharedSession() -> NSURLSession {
683705
return MockSession()
684706
}
685-
707+
686708
override func dataTaskWithRequest(request: NSURLRequest, completionHandler: (NSData?, NSURLResponse?, NSError?) -> Void) -> NSURLSessionDataTask {
687709
self.completionHandler = completionHandler
688710
return MockTask(response: MockSession.mockResponse, completionHandler: completionHandler)

0 commit comments

Comments
 (0)