Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CheckoutNetworkFakeClient #22

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public struct RequestConfiguration {

/// Request created from the consumers configuration
private(set) public var request: URLRequest
var decodingStrategy: JSONDecoder.KeyDecodingStrategy
private(set) public var decodingStrategy: JSONDecoder.KeyDecodingStrategy

/// Create request configuration with provided parameters. In case of failure will throw a `CheckoutNetworkError`
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ final public class CheckoutNetworkFakeClient: CheckoutClientInterface {
public var calledRequests: [(config: RequestConfiguration, completion: Any)] = []

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

public func runRequest<T: Decodable>(with configuration: RequestConfiguration,
Expand All @@ -31,7 +31,10 @@ extension CheckoutNetworkFakeClient {
calledAsyncRequests.append(configuration)
// swiftlint:disable force_cast
guard let error = errorToBeThrown else {
return dataToBeReturned as! T
let decoder = JSONDecoder()
decoder.keyDecodingStrategy = configuration.decodingStrategy
let decoded = try decoder.decode(T.self, from: dataToBeReturned)
return decoded
}
throw error
// swiftlint:enable force_cast
Expand Down
Loading