Guest User

Untitled

a guest
Feb 10th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. func loginUser(from url: URL, with username: String, and password: String, completionHandler: @escaping (DrivetimeUserProfile?, DrivetimeAPIError.LoginError?) -> Void) {
  2. DispatchQueue.main.async {
  3. completionHandler(nil, .EmptyData)
  4. }
  5. }
  6.  
  7. @IBAction func onLoginButtonTapped(_ sender: Any) {
  8.  
  9. guard let url = URL(string: USER_LOGIN_ENDPOINT) else { return }
  10.  
  11. let username = userNameTextField.text
  12. let password = passwordTextField.text
  13.  
  14. client.loginUser(from: url, with: username!, and: password!) { (data, error) in
  15.  
  16. if let error = error {
  17.  
  18. switch error {
  19.  
  20. case .EmptyData:
  21. DispatchQueue.main.async {
  22. presentAlertVC()
  23. }
  24.  
  25. case .CannotDecodeJson:
  26. DispatchQueue.main.async {
  27. presentAlertVC()
  28. }
  29. }
  30. }
  31. }
  32.  
  33. func testLoginButtin_ShouldPresentAlertContollerIfErrorIsNotNil() {
  34.  
  35. sut.onLoginButtonTapped(sut.loginButton)
  36.  
  37. let alert = sut.presentingViewController
  38.  
  39. XCTAssertNotNil(alert)
  40.  
  41.  
  42. }
Add Comment
Please, Sign In to add comment