Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement