Skip to content

Commit

Permalink
update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nan-li committed Dec 16, 2024
1 parent 14e1032 commit 8186def
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class MockOneSignalClient: NSObject, IOneSignalClient {
let lock = NSLock()

var mockResponses: [String: [String: Any]] = [:]
var mockFailureResponses: [String: NSError] = [:]
var mockFailureResponses: [String: OneSignalClientError] = [:]
public var lastHTTPRequest: OneSignalRequest?
public var networkRequestCount = 0
public var executedRequests: [OneSignalRequest] = []
Expand Down Expand Up @@ -90,7 +90,7 @@ public class MockOneSignalClient: NSObject, IOneSignalClient {
remoteParamsOutcomes = [:]
}

public func execute(_ request: OneSignalRequest, onSuccess successBlock: @escaping OSResultSuccessBlock, onFailure failureBlock: @escaping OSFailureBlock) {
public func execute(_ request: OneSignalRequest, onSuccess successBlock: @escaping OSResultSuccessBlock, onFailure failureBlock: @escaping OSClientFailureBlock) {
print("🧪 MockOneSignalClient execute called")

if executeInstantaneously {
Expand All @@ -117,7 +117,7 @@ public class MockOneSignalClient: NSObject, IOneSignalClient {
return stringified
}

func finishExecutingRequest(_ request: OneSignalRequest, onSuccess successBlock: OSResultSuccessBlock, onFailure failureBlock: OSFailureBlock) {
func finishExecutingRequest(_ request: OneSignalRequest, onSuccess successBlock: OSResultSuccessBlock, onFailure failureBlock: OSClientFailureBlock) {

// TODO: This entire method needs to contained within the equivalent of @synchronized ❗️
print("🧪 completing HTTP request: \(request)")
Expand All @@ -137,8 +137,8 @@ public class MockOneSignalClient: NSObject, IOneSignalClient {
}
if (mockResponses[stringifiedRequest]) != nil {
successBlock(mockResponses[stringifiedRequest])
} else if (mockFailureResponses[stringifiedRequest]) != nil {
failureBlock(mockFailureResponses[stringifiedRequest])
} else if let response = mockFailureResponses[stringifiedRequest] {
failureBlock(response)
} else if fireSuccessForAllRequests {
allRequestsHandled = false
successBlock([:])
Expand Down Expand Up @@ -166,7 +166,7 @@ public class MockOneSignalClient: NSObject, IOneSignalClient {
mockResponses[request] = response
}

public func setMockFailureResponseForRequest(request: String, error: NSError) {
public func setMockFailureResponseForRequest(request: String, error: OneSignalClientError) {
mockFailureResponses[request] = error
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ final class OSLiveActivitiesExecutorTests: XCTestCase {
mockClient.reset()

let request = OSRequestSetStartToken(key: "my-activity-type", token: "my-token")
mockClient.setMockFailureResponseForRequest(request: String(describing: request), error: NSError(domain: "not-important", code: 500))
mockClient.setMockFailureResponseForRequest(request: String(describing: request), error: OneSignalClientError(code: 500, message: "not-important", responseHeaders: nil, response: nil, underlyingError: nil))

/* When */
let executor = OSLiveActivitiesExecutor(requestDispatch: mockDispatchQueue)
Expand All @@ -210,7 +210,7 @@ final class OSLiveActivitiesExecutorTests: XCTestCase {
mockClient.reset()

let request = OSRequestSetStartToken(key: "my-activity-type", token: "my-token")
mockClient.setMockFailureResponseForRequest(request: String(describing: request), error: NSError(domain: "not-important", code: 401))
mockClient.setMockFailureResponseForRequest(request: String(describing: request), error: OneSignalClientError(code: 401, message: "not-important", responseHeaders: nil, response: nil, underlyingError: nil))

/* When */
let executor = OSLiveActivitiesExecutor(requestDispatch: mockDispatchQueue)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ extension MockUserRequests {
fetchResponse = MockUserRequests.testIdentityPayload(onesignalId: osid, externalId: externalId)
client.setMockFailureResponseForRequest(
request: "<OSRequestIdentifyUser with external_id: \(externalId)>",
error: NSError(domain: "not-important", code: 409)
error: OneSignalClientError(code: 409, message: "not-important", responseHeaders: nil, response: nil, underlyingError: nil)
)
// 2. Set the response for the subsequent Create User request
let userResponse = MockUserRequests.testIdentityPayload(onesignalId: osid, externalId: externalId)
Expand Down

0 comments on commit 8186def

Please sign in to comment.