Last active
November 13, 2020 23:58
-
-
Save FranDepascuali/56f062415c75aef37f417721af9465ae to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Just playing with this pointfreeco sample | |
// https://github.com/pointfreeco/episode-code-samples/blob/main/0114-designing-dependencies-pt5/DesigningDependencies/WeatherClient/Sources/WeatherClient/Mocks.swift | |
extension WeatherClient { | |
static func faked( | |
response: Result<[WeatherResponse.ConsolidatedWeather], Error>, | |
locations: Result<[Location], Error>) -> WeatherClient { | |
return Self( | |
weather: { _ in | |
return response | |
.publisher | |
.map { WeatherResponse(consolidatedWeather: $0) } | |
.eraseToAnyPublisher() | |
}, | |
searchLocations: { _ in | |
locations.publisher.eraseToAnyPublisher() | |
} | |
) | |
} | |
static let empty = WeatherClient.faked( | |
response: .success([]), | |
locations: .success([]) | |
) | |
static let happyPath = WeatherClient.faked( | |
response: .success([ | |
.init(applicableDate: Date(), id: 1, maxTemp: 30, minTemp: 10, theTemp: 20), | |
.init(applicableDate: Date().addingTimeInterval(86400), id: 2, maxTemp: -10, minTemp: -30, theTemp: -20) | |
]), | |
locations: .success([ | |
Location(title: "New York", woeid: 1) | |
]) | |
) | |
static let failed = WeatherClient.faked( | |
response: .failure(NSError(domain: "", code: 1)), | |
locations: .success([]) | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment