PageRenderTime 28ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

/CoreApplicationPrototypeTests/CoreApplicationPrototypeTests.swift

https://gitlab.com/InboundRX-Capstone/Paulsens-iOS-App
Swift | 193 lines | 121 code | 34 blank | 38 comment | 18 complexity | c17fabca16e3c7d064b7294628283437 MD5 | raw file
  1. //
  2. // CoreApplicationPrototypeTests.swift
  3. // CoreApplicationPrototypeTests
  4. //
  5. // Created by Thaddeus Sundin on 11/21/16.
  6. // Copyright © 2016 InboundRXCapstone. All rights reserved.
  7. //
  8. import XCTest
  9. @testable import CoreApplicationPrototype
  10. class CoreApplicationPrototypeTests: XCTestCase {
  11. override func setUp() {
  12. super.setUp()
  13. // Put setup code here. This method is called before the invocation of each test method in the class.
  14. }
  15. override func tearDown() {
  16. // Put teardown code here. This method is called after the invocation of each test method in the class.
  17. super.tearDown()
  18. }
  19. func testExample() {
  20. // This is an example of a functional test case.
  21. // Use XCTAssert and related functions to verify your tests produce the correct results.
  22. }
  23. func testPerformanceExample() {
  24. // This is an example of a performance test case.
  25. self.measure {
  26. // Put the code you want to measure the time of here.
  27. }
  28. }
  29. // Test the webCallController daily Deals web call
  30. // First set an expectation, then, make the callback function call
  31. // Inside do any tests desired, (here make sure if error we get no list)
  32. // and an error message. If no error, make sure any deals contained
  33. // are actually daily deals, then fulfill the set expectation
  34. // so it doesnt time out.
  35. func testDealsWebCall () {
  36. let exp = expectation(description: "getDailyDeals")
  37. let webCallController = WebCallController()
  38. webCallController.getDailyDealList(callback: { (isError, errorMessage, dailyDealsList) in
  39. if isError {
  40. XCTAssertNotNil(errorMessage)
  41. XCTAssertNil(dailyDealsList)
  42. } else {
  43. for dict in dailyDealsList! {
  44. XCTAssert(dict["daily_deal"] as! Bool)
  45. }
  46. }
  47. exp.fulfill()
  48. })
  49. waitForExpectations(timeout: 15, handler: nil)
  50. }
  51. // Test the webCallController Rewards web call
  52. // First set an expectation, then, make the callback function call
  53. // Inside do any tests desired, (here make sure if error we get no list)
  54. // and an error message. If no error, make sure any deals contained
  55. // are actually rewards. Once this is done, fulfill the expectation
  56. // so it doesn't time out and fail
  57. func testRewardsWebCall () {
  58. let exp = expectation(description: "getRewards")
  59. let webCallController = WebCallController()
  60. webCallController.getRewardsList(callback: { (isError, errorMessage, rewardsList) in
  61. if isError {
  62. XCTAssertNotNil(errorMessage)
  63. XCTAssertNil(rewardsList)
  64. } else {
  65. for dict in rewardsList! {
  66. XCTAssertFalse(dict["daily_deal"] as! Bool)
  67. }
  68. }
  69. exp.fulfill()
  70. })
  71. waitForExpectations(timeout: 15, handler: nil)
  72. }
  73. // Test the webCallController getHistoryList web call
  74. // First set an expectation, then, make the callback function call
  75. // Inside do any tests desired, (here make sure if error we get no list)
  76. // and an error message. If no error, make sure the list is not empty
  77. // then fulfill the set expectation so it doesnt time out.
  78. func testHistoryWebCall () {
  79. let exp = expectation(description: "getHistory")
  80. let webCallController = WebCallController()
  81. webCallController.getHistoricalEventList(callback: { (isError, errorMessage, historicalEvents) in
  82. if isError {
  83. XCTAssertNotNil(errorMessage)
  84. XCTAssertNil(historicalEvents)
  85. } else {
  86. XCTAssertNotNil(historicalEvents)
  87. }
  88. exp.fulfill()
  89. })
  90. waitForExpectations(timeout: 15, handler: nil)
  91. }
  92. // Test the webCallController Beacons web call
  93. // First set an expectation, then, make the callback function call
  94. // Inside do any tests desired, (here make sure if error we get no list)
  95. // and an error message. If no error, make certain there is in fact a list
  96. func testBeaconsWebCall () {
  97. let exp = expectation(description: "getBeacons")
  98. let webCallController = WebCallController()
  99. webCallController.getBeaconList(callback: { (isError, errorMessage, beaconList) in
  100. if isError {
  101. XCTAssertNotNil(errorMessage)
  102. XCTAssertNil(beaconList)
  103. } else {
  104. XCTAssertNotNil(beaconList)
  105. }
  106. exp.fulfill()
  107. })
  108. waitForExpectations(timeout: 15, handler: nil)
  109. }
  110. // Unit test the user login and logout functions. This does
  111. // Test the webCallController function as well.
  112. func testUser() {
  113. let user = User(userEmail: "noUser")
  114. XCTAssertTrue(user.loggedIn() == false)
  115. var result = user.loginUser(emailField: "edittest@edit.com", passwordField: "password123")
  116. XCTAssert(result.0)
  117. XCTAssert(user.loggedIn())
  118. result = user.logOut()
  119. XCTAssert(result.0)
  120. XCTAssertTrue(user.loggedIn() == false)
  121. }
  122. // Test if the user can change their password then change it back to the original
  123. // so testUser() can sign in with the same credentials
  124. func testChangePasswordEditAccount() {
  125. let user = User(userEmail: "noUser")
  126. XCTAssertTrue(user.loggedIn() == false)
  127. var result = user.loginUser(emailField: "edittest@edit.com", passwordField: "password123")
  128. XCTAssert(result.0)
  129. XCTAssertTrue(user.loggedIn())
  130. result = user.editPassword(currentPassword: "password123", password: "password321", repeatPassword:"password321")
  131. XCTAssert(result.0)
  132. result = user.editPassword(currentPassword: "password321", password: "password123", repeatPassword:"password123")
  133. XCTAssert(result.0)
  134. result = user.logOut()
  135. XCTAssertTrue(user.loggedIn() == false)
  136. }
  137. func testChangePhoneNumberEditAccount() {
  138. let user = User(userEmail: "noUser")
  139. XCTAssertTrue(user.loggedIn() == false)
  140. var result = user.loginUser(emailField: "edittest@edit.com", passwordField: "password123")
  141. XCTAssert(result.0)
  142. XCTAssertTrue(user.loggedIn())
  143. result = user.editPhone(phone: "1234567890", currentPassword: "password123")
  144. XCTAssert(result.0)
  145. result = user.logOut()
  146. XCTAssert(user.loggedIn() == false)
  147. }
  148. func testChangeAddressEditAccount() {
  149. let user = User(userEmail: "noUser")
  150. XCTAssertTrue(user.loggedIn() == false)
  151. var result = user.loginUser(emailField: "edittest@edit.com", passwordField: "password123")
  152. XCTAssert(result.0)
  153. XCTAssertTrue(user.loggedIn())
  154. result = user.editAddress(address: "12345 NorthPole Ave., North Pole, North 00000", currentPassword: "password123")
  155. XCTAssert(result.0)
  156. result = user.logOut()
  157. XCTAssert(user.loggedIn() == false)
  158. }
  159. }