Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.45 KB | None | 0 0
  1. //
  2. // ProfilesTests.swift
  3. // GWA-appTests
  4. //
  5. // Created by Joseph Reusing on 2018-04-24.
  6. // Copyright © 2018 manulife. All rights reserved.
  7. //
  8.  
  9. import XCTest
  10. @testable import GWA_app
  11.  
  12. class ProfilesTests: XCTestCase {
  13. let user = User()
  14. let profiles = Profiles()
  15.  
  16. override func setUp() {
  17. super.setUp()
  18. }
  19.  
  20. override func tearDown() {
  21. // Put teardown code here. This method is called after the invocation of each test method in the class.
  22. super.tearDown()
  23. }
  24.  
  25. func testExample() {
  26. // This is an example of a functional test case.
  27. // Use XCTAssert and related functions to verify your tests produce the correct results.
  28. }
  29.  
  30. func testPerformanceExample() {
  31. // This is an example of a performance test case.
  32. self.measure {
  33. // Put the code you want to measure the time of here.
  34. }
  35. }
  36.  
  37. // Tests loading all the profiles and loadMyProfile
  38. func testLoadProfiles() {
  39. let _ = Profile()
  40. let expect1 = expectation(description: "Data should load")
  41. let expect2 = expectation(description: "MyProfile should load")
  42.  
  43. self.user.login(email: "joseph_reusing@manulife.com", password: "123456", completion: {
  44. (error) in
  45. if error == nil {
  46. self.profiles.load {
  47. expect1.fulfill()
  48. }
  49. self.profiles.loadMyProfile {
  50. XCTAssert(self.profiles.myProfile != nil, "My Profile did not load.")
  51. expect2.fulfill()
  52. }
  53. }
  54. })
  55.  
  56. waitForExpectations(timeout: 2, handler: {
  57. (error) in
  58. if let error = error {
  59. XCTFail("waitForExpectationsWithTimeout errored: \(error)")
  60. }
  61. })
  62. }
  63.  
  64. // Test updating profile
  65. func testUpdateProfile() {
  66. let expect = expectation(description: "Profile should update.")
  67.  
  68. self.user.login(email: "joseph_reusing@manulife.com", password: "123456", completion: {
  69. (error) in
  70. if error == nil {
  71. self.profiles.loadMyProfile {
  72. XCTAssert(self.profiles.myProfile != nil, "My Profile did not load.")
  73. if let myProfile = self.profiles.myProfile {
  74. myProfile.firstName = nil
  75. myProfile.lastName = nil
  76. myProfile.email = nil
  77. myProfile.jobTitle = nil
  78. myProfile.businessUnit = nil
  79. myProfile.homeOffice = nil
  80. myProfile.interests = nil
  81. myProfile.linkedInURL = nil
  82.  
  83. self.profiles.updateMyProfile(completion: {
  84. (error) in
  85. XCTAssert(error == nil, "Failed to update my profile.")
  86. myProfile.firstName = "Joseph"
  87. myProfile.lastName = "Reusing"
  88. myProfile.email = "joseph_reusing@manulife.com"
  89. myProfile.jobTitle = "Software Developer"
  90. myProfile.businessUnit = "Red Lab"
  91. myProfile.homeOffice = "151 Charles St."
  92. myProfile.interests = "Fun stuff"
  93. myProfile.linkedInURL = nil
  94. self.profiles.updateMyProfile(completion: {
  95. (error) in
  96. XCTAssert(error == nil, "Failed to update my profile.")
  97. expect.fulfill()
  98. })
  99. })
  100. }
  101. }
  102. }
  103. })
  104. waitForExpectations(timeout: 2, handler: {
  105. (error) in
  106. if let error = error {
  107. XCTFail("waitForExpectationsWithTimeout errored: \(error)")
  108. }
  109. })
  110. }
  111.  
  112. // Test the functions unverified users will use
  113. func testUnverified() {
  114. let expect1 = expectation(description: "Should get pid from email.")
  115. let expect2 = expectation(description: "Should create unfound profile.")
  116.  
  117. self.user.login(email: "joseph_reusing@manulife.com", password: "123456", completion: {
  118. (error) in
  119. if error == nil {
  120. self.profiles.getProfileByEmail(email: "unit_tester@manulife.com", completion: {
  121. pid in
  122. XCTAssert(pid == "-LAOKj6llCIP1TeU7yDK", "Incorrect PID of unit_tester@manulife.com")
  123. expect1.fulfill()
  124. })
  125. self.profiles.createUnfound(name: "Unfound Test", email: "unfound_test@manulife.com", completion: {
  126. (new_pid) in
  127. XCTAssert(new_pid != nil, "No PID created for unfound profile.")
  128. expect2.fulfill()
  129. })
  130. self.profiles.loadNameEmail(pid: "-LAOKj6llCIP1TeU7yDK", completion: {
  131. (name, email) in
  132. XCTAssert(email == "unit_tester@manulife.com", "Email retrieved not matching PID.")
  133. })
  134. }
  135. })
  136.  
  137. waitForExpectations(timeout: 4, handler: {
  138. (error) in
  139. if let error = error {
  140. XCTFail("waitForExpectationsWithTimeout errored: \(error)")
  141. }
  142. })
  143. }
  144.  
  145. // Test Cloud functions
  146. func testCloud() {
  147. let expect = expectation(description: "Upload and download should succeed")
  148.  
  149. let image = #imageLiteral(resourceName: "avatar")
  150. let thumbnailImage = image.resizeImage(CGFloat(60), opaque: false)
  151. guard let avatarData = UIImageJPEGRepresentation(image, 0.8),
  152. let thumbnailData = UIImageJPEGRepresentation(thumbnailImage, 0.8) else {
  153. return
  154. }
  155. self.user.login(email: "joseph_reusing@manulife.com", password: "123456", completion: {
  156. (error) in
  157. if error == nil {
  158. self.profiles.upload(avatarData: avatarData, thumbnailData: thumbnailData, completion: {
  159. (error) in
  160. XCTAssert(error == nil, "Failed to upload Avatar.")
  161. self.profiles.download(completion: {
  162. (image, error) in
  163. XCTAssert(error == nil, "Failed to download Avatar.")
  164. self.profiles.deleteMyAvatar(completion: {
  165. (error) in
  166. XCTAssert(error != nil, "Should not be able to delete Avatar.")
  167. expect.fulfill()
  168. })
  169. })
  170. })
  171. }
  172. })
  173.  
  174. waitForExpectations(timeout: 10, handler: {
  175. (error) in
  176. if let error = error {
  177. XCTFail("waitForExpectationsWithTimeout errored: \(error)")
  178. }
  179. })
  180. }
  181.  
  182. // Test loading profile thumbnail
  183. func testThumbnail() {
  184. let expect = expectation(description: "Loading thumbnail should succeed.")
  185.  
  186. self.user.login(email: "joseph_reusing@manulife.com", password: "123456", completion: {
  187. (error) in
  188. if error == nil {
  189. self.profiles.loadMyProfile {
  190. if let myProfile = self.profiles.myProfile {
  191. myProfile.loadThumbnail(completion: {
  192. (image, error) in
  193. XCTAssert(error == nil, "Failed to load thumbnail.")
  194. myProfile.hasAvatar = false
  195. myProfile.loadThumbnail(completion: {
  196. (image, error) in
  197. XCTAssert(image == nil, "Should not load image.")
  198. myProfile.hasAvatar = true
  199. expect.fulfill()
  200. })
  201. })
  202. }
  203. }
  204. }
  205. })
  206.  
  207. waitForExpectations(timeout: 10, handler: {
  208. (error) in
  209. if let error = error {
  210. XCTFail("waitForExpectationsWithTimeout errored: \(error)")
  211. }
  212. })
  213. }
  214.  
  215. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement