This file contains hidden or 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
import Foundation | |
import XCTest | |
extension Data { | |
public static func fromJSON(fileName: String) throws -> Data { | |
let bundle = Bundle(for: TestBundleClass.self) | |
let url = try XCTUnwrap(bundle.url(forResource: fileName, withExtension: "json")) | |
return try Data(contentsOf: url) | |
} | |
} |
This file contains hidden or 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
import Foundation | |
import XCTest | |
protocol DecodableTestCase: class { | |
associatedtype T: Decodable | |
var sut: T! { get set } | |
} | |
extension DecodableTestCase { | |
func givenSUTFromJSON(fileName: String = "\(T.self)") throws { | |
let decoder = JSONDecoder() |
This file contains hidden or 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
import XCTest | |
@testable import SpaceXLaunch // 1 | |
class LaunchResponseTests: XCTestCase, DecodableTestCase { // 2 | |
var sut: LaunchResponse! // 3 | |
override func setUpWithError() throws { | |
// Put setup code here. This method is called before the invocation of each test method in the class. | |
try super.setUpWithError() | |
try! givenSUTFromJSON() // 4 |
This file contains hidden or 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
import XCTest | |
class LaunchResponseTests: XCTestCase { | |
override func setUpWithError() throws { | |
// Put setup code here. This method is called before the invocation of each test method in the class. | |
} | |
override func tearDownWithError() throws { | |
// Put teardown code here. This method is called after the invocation of each test method in the class. |
This file contains hidden or 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
{ | |
"height": { | |
"meters": 70, | |
"feet": 229.6 | |
}, | |
"diameter": { | |
"meters": 12.2, | |
"feet": 39.9 | |
}, | |
"mass": { |
This file contains hidden or 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
{ | |
"docs": [ | |
{ | |
"fairings": { | |
"reused": false, | |
"recovery_attempt": false, | |
"recovered": false, | |
"ships": [] | |
}, | |
"links": { |
This file contains hidden or 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
import Alamofire | |
protocol APIServiceProtocol { // 1 | |
func fetchLaunchesWithQuery(startDate: Date, endDate: Date, completion: @escaping (LaunchResponse?, Error?, AFDataResponse<Any>) -> Void) -> DataRequestProtocol | |
func fetchRocket(rocketName: String, completion: @escaping (Rocket?, Error?, AFDataResponse<Any>) -> Void) -> DataRequestProtocol | |
} | |
extension APIServiceProtocol { // 2 | |
@discardableResult func fetchLaunchesWithQuery(startDate: Date = Calendar.current.date(byAdding: .year, value: -3, to: Date()) ?? Date(), endDate: Date = Date(), completion: @escaping (LaunchResponse?, Error?, AFDataResponse<Any>) -> Void) -> DataRequestProtocol { | |
return fetchLaunchesWithQuery(startDate: startDate, endDate: endDate, completion: completion) |
This file contains hidden or 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
import Foundation | |
import RxCocoa | |
protocol LaunchListTableViewCellViewModelType { // 1 | |
var launch: BehaviorRelay<Launch?> { get } | |
var launchNumber: BehaviorRelay<String?> { get } | |
var detail: BehaviorRelay<String?> { get } | |
var hideDetail: BehaviorRelay<Bool> { get } | |
var dateTime: BehaviorRelay<String?> { get } | |
var statusString: BehaviorRelay<String?> { get } |
This file contains hidden or 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
import UIKit | |
import RxSwift | |
class LaunchListViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { | |
@IBOutlet var tableView: UITableView! | |
var viewModel: LaunchListViewModelType = LaunchListViewModel() | |
var disposeBag: DisposeBag! | |
override func viewDidLoad() { | |
super.viewDidLoad() |
This file contains hidden or 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
import Alamofire | |
protocol APIServiceProtocol { | |
func fetchLaunchesWithQuery(startDate: Date, endDate: Date, completion: @escaping (LaunchResponse?, Error?, AFDataResponse<Any>) -> Void) -> DataRequestProtocol | |
func fetchRocket(rocketName: String, completion: @escaping (Rocket?, Error?, AFDataResponse<Any>) -> Void) -> DataRequestProtocol | |
} | |
extension APIServiceProtocol { | |
@discardableResult func fetchLaunchesWithQuery(startDate: Date = Calendar.current.date(byAdding: .year, value: -3, to: Date()) ?? Date(), endDate: Date = Date(), completion: @escaping (LaunchResponse?, Error?, AFDataResponse<Any>) -> Void) -> DataRequestProtocol { | |
return fetchLaunchesWithQuery(startDate: startDate, endDate: endDate, completion: completion) |