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
// Checking if unit tests are running | |
if ProcessInfo.processInfo.environment["unit_tests"] == "true" { | |
print("Setting up Firebase emulator localhost:8080") | |
let settings = Firestore.firestore().settings | |
settings.host = "localhost:8080" | |
settings.isPersistenceEnabled = false | |
settings.isSSLEnabled = false | |
Firestore.firestore().settings = settings | |
} |
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
init?(from document: [String: Any]) { | |
guard let idString = document["id"] as? String, | |
let id = Int(idString), | |
let name = document["name"] as? String, | |
let priceString = document["pricePerUnit"] as? String, | |
let price = Double(priceString) else { return nil } | |
self.init(id: id, name: name, pricePerUnit: price) | |
} |
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
typealias GetProductsCompletionHandler = ([Product]) -> Void | |
func getProductsFromCart(_ completion: @escaping GetProductsCompletionHandler) { | |
self.db.collection("cart").getDocuments { (snapshot, error) in | |
// Handle error | |
if error != nil { | |
completion([]) | |
return | |
} |
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
func test_WhenProductIsNotNilAndAddToCartIsCalled_ThenTheProductIsAdded() { | |
// given | |
self.viewModel.product = Product(id: 1, name: "Grey T-Shirt", pricePerUnit: 20) | |
let exp = self.expectation(description: "Waiting for async operation") | |
// when | |
self.viewModel.addToCart { (result) in | |
// then | |
switch result { | |
case .success: |
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 | |
import Firebase | |
extension XCTestCase { | |
func clearFirestore() { | |
let semaphore = DispatchSemaphore(value: 0) | |
let projectId = FirebaseApp.app()!.options.projectID! | |
let url = URL(string: "http://localhost:8080/emulator/v1/projects/\(projectId)/databases/(default)/documents")! | |
var request = URLRequest(url: 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
override func tearDownWithError() throws { | |
self.viewModel = nil | |
self.clearFirestore() | |
} |
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
self.stackView.setCustomSpacing(32, after: self.secondLabel) |
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 | |
protocol Animal { | |
func walk() | |
func run() | |
} | |
class Elephant: Animal { | |
func walk() { | |
print("I am walking") |
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 | |
@objc protocol Animal { | |
func walk() | |
@objc optional func run() | |
} | |
class Elephant: NSObject, Animal { | |
func walk() { | |
print("I am walking") |
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 | |
protocol Animal { | |
func walk() | |
func run() | |
} | |
extension Animal { | |
func run() { | |
} |
OlderNewer