2019-01-06 19:26:08 +00:00
|
|
|
//
|
2019-01-06 21:01:08 +00:00
|
|
|
// NetworkSessionMock
|
2019-01-06 19:26:08 +00:00
|
|
|
// MasKitTests
|
|
|
|
//
|
|
|
|
// Created by Ben Chatelain on 11/13/18.
|
|
|
|
// Copyright © 2018 mas-cli. All rights reserved.
|
|
|
|
//
|
|
|
|
|
2021-04-14 19:08:55 +00:00
|
|
|
import Foundation
|
2021-04-23 02:15:57 +00:00
|
|
|
import PromiseKit
|
2021-05-09 20:25:20 +00:00
|
|
|
|
2021-04-22 01:05:36 +00:00
|
|
|
@testable import MasKit
|
2019-01-06 19:26:08 +00:00
|
|
|
|
2019-01-06 21:01:08 +00:00
|
|
|
/// Mock NetworkSession for testing.
|
|
|
|
class NetworkSessionMock: NetworkSession {
|
2019-01-06 19:26:08 +00:00
|
|
|
// Properties that enable us to set exactly what data or error
|
|
|
|
// we want our mocked URLSession to return for any request.
|
|
|
|
var data: Data?
|
|
|
|
var error: Error?
|
|
|
|
|
|
|
|
/// Immediately passes data and error to completion handler.
|
|
|
|
///
|
|
|
|
/// - Parameters:
|
|
|
|
/// - url: unused
|
|
|
|
/// - completionHandler: Closure which is delivered either data or an error.
|
2021-04-23 02:15:57 +00:00
|
|
|
func loadData(from _: URL) -> Promise<Data> {
|
|
|
|
guard let data = data else {
|
|
|
|
return Promise(error: error ?? MASError.noData)
|
|
|
|
}
|
|
|
|
|
|
|
|
return .value(data)
|
2019-01-06 19:26:08 +00:00
|
|
|
}
|
|
|
|
}
|