Skip to content

Commit

Permalink
Merge pull request #1957 from ably/fix/1946-replace-error-message-wit…
Browse files Browse the repository at this point in the history
…h-code

[ECO-4874] Replaced all occurences of checking error message
  • Loading branch information
maratal authored Aug 15, 2024
2 parents 8f2af01 + b98ce6e commit 85326a6
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 37 deletions.
25 changes: 9 additions & 16 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 Expand Up @@ -2423,10 +2420,10 @@ class AuthTests: XCTestCase {
waitUntil(timeout: testTimeout) { done in
rest.auth.createTokenRequest(tokenParams, options: nil, callback: { tokenRequest, error in
defer { done() }
guard let error = error else {
guard let error = error as? NSError else {
XCTFail("Error is nil"); return
}
expect(error.localizedDescription).to(contain("Capability"))
XCTAssertTrue(error.code == 3840) // Capability: The data couldn’t be read because it isn’t in the correct format.
XCTAssertNil(tokenRequest?.capability)
})
}
Expand Down Expand Up @@ -4086,8 +4083,7 @@ class AuthTests: XCTestCase {
guard let reason = stateChange.reason else {
fail("Reason error is nil"); done(); return
}
XCTAssertEqual(reason.code, ARTErrorCode.invalidJwtFormat.intValue)
expect(reason.description).to(satisfyAnyOf(contain("invalid signature"), contain("signature verification failed")))
XCTAssertEqual(reason.code, ARTErrorCode.invalidJwtFormat.intValue) // Error verifying JWT; err = Unexpected exception decoding token; err = signature verification failed. (See https://help.ably.io/error/40144 for help.)
done()
}
client.connect()
Expand Down Expand Up @@ -4137,8 +4133,7 @@ class AuthTests: XCTestCase {
guard let reason = stateChange.reason else {
fail("Reason error is nil"); done(); return
}
XCTAssertEqual(reason.code, ARTErrorCode.invalidJwtFormat.intValue)
expect(reason.description).to(satisfyAnyOf(contain("invalid signature"), contain("signature verification failed")))
XCTAssertEqual(reason.code, ARTErrorCode.invalidJwtFormat.intValue) // Error verifying JWT; err = Unexpected exception decoding token; err = signature verification failed. (See https://help.ably.io/error/40144 for help.)
done()
}
client.connect()
Expand Down Expand Up @@ -4257,8 +4252,7 @@ class AuthTests: XCTestCase {
guard let reason = stateChange.reason else {
fail("Reason error is nil"); done(); return
}
XCTAssertEqual(reason.code, ARTErrorCode.invalidJwtFormat.intValue)
expect(reason.description).to(satisfyAnyOf(contain("invalid signature"), contain("signature verification failed")))
XCTAssertEqual(reason.code, ARTErrorCode.invalidJwtFormat.intValue) // Error verifying JWT; err = Unexpected exception decoding token; err = signature verification failed. (See https://help.ably.io/error/40144 for help.)
done()
}
client.connect()
Expand Down Expand Up @@ -4334,8 +4328,7 @@ class AuthTests: XCTestCase {

waitUntil(timeout: testTimeout) { done in
client.channels.get(channelName).publish(messageName, data: nil, callback: { error in
XCTAssertEqual(error?.code, ARTErrorCode.operationNotPermittedWithProvidedCapability.intValue)
expect(error?.message).to(contain("permission denied"))
XCTAssertEqual(error?.code, ARTErrorCode.operationNotPermittedWithProvidedCapability.intValue) // Unable to perform publish (permission denied)
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
12 changes: 5 additions & 7 deletions Test/Tests/RealtimeClientConnectionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1966,7 +1966,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 @@ -2124,9 +2124,8 @@ class RealtimeClientConnectionTests: XCTestCase {
guard let reason = stateChange.reason else {
fail("Reason is nil"); done(); return
}
XCTAssertEqual(reason.code, ARTErrorCode.tokenExpired.intValue)
XCTAssertEqual(reason.code, ARTErrorCode.tokenExpired.intValue) // Key/token status changed (expire)
XCTAssertEqual(reason.statusCode, 401)
expect(reason.message).to(contain("Key/token status changed (expire)"))
partialDone()
}
client.connect()
Expand Down Expand Up @@ -2342,9 +2341,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 @@ -4134,7 +4132,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
6 changes: 3 additions & 3 deletions 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 Expand Up @@ -741,10 +741,10 @@ class RealtimeClientTests: XCTestCase {
}

client.auth.authorize(nil, options: authOptions) { tokenDetails, error in
guard let error = error else {
guard let error = error as? NSError else {
fail("ErrorInfo is nil"); partialDone(); return
}
expect(error.localizedDescription).to(contain("Invalid accessToken"))
XCTAssertTrue(error.code == ARTErrorCode.invalidCredential.rawValue) // Invalid accessToken in request: xxxxxxxxxxxx
XCTAssertEqual(tokenDetails?.token, invalidToken)
authError = error as NSError?
partialDone()
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 85326a6

Please sign in to comment.