Advertisement
Guest User

Untitled

a guest
Sep 2nd, 2017
450
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 KB | None | 0 0
  1. import Quick
  2. import Nimble
  3.  
  4. class UserRepoTest: QuickSpec {
  5.  
  6. override func spec() {
  7. var userRepo = UserRepo()
  8.  
  9. describe("#findAdminsBy") {
  10. var email = ""
  11. var result = [User]()
  12.  
  13. let findAdminsByAction: Action = Action() {
  14. createAdmin(name: "User Admin 1")
  15. createUser(name: "User")
  16.  
  17. result = userRepo.findAdminsBy(email: email)
  18. }
  19.  
  20. // Guarantee the dataBase will be cleaned before each test
  21. beforeEach {
  22. userRepo.clean()
  23. }
  24.  
  25. context("When have two Admins and one commun User with same email and pass the email as parameter") {
  26. let expectedNameTwo = "User Admin 2"
  27.  
  28. beforeEach{
  29. execute(action: findAdminsByAction) {
  30. email = "user@gmail.com"
  31. createAdmin(name: expectedNameTwo)
  32. }
  33. }
  34.  
  35. it("Should return two admins") {
  36. expect(result.count).to(equal(2))
  37. }
  38.  
  39. it("Should return two admins with correct names") {
  40. let expectedNameOne = "User Admin 1"
  41.  
  42. expect(result[1].name).to(equal(expectedNameOne))
  43. expect(result[0].name).to(equal(expectedNameTwo))
  44. }
  45. }
  46.  
  47. context("When have one Admim and one commun User with same email") {
  48.  
  49. context("When pass the email as parameter") {
  50.  
  51. beforeEach{
  52. execute(action: findAdminsByAction) {
  53. email = "user@gmail.com"
  54. }
  55. }
  56.  
  57. it("Should return one admim") {
  58. expect(result.count).to(equal(1))
  59. }
  60.  
  61. it("Should return the admim with correct name") {
  62. let expectedName = "User Admin 1"
  63. expect(result[0].name).to(equal(expectedName))
  64. }
  65. }
  66.  
  67. context("When pass different email as parameter") {
  68.  
  69. beforeEach{
  70. execute(action: findAdminsByAction) {
  71. email = "none@gmail.com"
  72. }
  73. }
  74.  
  75. it("Should return none admim") {
  76. expect(result).to(beEmpty())
  77. }
  78.  
  79. }
  80.  
  81. }
  82.  
  83. }
  84.  
  85. // MARK: Functions to help to create User and Admin
  86.  
  87. func createUser(name: String, email: String = "user@gmail.com") {
  88. let user = User(email: email, name: name)
  89. userRepo.save(user)
  90. }
  91.  
  92. func createAdmin(name: String, email: String = "user@gmail.com") {
  93. let user = User(email: email, name: name, isAdmin: true)
  94. userRepo.save(user)
  95. }
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement