Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trupin/9e304958670581c4064129bc4302654d to your computer and use it in GitHub Desktop.
Save trupin/9e304958670581c4064129bc4302654d to your computer and use it in GitHub Desktop.
final class KeyValueStoreSpy: KeyValueStoring {
// MARK: - Records
private(set) var keyRecords = [String]()
private(set) var valueRecords = [StoreValueRepresentable]()
// MARK: - Stubs
var getEntryResultStub: [String: Result<Any?, MovieStoreError>]()
// MARK: - Implementation
func getValue<Value: StoreValueRepresentable>(for key: String, completion: @escaping (Result<Value?, StoreError>) -> Void) {
keyRecords.append(key)
completion(completionResultStub)
}
func set(value: StoreValueRepresentable, for key: String) {
valueRecords.append(value)
keyRecords.append(key)
}
}
final class ClientSpy: ClientProtocol {
// MARK: - Records
private(set) var pathRecords = [String]()
// MARK: - Stubs
var getResultStub = [String: Result<Any, ClientError>]()
// MARK: - Implementation
func get<Model: Decodable>(path: String, completion: @escaping (Result<Model, ClientError>) -> Void) {
pathRecords.append(path)
let result = getResultStub[path] as! Result<Model, ClientError>
completion(result)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment