Skip to content

Commit 52ff3d8

Browse files
committed
Update tests for requestFor (AuthRequestBuilderProtocol) changes
1 parent e3fff80 commit 52ff3d8

File tree

1 file changed

+41
-2
lines changed

1 file changed

+41
-2
lines changed

Tests/AuthenticationTests.swift

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,51 @@ class AuthenticationTests: XCTestCase {
108108
waitForExpectations(timeout: 0.5)
109109
}
110110

111-
func testAuthorizationUsingSomethingConformingToTheAuthRequestBuilderProtocol() {
111+
func testAuthorizationUsingSomethingConformingToTheDeprecatedAuthRequestBuilderProtocol() {
112112

113113
class AuthRequestBuilder: AuthRequestBuilderProtocol {
114-
func requestFor(socketID: String, channel: PusherChannel) -> URLRequest? {
114+
func requestFor(socketID: String, channelName: String) -> URLRequest? {
115115
var request = URLRequest(url: URL(string: "http://localhost:9292/builder")!)
116116
request.httpMethod = "POST"
117+
request.httpBody = "socket_id=\(socketID)&channel_name=\(channelName)".data(using: String.Encoding.utf8)
118+
request.addValue("myToken", forHTTPHeaderField: "Authorization")
119+
return request
120+
}
121+
}
122+
123+
let ex = expectation(description: "the channel should be subscribed to successfully")
124+
let channelName = "private-test-channel"
125+
126+
let dummyDelegate = DummyDelegate()
127+
dummyDelegate.ex = ex
128+
dummyDelegate.testingChannelName = channelName
129+
130+
let options = PusherClientOptions(
131+
authMethod: AuthMethod.authRequestBuilder(authRequestBuilder: AuthRequestBuilder())
132+
)
133+
pusher = Pusher(key: "testKey123", options: options)
134+
pusher.delegate = dummyDelegate
135+
socket.delegate = pusher.connection
136+
pusher.connection.socket = socket
137+
138+
let jsonData = "{\"auth\":\"testKey123:12345678gfder78ikjbg\"}".data(using: String.Encoding.utf8, allowLossyConversion: false)!
139+
let urlResponse = HTTPURLResponse(url: URL(string: "http://localhost:9292/builder?channel_name=private-test-channel&socket_id=45481.3166671")!, statusCode: 200, httpVersion: nil, headerFields: nil)
140+
MockSession.mockResponse = (jsonData, urlResponse: urlResponse, error: nil)
141+
pusher.connection.URLSession = MockSession.shared
142+
143+
let chan = pusher.subscribe("private-test-channel")
144+
XCTAssertFalse(chan.subscribed, "the channel should not be subscribed")
145+
pusher.connect()
146+
147+
waitForExpectations(timeout: 0.5)
148+
}
149+
150+
func testAuthorizationUsingSomethingConformingToTheAuthRequestBuilderProtocol() {
151+
152+
class AuthRequestBuilder: AuthRequestBuilderProtocol {
153+
func requestFor(socketID: String, channel: PusherChannel) -> NSMutableURLRequest? {
154+
let request = NSMutableURLRequest(url: URL(string: "http://localhost:9292/builder")!)
155+
request.httpMethod = "POST"
117156
request.httpBody = "socket_id=\(socketID)&channel_name=\(channel.name)".data(using: String.Encoding.utf8)
118157
request.addValue("myToken", forHTTPHeaderField: "Authorization")
119158
return request

0 commit comments

Comments
 (0)