Skip to content

Instantly share code, notes, and snippets.

@ykpoh
Created July 24, 2021 07:41
Show Gist options
  • Save ykpoh/5696afb67bb61dc633e676d29d70a307 to your computer and use it in GitHub Desktop.
Save ykpoh/5696afb67bb61dc633e676d29d70a307 to your computer and use it in GitHub Desktop.
import Foundation
@testable import SpaceXLaunch
import Alamofire // 1
class MockDataRequest: DataRequestProtocol { // 2
// 3
static var statusCode: Int = 200
static var data: Data?
var dataResponse = AFDataResponse<Any>(
request: nil,
response: HTTPURLResponse(url: URL(string: "test.ykpoh.com")!, statusCode: MockDataRequest.statusCode, httpVersion: "1.1", headerFields: nil),
data: MockDataRequest.data,
metrics: nil,
serializationDuration: TimeInterval(),
result: Result.success(true)
)
func response(completionHandler: @escaping (AFDataResponse<Any>) -> Void) -> Self {
completionHandler(dataResponse)
return self
}
func responseJSON(completionHandler: @escaping (AFDataResponse<Any>) -> Void) -> Self {
return response(completionHandler: completionHandler)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment