IOS-1541 point from VerificationService to AccountVS IOS-1541
authorAlejandro Gelos <agp@pep.security>
Fri, 12 Apr 2019 11:35:32 +0200
branchIOS-1541
changeset 8221d77a4e242296
parent 8220 3cedf7eb65ba
IOS-1541 point from VerificationService to AccountVS
pEpForiOS/UI/Login/LoginViewController.swift
pEpForiOS/UI/Login/ViewModel/LoginViewModel.swift
pEpForiOS/UI/ManualLogin/SMTPSetup/SMTPSettingsTableViewController.swift
pEpForiOS/UI/Settings/Setting/AccountSettings/AccountSettingsTableViewController.swift
pEpForiOS/UI/Settings/Setting/AccountSettings/ViewModel/AccountSettingsViewModel.swift
pEpForiOSTests/AccountVerificationServiceTests.swift
pEpForiOSTests/Models/Folder/FolderViewModelTest.swift
pEpForiOSTests/Models/LoginViewModelTests.swift
pEpForiOSTests/Models/Settings/AccountSettingsViewModelTest.swift
     1.1 --- a/pEpForiOS/UI/Login/LoginViewController.swift	Fri Apr 12 11:34:10 2019 +0200
     1.2 +++ b/pEpForiOS/UI/Login/LoginViewController.swift	Fri Apr 12 11:35:32 2019 +0200
     1.3 @@ -88,7 +88,7 @@
     1.4  
     1.5      override func didSetAppConfig() {
     1.6          super.didSetAppConfig()
     1.7 -        loginViewModel.verificationService = VerificationService()
     1.8 +        loginViewModel.verificationService = AccountVerificationService()
     1.9      }
    1.10  
    1.11      override func viewDidLoad() {
     2.1 --- a/pEpForiOS/UI/Login/ViewModel/LoginViewModel.swift	Fri Apr 12 11:34:10 2019 +0200
     2.2 +++ b/pEpForiOS/UI/Login/ViewModel/LoginViewModel.swift	Fri Apr 12 11:35:32 2019 +0200
     2.3 @@ -24,7 +24,7 @@
     2.4      }
     2.5  
     2.6      var loginAccount: Account?
     2.7 -    var verificationService: VerificationServiceProtocol?
     2.8 +    var verificationService: AccountVerificationServiceProtocol?
     2.9  
    2.10      /** If the last login attempt was via OAuth2, this will collect temporary parameters */
    2.11      private var lastOAuth2Parameters: OAuth2Parameters?
    2.12 @@ -56,8 +56,9 @@
    2.13  
    2.14      let qualifyServerService = QualifyServerIsLocalService()
    2.15  
    2.16 -    init(verificationService: VerificationServiceProtocol? = nil) {
    2.17 +    init(verificationService: AccountVerificationServiceProtocol? = nil) {
    2.18          self.verificationService = verificationService
    2.19 +        self.verificationService?.delegate = self
    2.20      }
    2.21  
    2.22      func isThereAnAccount() -> Bool {
    2.23 @@ -175,7 +176,7 @@
    2.24              return
    2.25          }
    2.26          account.imapServer?.trusted = trusted
    2.27 -        verificationService.requestVerification(account: account, delegate: self)
    2.28 +        verificationService.verify(account: account)
    2.29      }
    2.30  
    2.31      /**
     3.1 --- a/pEpForiOS/UI/ManualLogin/SMTPSetup/SMTPSettingsTableViewController.swift	Fri Apr 12 11:34:10 2019 +0200
     3.2 +++ b/pEpForiOS/UI/ManualLogin/SMTPSetup/SMTPSettingsTableViewController.swift	Fri Apr 12 11:35:32 2019 +0200
     3.3 @@ -23,6 +23,7 @@
     3.4  
     3.5      var model: AccountUserInput!
     3.6      private var currentlyVerifiedAccount: Account?
     3.7 +    private var accountVerificationService = AccountVerificationService()
     3.8      var fields = [UITextField]()
     3.9      var responder = 0
    3.10  
    3.11 @@ -40,6 +41,7 @@
    3.12          self.title = NSLocalizedString("SMTP", comment: "Manual account setup")
    3.13          UIHelper.variableCellHeightsTableView(tableView)
    3.14          fields = [serverValue, portValue]
    3.15 +        accountVerificationService.delegate = self
    3.16      }
    3.17  
    3.18      public override func viewWillAppear(_ animated: Bool) {
    3.19 @@ -79,7 +81,7 @@
    3.20          isCurrentlyVerifying =  true
    3.21          let account = try model.account()
    3.22          currentlyVerifiedAccount = account
    3.23 -        VerificationService().requestVerification(account: account, delegate: self)
    3.24 +        accountVerificationService.verify(account: account)
    3.25      }
    3.26  
    3.27      private func informUser(about error: Error, title: String) {
     4.1 --- a/pEpForiOS/UI/Settings/Setting/AccountSettings/AccountSettingsTableViewController.swift	Fri Apr 12 11:34:10 2019 +0200
     4.2 +++ b/pEpForiOS/UI/Settings/Setting/AccountSettings/AccountSettingsTableViewController.swift	Fri Apr 12 11:35:32 2019 +0200
     4.3 @@ -54,7 +54,7 @@
     4.4          configureView()
     4.5          if let vm = viewModel {
     4.6              vm.delegate = self
     4.7 -            vm.verificationService = VerificationService()
     4.8 +            vm.verificationService = AccountVerificationService()
     4.9          }
    4.10          passwordTextfield.delegate = self
    4.11      }
     5.1 --- a/pEpForiOS/UI/Settings/Setting/AccountSettings/ViewModel/AccountSettingsViewModel.swift	Fri Apr 12 11:34:10 2019 +0200
     5.2 +++ b/pEpForiOS/UI/Settings/Setting/AccountSettings/ViewModel/AccountSettingsViewModel.swift	Fri Apr 12 11:35:32 2019 +0200
     5.3 @@ -91,7 +91,7 @@
     5.4          }
     5.5      }
     5.6  
     5.7 -    var verificationService: VerificationService?
     5.8 +    var verificationService: AccountVerificationService?
     5.9      weak var delegate: AccountVerificationResultDelegate?
    5.10  
    5.11      //Currently we assume imap and smtp servers exist already (update).
    5.12 @@ -132,7 +132,7 @@
    5.13              Logger.frontendLogger.errorAndCrash("no VerificationService")
    5.14              return
    5.15          }
    5.16 -        verificationService.requestVerification(account: account, delegate: self)
    5.17 +        verificationService.verify(account: account)
    5.18      }
    5.19  
    5.20      func sectionIsValid(section: Int) -> Bool {
     6.1 --- a/pEpForiOSTests/AccountVerificationServiceTests.swift	Fri Apr 12 11:34:10 2019 +0200
     6.2 +++ b/pEpForiOSTests/AccountVerificationServiceTests.swift	Fri Apr 12 11:35:32 2019 +0200
     6.3 @@ -93,13 +93,13 @@
     6.4          let delegate = AccountVerificationTestDelegate(expVerified: expVerified)
     6.5  
     6.6          let asService = AccountVerificationService()
     6.7 -        let verificationService = VerificationService(parentName: #function)
     6.8 +        let verificationService = AccountVerificationService(delegate: delegate)
     6.9  
    6.10          if testDirectly {
    6.11              asService.delegate = delegate
    6.12              asService.verify(account: account)
    6.13          } else {
    6.14 -            verificationService.requestVerification(account: account, delegate: delegate)
    6.15 +            verificationService.verify(account: account)
    6.16          }
    6.17  
    6.18          waitForExpectations(timeout: TestUtil.waitTime, handler: { error in
     7.1 --- a/pEpForiOSTests/Models/Folder/FolderViewModelTest.swift	Fri Apr 12 11:34:10 2019 +0200
     7.2 +++ b/pEpForiOSTests/Models/Folder/FolderViewModelTest.swift	Fri Apr 12 11:35:32 2019 +0200
     7.3 @@ -100,10 +100,12 @@
     7.4          viewmodel = FolderViewModel(withFoldersIn: nil, includeUnifiedInbox: withUnifiedInbox)
     7.5      }
     7.6      
     7.7 -    class VerificationServiceMock: VerificationServiceProtocol {
     7.8 -        func requestVerification(account: Account, delegate: AccountVerificationServiceDelegate) {
     7.9 -            
    7.10 -        }
    7.11 +    class VerificationServiceMock: AccountVerificationServiceProtocol {
    7.12 +        var delegate: AccountVerificationServiceDelegate?
    7.13 +        var accountVerificationState  = AccountVerificationState.idle
    7.14 +
    7.15 +        func verify(account: Account) {}
    7.16 +
    7.17      }
    7.18  
    7.19  }
     8.1 --- a/pEpForiOSTests/Models/LoginViewModelTests.swift	Fri Apr 12 11:34:10 2019 +0200
     8.2 +++ b/pEpForiOSTests/Models/LoginViewModelTests.swift	Fri Apr 12 11:35:32 2019 +0200
     8.3 @@ -24,16 +24,20 @@
     8.4  }
     8.5  
     8.6  class LoginViewModelTests: CoreDataDrivenTestBase {
     8.7 -    class TestVerificationService: VerificationServiceProtocol {
     8.8 +    class TestVerificationService: AccountVerificationServiceProtocol {
     8.9 +        var delegate: AccountVerificationServiceDelegate?
    8.10 +
    8.11 +        var accountVerificationState = AccountVerificationState.idle
    8.12 +
    8.13          let accountSettings: TestDataBase.AccountSettings
    8.14          let expLookedUp: XCTestExpectation
    8.15 -
    8.16 +        
    8.17          init(accountSettings: TestDataBase.AccountSettings, expLookedUp: XCTestExpectation) {
    8.18              self.accountSettings = accountSettings
    8.19              self.expLookedUp = expLookedUp
    8.20          }
    8.21  
    8.22 -        func requestVerification(account: Account, delegate: AccountVerificationServiceDelegate) {
    8.23 +        func verify(account: Account) {
    8.24              XCTAssertEqual(account.user.address, accountSettings.idAddress)
    8.25              guard let imapServer = account.imapServer else {
    8.26                  XCTFail("expecting IMAP server")
    8.27 @@ -53,10 +57,6 @@
    8.28  
    8.29              expLookedUp.fulfill()
    8.30          }
    8.31 -
    8.32 -        func requestFetchOlderMessages(inFolder folder: Folder) {
    8.33 -            XCTFail("unexpected call to \(#function)")
    8.34 -        }
    8.35      }
    8.36  
    8.37      /// This tests makes sense only if the server settings 
     9.1 --- a/pEpForiOSTests/Models/Settings/AccountSettingsViewModelTest.swift	Fri Apr 12 11:34:10 2019 +0200
     9.2 +++ b/pEpForiOSTests/Models/Settings/AccountSettingsViewModelTest.swift	Fri Apr 12 11:35:32 2019 +0200
     9.3 @@ -132,7 +132,7 @@
     9.4      private func setUpViewModel() {
     9.5          account.save()
     9.6          viewModel = AccountSettingsViewModel(account: account)
     9.7 -        viewModel.verificationService = VerificationService()
     9.8 +        viewModel.verificationService = AccountVerificationService(delegate: viewModel)
     9.9      }
    9.10  }
    9.11