Created
September 2, 2017 19:14
-
-
Save rachidcalazans/a0503ac8886f43b791d90e90913349a6 to your computer and use it in GitHub Desktop.
Test Class #2 for the Post - better-setups-on-swift-tests
This file contains 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 UserRepoRefactoredTests: XCTestCase { | |
var userRepo = UserRepo() | |
var email = "user@gmail.com" | |
var result = [User]() | |
lazy var findAdminsByAction: Action = { | |
return Action() { | |
self.createAdmin(name: "User Admin 1") | |
self.createUser(name: "User") | |
self.result = self.userRepo.findAdminsBy(email: self.email) | |
} | |
}() | |
func testFindAdminsByMethodWhenHaveTwoAdminsAndOneCommunUserWithSameEmailAndPassTheEmailAsParameter() { | |
let expectedCount = 2 | |
let expectedNameOne = "User Admin 1" | |
let expectedNameTwo = "User Admin 2" | |
execute(action: findAdminsByAction) { | |
self.createAdmin(name: expectedNameTwo) | |
} | |
XCTAssertEqual(expectedCount, result.count) | |
XCTAssertEqual(expectedNameOne, result[1].name) | |
XCTAssertEqual(expectedNameTwo, result[0].name) | |
} | |
func testFindAdminsByMethodWhenHaveOneAdmimAndOneCommunUserWithSameEmailAndPassTheEmailAsParameter() { | |
let expectedCount = 1 | |
let expectedName = "User Admin 1" | |
execute(action: findAdminsByAction) | |
XCTAssertEqual(expectedCount, result.count) | |
XCTAssertEqual(expectedName, result[0].name) | |
} | |
func testFindAdminsByMethodWhenHaveOneAdmimAndOneCommunUserWithSameEmailAndPassDifferentEmailAsParameter() { | |
let expectedCount = 0 | |
execute(action: findAdminsByAction) { | |
self.email = "none@gmail.com" | |
} | |
XCTAssertEqual(expectedCount, result.count) | |
} | |
// MARK: Functions to help to create User and Admin | |
func createUser(name: String, email: String = "user@gmail.com") { | |
let user = User(email: email, name: name) | |
userRepo.save(user) | |
} | |
func createAdmin(name: String, email: String = "user@gmail.com") { | |
let user = User(email: email, name: name, isAdmin: true) | |
userRepo.save(user) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment