Skip to content

Instantly share code, notes, and snippets.

View koromiko's full-sized avatar

Shih Ting Huang (Neo) koromiko

View GitHub Profile
struct Staging: Configuration {
var certificate = "ios_distribution"
var provisioningProfile = "Brewer_Staging"
var buildConfiguration = "Staging"
var appIdentifier = "works.sth.brewer.staging"
var exportMethod = "ad-hoc"
}
struct Production: Configuration {
var certificate = "ios_distribution"
protocol Configuration {
/// file name of the certificate
var certificate: String { get }
/// file name of the provisioning profile
var provisioningProfile: String { get }
/// configuration name in xcode project
var buildConfiguration: String { get }
func package(config: Configuration) {
}
class Fastfile: LaneFile {
func developerReleaseLane() {
desc("Create a developer release")
package(config: Staging())
crashlytics
}
func qaReleaseLane() {
desc("Create a qa release")
package(config: Production())
override func setUp() {
super.setUp()
mockAPIService = MockApiService()
sut = PhotoListViewModel(apiService: mockAPIService)
}
override func tearDown() {
sut = nil
mockAPIService = nil
super.tearDown()
func test_user_press_for_sale_item() {
let indexPath = IndexPath(row: 0, section: 0)
//Given some photo stubs
mockAPIService.completePhotos = StubGenerator().stubPhotos()
sut.initFetch() // Fetch stubs
mockAPIService.fetchSuccess()
class MockApiService: APIServiceProtocol {
var completePhotos: [Photo] = [Photo]() // Array of stubs
var completeClosure: ((Bool, [Photo], APIError?) -> ())
func fetchPopularPhoto(complete: @escaping (Bool, [Photo], APIError?) -> ()) {
\\...\\
completeClosure = complete
}
func fetchSuccess() {
func test_user_press_for_sale_item() {
//Given a sut with fetched photos
let indexPath = IndexPath(row: 0, section: 0)
//When
sut.userPressed( at: indexPath )
//Assert
XCTAssertTrue( sut.isAllowSegue )
class MockAPIService: APIServiceProtocol {
var completeClosure: ((Bool, [Photo], APIError?) -> ())!
func fetchPopularPhoto(complete: @escaping (Bool, [Photo], APIError?) -> ()) {
isFetchPopularPhotoCalled = true
completeClosure = complete
}
func fetchSuccess() {
completeClosure( true, [Photo](), nil )
func initFetch() {
self.isLoading = true
apiService.fetchPopularPhoto { [weak self] (success, photos, error) in
self?.isLoading = false
if let error = error {
self?.alertMessage = error.rawValue
} else {
self?.processFetchedPhoto(photos: photos)
}
}