Skip to content

Instantly share code, notes, and snippets.

@stevencurtis
Created July 14, 2020 17:07
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 stevencurtis/2991c3439bcb0a59ea8f22e48977d4d4 to your computer and use it in GitHub Desktop.
Save stevencurtis/2991c3439bcb0a59ea8f22e48977d4d4 to your computer and use it in GitHub Desktop.
httpmanagermockcombine
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