Created
September 2, 2017 19:12
-
-
Save rachidcalazans/fa4494d904d17381a5308ed8a6ae1095 to your computer and use it in GitHub Desktop.
Test Class #1 for the Post - better-setups-on-swift-tests
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 UserRepoTests: XCTestCase { | |
| var userRepo = UserRepo() | |
| var email = "[email protected]" | |
| var result = [User]() | |
| override func setUp() { | |
| super.setUp() | |
| createAdmin(name: "User Admin 1") | |
| createUser(name: "User") | |
| } | |
| func testFindAdminsByMethodWhenHaveTwoAdminsAndOneCommunUserWithSameEmailAndPassTheEmailAsParameter() { | |
| let expectedCount = 2 | |
| let expectedNameOne = "User Admin 1" | |
| let expectedNameTwo = "User Admin 2" | |
| createAdmin(name: "User Admin 2") | |
| result = userRepo.findAdminsBy(email: email) | |
| XCTAssertEqual(expectedCount, result.count) | |
| XCTAssertEqual(expectedNameOne, result[0].name) | |
| XCTAssertEqual(expectedNameTwo, result[1].name) | |
| } | |
| func testFindAdminsByMethodWhenHaveOneAdmimAndOneCommunUserWithSameEmailAndPassTheEmailAsParameter() { | |
| let expectedCount = 1 | |
| let expectedName = "User Admin 1" | |
| result = userRepo.findAdminsBy(email: email) | |
| XCTAssertEqual(expectedCount, result.count) | |
| XCTAssertEqual(expectedName, result[0].name) | |
| } | |
| func testFindAdminsByMethodWhenHaveOneAdmimAndOneCommunUserWithSameEmailAndPassDifferentEmailAsParameter() { | |
| let expectedCount = 0 | |
| result = userRepo.findAdminsBy(email: "[email protected]") | |
| XCTAssertEqual(expectedCount, result.count) | |
| } | |
| // MARK: Functions to help to create User and Admin | |
| func createUser(name: String, email: String = "[email protected]") { | |
| let user = User(email: email, name: name) | |
| userRepo.save(user) | |
| } | |
| func createAdmin(name: String, email: String = "[email protected]") { | |
| 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