Skip to content

Commit

Permalink
Merge pull request #17 from checkout/update/fake-network-client
Browse files Browse the repository at this point in the history
Update request to handle error cases
  • Loading branch information
aashna-narula-cko authored Mar 18, 2024
2 parents e1be5da + faa3140 commit bb96091
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ final public class CheckoutNetworkFakeClient: CheckoutClientInterface {

public var calledAsyncRequests: [RequestConfiguration] = []
public var dataToBeReturned: Decodable!
public var errorToBeThrown: CheckoutNetworkError?

public func runRequest<T: Decodable>(with configuration: RequestConfiguration,
completionHandler: @escaping CompletionHandler<T>) {
Expand All @@ -29,13 +30,19 @@ extension CheckoutNetworkFakeClient {
public func runRequest<T: Decodable>(with configuration: CheckoutNetwork.RequestConfiguration) async throws -> T {
calledAsyncRequests.append(configuration)
// swiftlint:disable force_cast
return dataToBeReturned as! T
guard let error = errorToBeThrown else {
return dataToBeReturned as! T
}
throw error
// swiftlint:enable force_cast
}

public func runRequest(with configuration: RequestConfiguration) async throws {
calledAsyncRequests.append(configuration)
try await Task.sleep(nanoseconds: 1 * 1_000_000_000) // 1 second
return ()
guard let error = errorToBeThrown else {
return ()
}
throw error
}
}

0 comments on commit bb96091

Please sign in to comment.