IOS-1740 fix testSavePasswordAfterEndVerification test in AccountSettingsViewModelTest IOS-1740
authorAlejandro Gelos <agp@pep.security>
Tue, 20 Aug 2019 13:52:25 +0200
branchIOS-1740
changeset 9725efdbdfc23000
parent 9724 23a57a9beeb1
child 9726 28adceb916e6
IOS-1740 fix testSavePasswordAfterEndVerification test in AccountSettingsViewModelTest
pEpForiOSTests/Models/Settings/AccountSettingsViewModelTest.swift
     1.1 --- a/pEpForiOSTests/Models/Settings/AccountSettingsViewModelTest.swift	Mon Aug 19 13:43:37 2019 +0200
     1.2 +++ b/pEpForiOSTests/Models/Settings/AccountSettingsViewModelTest.swift	Tue Aug 20 13:52:25 2019 +0200
     1.3 @@ -7,6 +7,7 @@
     1.4  //
     1.5  
     1.6  import XCTest
     1.7 +import PantomimeFramework
     1.8  @testable import pEpForiOS
     1.9  @testable import MessageModel
    1.10  
    1.11 @@ -138,24 +139,49 @@
    1.12      public func testSavePasswordAfterEndVerification() {
    1.13          // GIVEN
    1.14          setUpViewModel()
    1.15 -        let successResult: Result<Void, Error> = .success(())
    1.16 -        let expectedPassword = "passwordChanged"
    1.17 -        let imap = AccountSettingsViewModel.ServerViewModel(address: nil, port: nil, transport: nil)
    1.18 -        let smtp = AccountSettingsViewModel.ServerViewModel(address: nil, port: nil, transport: nil)
    1.19 -        viewModel.update(loginName: "", name: "", password: expectedPassword, imap: imap, smtp: smtp)
    1.20 +        guard let imapPort = account.imapServer?.port,
    1.21 +            let smtpPort = account.smtpServer?.port else {
    1.22 +                XCTFail()
    1.23 +                return
    1.24 +        }
    1.25 +        let correctPwd = account.imapServer?.credentials.password
    1.26 +        let wrongPwd = "Wrong Password"
    1.27 +        account.imapServer?.credentials.password = wrongPwd
    1.28 +
    1.29 +        let savedExpectation = expectation(description: "Did save expectation")
    1.30 +        let verifiableAccount = VerifiableAccount(messageModelService: viewModel.messageModelService,
    1.31 +                                                  address: account.user.address,
    1.32 +                                                  userName: account.user.userName,
    1.33 +                                                  loginName: account.imapServer!.credentials.loginName,
    1.34 +                                                  password: correctPwd,
    1.35 +                                                  serverIMAP: account.imapServer?.address,
    1.36 +                                                  portIMAP: imapPort,
    1.37 +                                                  transportIMAP: ConnectionTransport.init(transport: account.imapServer!.transport),
    1.38 +                                                  serverSMTP: account.smtpServer?.address,
    1.39 +                                                  portSMTP: smtpPort,
    1.40 +                                                  transportSMTP: ConnectionTransport.init(transport: account.smtpServer!.transport),
    1.41 +                                                  automaticallyTrustedImapServer: true)
    1.42 +
    1.43  
    1.44          // WHEN
    1.45 -        viewModel.didEndVerification(result: successResult)
    1.46 +        try? verifiableAccount.save { _ in
    1.47 +            savedExpectation.fulfill()
    1.48 +        }
    1.49  
    1.50          // THEN
    1.51 -        let connectionInfo = account.cdObject.imapConnectInfo
    1.52 -        let actualPassword = connectionInfo?.loginPassword
    1.53 -        XCTAssertEqual(actualPassword, expectedPassword)
    1.54 +        waitForExpectations(timeout: UnitTestUtils.asyncWaitTime)
    1.55 +        let actualPassword = account.imapServer?.credentials.password
    1.56 +        XCTAssertEqual(actualPassword, correctPwd)
    1.57      }
    1.58  
    1.59  
    1.60      private func setUpViewModel() {
    1.61 -        account.save()
    1.62 +        let inbox = CdFolder(context: moc)
    1.63 +        inbox.account = account.cdObject
    1.64 +        inbox.folderType = .inbox
    1.65 +        inbox.name = ImapSync.defaultImapInboxName
    1.66 +        moc.saveAndLogErrors()
    1.67 +
    1.68          keySyncServiceHandshakeDelegateMoc = KeySyncServiceHandshakeDelegateMoc()
    1.69          let theMessageModelService = MessageModelService(
    1.70              errorPropagator: ErrorPropagator(),