Skip to content

Commit bb96091

Browse files
Merge pull request #17 from checkout/update/fake-network-client
Update request to handle error cases
2 parents e1be5da + faa3140 commit bb96091

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

Sources/CheckoutNetworkFakeClient/CheckoutNetworkFakeClient.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ final public class CheckoutNetworkFakeClient: CheckoutClientInterface {
1313

1414
public var calledAsyncRequests: [RequestConfiguration] = []
1515
public var dataToBeReturned: Decodable!
16+
public var errorToBeThrown: CheckoutNetworkError?
1617

1718
public func runRequest<T: Decodable>(with configuration: RequestConfiguration,
1819
completionHandler: @escaping CompletionHandler<T>) {
@@ -29,13 +30,19 @@ extension CheckoutNetworkFakeClient {
2930
public func runRequest<T: Decodable>(with configuration: CheckoutNetwork.RequestConfiguration) async throws -> T {
3031
calledAsyncRequests.append(configuration)
3132
// swiftlint:disable force_cast
32-
return dataToBeReturned as! T
33+
guard let error = errorToBeThrown else {
34+
return dataToBeReturned as! T
35+
}
36+
throw error
3337
// swiftlint:enable force_cast
3438
}
3539

3640
public func runRequest(with configuration: RequestConfiguration) async throws {
3741
calledAsyncRequests.append(configuration)
3842
try await Task.sleep(nanoseconds: 1 * 1_000_000_000) // 1 second
39-
return ()
43+
guard let error = errorToBeThrown else {
44+
return ()
45+
}
46+
throw error
4047
}
4148
}

0 commit comments

Comments
 (0)