Created
September 2, 2017 19:14
-
-
Save rachidcalazans/d6c0ef2685183dd63294e3d6d3ef14c5 to your computer and use it in GitHub Desktop.
Test Class #3 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 Quick | |
import Nimble | |
class UserRepoTest: QuickSpec { | |
override func spec() { | |
var userRepo = UserRepo() | |
describe("#findAdminsBy") { | |
var email = "" | |
var result = [User]() | |
let findAdminsByAction: Action = Action() { | |
createAdmin(name: "User Admin 1") | |
createUser(name: "User") | |
result = userRepo.findAdminsBy(email: email) | |
} | |
// Guarantee the dataBase will be cleaned before each test | |
beforeEach { | |
userRepo.clean() | |
} | |
context("When have two Admins and one commun User with same email and pass the email as parameter") { | |
let expectedNameTwo = "User Admin 2" | |
beforeEach{ | |
execute(action: findAdminsByAction) { | |
email = "user@gmail.com" | |
createAdmin(name: expectedNameTwo) | |
} | |
} | |
it("Should return two admins") { | |
expect(result.count).to(equal(2)) | |
} | |
it("Should return two admins with correct names") { | |
let expectedNameOne = "User Admin 1" | |
expect(result[1].name).to(equal(expectedNameOne)) | |
expect(result[0].name).to(equal(expectedNameTwo)) | |
} | |
} | |
context("When have one Admim and one commun User with same email") { | |
context("When pass the email as parameter") { | |
beforeEach{ | |
execute(action: findAdminsByAction) { | |
email = "user@gmail.com" | |
} | |
} | |
it("Should return one admim") { | |
expect(result.count).to(equal(1)) | |
} | |
it("Should return the admim with correct name") { | |
let expectedName = "User Admin 1" | |
expect(result[0].name).to(equal(expectedName)) | |
} | |
} | |
context("When pass different email as parameter") { | |
beforeEach{ | |
execute(action: findAdminsByAction) { | |
email = "none@gmail.com" | |
} | |
} | |
it("Should return none admim") { | |
expect(result).to(beEmpty()) | |
} | |
} | |
} | |
} | |
// 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