refactor didError
This commit is contained in:
parent
dbc8b6fadc
commit
15cfba46bc
@ -100,6 +100,18 @@ class SocketSideEffectTest: XCTestCase {
|
|||||||
XCTAssertEqual(socket.testHandlers.count, 1)
|
XCTAssertEqual(socket.testHandlers.count, 1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func testHandlesErrorPacket() {
|
||||||
|
let expectation = expectationWithDescription("Handled error")
|
||||||
|
socket.on("error") {data, ack in
|
||||||
|
if let error = data[0] as? String where error == "test error" {
|
||||||
|
expectation.fulfill()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
socket.parseSocketMessage("4\"test error\"")
|
||||||
|
waitForExpectationsWithTimeout(3, handler: nil)
|
||||||
|
}
|
||||||
|
|
||||||
func testHandleBinaryEvent() {
|
func testHandleBinaryEvent() {
|
||||||
let expectation = expectationWithDescription("handled binary event")
|
let expectation = expectationWithDescription("handled binary event")
|
||||||
socket.on("test") {data, ack in
|
socket.on("test") {data, ack in
|
||||||
|
|||||||
@ -28,17 +28,16 @@ protocol SocketClientSpec: class {
|
|||||||
|
|
||||||
func didConnect()
|
func didConnect()
|
||||||
func didDisconnect(reason: String)
|
func didDisconnect(reason: String)
|
||||||
func didError(reason: AnyObject)
|
func didError(reason: String)
|
||||||
func handleAck(ack: Int, data: [AnyObject])
|
func handleAck(ack: Int, data: [AnyObject])
|
||||||
func handleEvent(event: String, data: [AnyObject], isInternalMessage: Bool, withAck ack: Int)
|
func handleEvent(event: String, data: [AnyObject], isInternalMessage: Bool, withAck ack: Int)
|
||||||
func joinNamespace(namespace: String)
|
func joinNamespace(namespace: String)
|
||||||
}
|
}
|
||||||
|
|
||||||
extension SocketClientSpec {
|
extension SocketClientSpec {
|
||||||
func didError(reason: AnyObject) {
|
func didError(reason: String) {
|
||||||
DefaultSocketLogger.Logger.error("%@", type: "SocketIOClient", args: reason)
|
DefaultSocketLogger.Logger.error("%@", type: "SocketIOClient", args: reason)
|
||||||
|
|
||||||
handleEvent("error", data: reason as? [AnyObject] ?? [reason],
|
handleEvent("error", data: [reason], isInternalMessage: true, withAck: -1)
|
||||||
isInternalMessage: true, withAck: -1)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -58,7 +58,7 @@ extension SocketParsable {
|
|||||||
case .Disconnect:
|
case .Disconnect:
|
||||||
didDisconnect("Got Disconnect")
|
didDisconnect("Got Disconnect")
|
||||||
case .Error:
|
case .Error:
|
||||||
didError(pack.data)
|
handleEvent("error", data: pack.data, isInternalMessage: false, withAck: pack.id)
|
||||||
default:
|
default:
|
||||||
DefaultSocketLogger.Logger.log("Got invalid packet: %@", type: "SocketParser", args: pack.description)
|
DefaultSocketLogger.Logger.log("Got invalid packet: %@", type: "SocketParser", args: pack.description)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user