Skip to content

Commit

Permalink
Replaced all occurences of checking error message instead of error co…
Browse files Browse the repository at this point in the history
…de (or removed where the error code check was already presented) except places where error is locally generated (since it doesn't contain proper error code - 0 usually).
  • Loading branch information
maratal committed Aug 11, 2024
1 parent 7fceb3e commit 5a087a7
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 23 deletions.
9 changes: 3 additions & 6 deletions Test/Tests/AuthTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,7 @@ class AuthTests: XCTestCase {
guard let error = error else {
fail("Error is nil"); done(); return
}
XCTAssertEqual(error.code, Int(ARTState.requestTokenFailed.rawValue))
expect(error.message).to(contain("no means to renew the token is provided"))

XCTAssertEqual(error.code, Int(ARTState.requestTokenFailed.rawValue)) // no means to renew the token is provided
XCTAssertEqual(proxyHTTPExecutor.requests.count, 0)
done()
}
Expand Down Expand Up @@ -505,8 +503,7 @@ class AuthTests: XCTestCase {
guard let error = error else {
fail("Error is nil"); done(); return
}
XCTAssertEqual(error.code, Int(ARTState.requestTokenFailed.rawValue))
expect(error.message).to(contain("no means to renew the token is provided"))
XCTAssertEqual(error.code, Int(ARTState.requestTokenFailed.rawValue)) // no means to renew the token is provided
XCTAssertEqual(proxyHTTPExecutor.requests.count, 1)
XCTAssertEqual(proxyHTTPExecutor.responses.count, 1)
guard let response = proxyHTTPExecutor.responses.first else {
Expand Down Expand Up @@ -1914,7 +1911,7 @@ class AuthTests: XCTestCase {
guard let error = error else {
fail("Error is nil"); done(); return
}
expect(error.message).to(contain("invalid clientId"))
XCTAssertTrue(error.code == ARTErrorCode.invalidClientId.rawValue)
done()
}
}
Expand Down
6 changes: 3 additions & 3 deletions Test/Tests/PushAdminTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ class PushAdminTests: XCTestCase {
fail("Error is missing"); done(); return
}
XCTAssertEqual(error.statusCode, 400)
expect(error.message).to(contain("recipient must contain"))
XCTAssertTrue(error.code == ARTErrorCode.badRequest.rawValue) // recipient must contain a 'deviceId', 'clientId', or 'transportType'
done()
}
}
Expand Down Expand Up @@ -368,7 +368,7 @@ class PushAdminTests: XCTestCase {
fail("Error should not be empty"); done(); return
}
XCTAssertEqual(error.statusCode, 404)
expect(error.message).to(contain("not found"))
XCTAssertTrue(error.code == ARTErrorCode.notFound.rawValue)
done()
}
}
Expand Down Expand Up @@ -715,7 +715,7 @@ class PushAdminTests: XCTestCase {
fail("Error is nil"); done(); return
}
XCTAssertEqual(error.statusCode, 400)
expect(error.message).to(contain("device madeup doesn't exist"))
XCTAssertTrue(error.code == ARTErrorCode.badRequest.rawValue) // registration for device madeup doesn't exist
done()
}
}
Expand Down
8 changes: 4 additions & 4 deletions Test/Tests/RealtimeClientChannelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1558,7 +1558,7 @@ class RealtimeClientChannelTests: XCTestCase {
guard let error = error else {
fail("Reason error is nil"); return
}
expect(error.message).to(contain("timed out"))
XCTAssertTrue(error.code == ARTState.detachTimedOut.rawValue)
XCTAssertEqual(channel.state, ARTRealtimeChannelState.attached)
done()
}
Expand Down Expand Up @@ -1948,7 +1948,7 @@ class RealtimeClientChannelTests: XCTestCase {
guard let error = error else {
fail("Error is nil"); return
}
expect(error.message).to(contain("timed out"))
XCTAssertTrue(error.code == ARTState.detachTimedOut.rawValue)
XCTAssertEqual(error, channel.errorReason)
callbackCalled = true
}
Expand Down Expand Up @@ -3959,7 +3959,7 @@ class RealtimeClientChannelTests: XCTestCase {
guard let error = stateChange.reason else {
fail("Reason error is nil"); done(); return
}
expect(error.message).to(contain("timed out"))
XCTAssertTrue(error.code == ARTState.attachTimedOut.rawValue)
XCTAssertTrue(channel.errorReason === error)
done()
}
Expand Down Expand Up @@ -4186,7 +4186,7 @@ class RealtimeClientChannelTests: XCTestCase {
guard let error = stateChange.reason else {
fail("Reason error is nil"); done(); return
}
expect(error.message).to(contain("timed out"))
XCTAssertTrue(error.code == ARTState.attachTimedOut.rawValue)
XCTAssertTrue(channel.errorReason === error)
done()
}
Expand Down
9 changes: 4 additions & 5 deletions Test/Tests/RealtimeClientConnectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1936,7 +1936,7 @@ class RealtimeClientConnectionTests: XCTestCase {
fail("expected error"); done(); return
}
let end = NSDate()
expect(error.message).to(contain("timed out"))
XCTAssertTrue(error.code == ARTErrorCode.connectionTimedOut.rawValue)
expect(end.timeIntervalSince(start as Date)).to(beCloseTo(realtimeRequestTimeout, within: 1.5))
done()
}
Expand Down Expand Up @@ -2312,9 +2312,8 @@ class RealtimeClientConnectionTests: XCTestCase {
options.authCallback = { _, _ in
// Ignore `completion` closure to force a time out
}
},
checkError: { error in
XCTAssertTrue(error.message.contains("timed out"))
}, checkError: { error in
XCTAssertTrue(error.code == ARTErrorCode.authConfiguredProviderFailure.rawValue) // timed out
})
}

Expand Down Expand Up @@ -4104,7 +4103,7 @@ class RealtimeClientConnectionTests: XCTestCase {
guard let error = stateChange.reason else {
fail("Error is nil"); done(); return
}
expect(error.message).to(contain("Invalid key"))
XCTAssertTrue(error.code == ARTErrorCode.invalidCredential.rawValue)
done()
}
}
Expand Down
4 changes: 2 additions & 2 deletions Test/Tests/RealtimeClientPresenceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1922,7 +1922,7 @@ class RealtimeClientPresenceTests: XCTestCase {
guard let error = error else {
fail("error expected"); done(); return
}
expect(error.message).to(contain("Channel denied access based on given capability"))
XCTAssertTrue(error.code == ARTErrorCode.operationNotPermittedWithProvidedCapability.rawValue)
done()
}
}
Expand Down Expand Up @@ -2002,7 +2002,7 @@ class RealtimeClientPresenceTests: XCTestCase {
guard let error = error else {
fail("Error is nil"); done(); return
}
expect(error.message).to(contain("Channel denied access based on given capability"))
XCTAssertTrue(error.code == ARTErrorCode.operationNotPermittedWithProvidedCapability.rawValue)
done()
}
}
Expand Down
2 changes: 1 addition & 1 deletion Test/Tests/RealtimeClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ class RealtimeClientTests: XCTestCase {
guard let error = stateChange.reason else {
fail("Error is nil"); done(); return
}
expect(error.message).to(contain("Channel denied access based on given capability"))
XCTAssertTrue(error.code == ARTErrorCode.operationNotPermittedWithProvidedCapability.rawValue)
done()
}
channel.attach()
Expand Down
2 changes: 0 additions & 2 deletions Test/Tests/RestClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1757,7 +1757,6 @@ class RestClientTests: XCTestCase {
return
}
XCTAssertEqual(error.code, Int(ARTState.requestTokenFailed.rawValue))
expect(error.message).to(contain("no means to renew the token is provided"))
done()
}
}
Expand Down Expand Up @@ -2053,7 +2052,6 @@ class RestClientTests: XCTestCase {
}
XCTAssertEqual(error.statusCode, 401)
XCTAssertEqual(error.code, ARTErrorCode.errorFromClientTokenCallback.intValue)
expect(error.message).to(contain("Error in requesting auth token"))
done()
}
}
Expand Down

0 comments on commit 5a087a7

Please sign in to comment.