@@ -19,6 +19,8 @@ class AuthenticationTests: XCTestCase {
19
19
private var pusher : Pusher !
20
20
private var socket : MockWebSocket !
21
21
22
+ private let authJSONData = " { \" \( Constants . JSONKeys. auth) \" : \" testKey123:12345678gfder78ikjbg \" } " . data ( using: . utf8) !
23
+
22
24
override func setUp( ) {
23
25
super. setUp ( )
24
26
@@ -42,9 +44,8 @@ class AuthenticationTests: XCTestCase {
42
44
pusher. delegate = dummyDelegate
43
45
44
46
if case . endpoint( authEndpoint: let authEndpoint) = pusher. connection. options. authMethod {
45
- let jsonData = " { \" auth \" : \" testKey123:12345678gfder78ikjbg \" } " . data ( using: String . Encoding. utf8, allowLossyConversion: false ) !
46
47
let urlResponse = HTTPURLResponse ( url: URL ( string: " \( authEndpoint) ?channel_name=private-test-channel&socket_id=45481.3166671 " ) !, statusCode: 200 , httpVersion: nil , headerFields: nil )
47
- MockSession . mockResponse = ( jsonData , urlResponse: urlResponse, error: nil )
48
+ MockSession . mockResponse = ( authJSONData , urlResponse: urlResponse, error: nil )
48
49
pusher. connection. URLSession = MockSession . shared
49
50
}
50
51
@@ -65,9 +66,8 @@ class AuthenticationTests: XCTestCase {
65
66
pusher. delegate = dummyDelegate
66
67
67
68
if case . endpoint( authEndpoint: let authEndpoint) = pusher. connection. options. authMethod {
68
- let jsonData = " { \" auth \" : \" testKey123:12345678gfder78ikjbg \" } " . data ( using: String . Encoding. utf8, allowLossyConversion: false ) !
69
69
let urlResponse = HTTPURLResponse ( url: URL ( string: " \( authEndpoint) ?channel_name=private-reservations-for-venue%40venue_id%3D399ccd2d-3f4a-43c9-803c-9e4b6bdf0f16%3Bdate%3D2017-01-13&socket_id=45481.3166671 " ) !, statusCode: 200 , httpVersion: nil , headerFields: nil )
70
- MockSession . mockResponse = ( jsonData , urlResponse: urlResponse, error: nil )
70
+ MockSession . mockResponse = ( authJSONData , urlResponse: urlResponse, error: nil )
71
71
pusher. connection. URLSession = MockSession . shared
72
72
}
73
73
@@ -91,7 +91,7 @@ class AuthenticationTests: XCTestCase {
91
91
XCTAssertFalse ( chan. subscribed, " the channel should not be subscribed " )
92
92
93
93
let ex = expectation ( description: " subscription succeed " )
94
- chan. bind ( eventName: " pusher:subscription_succeeded " ) { ( _: PusherEvent ) in
94
+ chan. bind ( eventName: Constants . Events . Pusher . subscriptionSucceeded ) { ( _: PusherEvent ) in
95
95
ex. fulfill ( )
96
96
XCTAssertTrue ( chan. subscribed, " the channel should be subscribed " )
97
97
}
@@ -126,7 +126,7 @@ class AuthenticationTests: XCTestCase {
126
126
XCTAssertFalse ( chan. subscribed, " the channel should not be subscribed " )
127
127
128
128
pusher. bind { event in
129
- XCTAssertEqual ( event. eventName, " pusher:subscription_error " )
129
+ XCTAssertEqual ( event. eventName, Constants . Events . Pusher . subscriptionError )
130
130
XCTAssertEqual ( event. channelName, " private-test-channel " )
131
131
XCTAssertTrue ( Thread . isMainThread)
132
132
ex. fulfill ( )
@@ -143,7 +143,7 @@ class AuthenticationTests: XCTestCase {
143
143
func requestFor( socketID: String , channelName: String ) -> URLRequest ? {
144
144
var request = URLRequest ( url: URL ( string: " http://localhost:9292/builder " ) !)
145
145
request. httpMethod = " POST "
146
- request. httpBody = " socket_id= \( socketID) &channel_name= \( channelName) " . data ( using: String . Encoding . utf8)
146
+ request. httpBody = " socket_id= \( socketID) &channel_name= \( channelName) " . data ( using: . utf8)
147
147
request. addValue ( " myToken " , forHTTPHeaderField: " Authorization " )
148
148
return request
149
149
}
@@ -165,9 +165,8 @@ class AuthenticationTests: XCTestCase {
165
165
socket. delegate = pusher. connection
166
166
pusher. connection. socket = socket
167
167
168
- let jsonData = " { \" auth \" : \" testKey123:12345678gfder78ikjbg \" } " . data ( using: String . Encoding. utf8, allowLossyConversion: false ) !
169
168
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 )
170
- MockSession . mockResponse = ( jsonData , urlResponse: urlResponse, error: nil )
169
+ MockSession . mockResponse = ( authJSONData , urlResponse: urlResponse, error: nil )
171
170
pusher. connection. URLSession = MockSession . shared
172
171
173
172
let chan = pusher. subscribe ( " private-test-channel " )
@@ -206,7 +205,7 @@ class AuthenticationTests: XCTestCase {
206
205
channelName,
207
206
auth: PusherAuth (
208
207
auth: " testKey123:12345678gfder78ikjbgmanualauth " ,
209
- channelData: " { \" user_id \ ":16, \" user_info \" :{ \" time \" : \" 2017-02-20 14:54:36 +0000 \" }} "
208
+ channelData: " { \" \( Constants . JSONKeys . userId ) \ ":16, \" \( Constants . JSONKeys . userInfo ) \" :{ \" time \" : \" 2017-02-20 14:54:36 +0000 \" }} "
210
209
)
211
210
)
212
211
XCTAssertFalse ( chan. subscribed, " the channel should not be subscribed " )
@@ -252,7 +251,7 @@ class AuthenticationTests: XCTestCase {
252
251
func fetchAuthValue( socketID: String , channelName: String , completionHandler: @escaping ( PusherAuth ? ) -> Void ) {
253
252
completionHandler ( PusherAuth (
254
253
auth: " testKey123:authorizerblah1234 " ,
255
- channelData: " { \" user_id \ ": \" 777 \" , \" user_info \" :{ \" twitter \" : \" hamchapman \" }} "
254
+ channelData: " { \" \( Constants . JSONKeys . userId ) \ ": \" 777 \" , \" \( Constants . JSONKeys . userInfo ) \" :{ \" twitter \" : \" hamchapman \" }} "
256
255
) )
257
256
}
258
257
}
0 commit comments