Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func loginUser(from url: URL, with username: String, and password: String, completionHandler: @escaping (DrivetimeUserProfile?, DrivetimeAPIError.LoginError?) -> Void) {
- DispatchQueue.main.async {
- completionHandler(nil, .EmptyData)
- }
- }
- @IBAction func onLoginButtonTapped(_ sender: Any) {
- guard let url = URL(string: USER_LOGIN_ENDPOINT) else { return }
- let username = userNameTextField.text
- let password = passwordTextField.text
- client.loginUser(from: url, with: username!, and: password!) { (data, error) in
- if let error = error {
- switch error {
- case .EmptyData:
- DispatchQueue.main.async {
- presentAlertVC()
- }
- case .CannotDecodeJson:
- DispatchQueue.main.async {
- presentAlertVC()
- }
- }
- }
- }
- func testLoginButtin_ShouldPresentAlertContollerIfErrorIsNotNil() {
- sut.onLoginButtonTapped(sut.loginButton)
- let alert = sut.presentingViewController
- XCTAssertNotNil(alert)
- }
Add Comment
Please, Sign In to add comment