Created
July 14, 2020 17:07
-
-
Save stevencurtis/2991c3439bcb0a59ea8f22e48977d4d4 to your computer and use it in GitHub Desktop.
httpmanagermockcombine
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
class HTTPManagerMock <T: URLSessionProtocol>: HTTPManagerProtocol { | |
let session: T | |
required init(session: T) { | |
self.session = session | |
} | |
func post<T>(url: URL, headers: [String : String], data: Data) -> AnyPublisher<T, Error> where T: Decodable { | |
var request = URLRequest( | |
url: URL(string: "www.fakeweb.com")!, | |
cachePolicy: .reloadIgnoringLocalCacheData, | |
timeoutInterval: 2.0) | |
request.httpMethod = "Post" | |
request.allHTTPHeaderFields = headers | |
request.httpBody = data | |
// let session = URLSessionMock() | |
return session.response(for: request) | |
.map { $0.data } | |
.decode(type: T.self, | |
decoder: JSONDecoder()) | |
.eraseToAnyPublisher() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment