merge default IOS-1661
authorbuff <andreas@pep-project.org>
Mon, 05 Aug 2019 16:12:42 +0200
branchIOS-1661
changeset 9537af29a463758f
parent 9533 04694693cb1b
parent 9536 1f84134b02d9
child 9546 6cabc4a7aa22
merge default
pEpForiOS/AppDelegate.swift
     1.1 --- a/pEpForiOS/AppDelegate.swift	Mon Aug 05 14:49:49 2019 +0200
     1.2 +++ b/pEpForiOS/AppDelegate.swift	Mon Aug 05 16:12:42 2019 +0200
     1.3 @@ -80,9 +80,8 @@
     1.4      private func gracefullyShutdownServices() {
     1.5          guard syncUserActionsAndCleanupbackgroundTaskId == UIBackgroundTaskIdentifier.invalid
     1.6              else {
     1.7 -                Log.shared.warn(
     1.8 -                    "Will not start background sync, pending %d",
     1.9 -                    syncUserActionsAndCleanupbackgroundTaskId.rawValue)
    1.10 +                Log.shared.errorAndCrash("Will not start background sync, pending %d",
    1.11 +                                         syncUserActionsAndCleanupbackgroundTaskId.rawValue)
    1.12                  return
    1.13          }
    1.14          syncUserActionsAndCleanupbackgroundTaskId =
     2.1 --- a/pEpForiOS/UI/Settings/Setting/OnOffSettings/ViewModel/EnableKeySyncViewModel.swift	Mon Aug 05 14:49:49 2019 +0200
     2.2 +++ b/pEpForiOS/UI/Settings/Setting/OnOffSettings/ViewModel/EnableKeySyncViewModel.swift	Mon Aug 05 16:12:42 2019 +0200
     2.3 @@ -16,7 +16,7 @@
     2.4      var cellIdentifier = "switchOptionCell"
     2.5      private let messageModelService: MessageModelServiceProtocol
     2.6  
     2.7 -    private(set) var title = NSLocalizedString("Key Sync Enable",
     2.8 +    private(set) var title = NSLocalizedString("Enable Key Sync",
     2.9                                                 comment: "enable key sync with other devices in the group")
    2.10  
    2.11      init(_ messageModelService: MessageModelServiceProtocol) {
     3.1 --- a/pEpForiOS/UI/Settings/ViewModel/SettingsCellViewModel.swift	Mon Aug 05 14:49:49 2019 +0200
     3.2 +++ b/pEpForiOS/UI/Settings/ViewModel/SettingsCellViewModel.swift	Mon Aug 05 16:12:42 2019 +0200
     3.3 @@ -89,6 +89,24 @@
     3.4      }
     3.5  
     3.6      func delete() {
     3.7 -        account?.delete()
     3.8 +        guard let acc = account else {
     3.9 +            Log.shared.errorAndCrash(message: "Account lost")
    3.10 +            return
    3.11 +        }
    3.12 +
    3.13 +        let oldAddress = acc.user.address
    3.14 +        acc.delete()
    3.15 +
    3.16 +        if AppSettings.defaultAccount == oldAddress {
    3.17 +            let newDefaultAccount = Account.all().first
    3.18 +            guard let newDefaultAddress = newDefaultAccount?.user.address else {
    3.19 +                return
    3.20 +                //no more accounts, no default account
    3.21 +            }
    3.22 +            AppSettings.defaultAccount = newDefaultAddress
    3.23 +        }
    3.24 +
    3.25      }
    3.26 +
    3.27 +
    3.28  }
     4.1 --- a/pEpForiOSTests/Models/Settings/SettingsViewModelTest.swift	Mon Aug 05 14:49:49 2019 +0200
     4.2 +++ b/pEpForiOSTests/Models/Settings/SettingsViewModelTest.swift	Mon Aug 05 16:12:42 2019 +0200
     4.3 @@ -16,6 +16,11 @@
     4.4      var keySyncDeviceGroupServiceMoc: KeySyncDeviceGroupServiceMoc!
     4.5      var messageModelServiceMoc: MessageModelServiceMoc!
     4.6  
     4.7 +    func givenThereAreTwoAccounts() {
     4.8 +        _ = SecretTestData().createWorkingCdAccount(number: 1, context: moc)
     4.9 +        moc.saveAndLogErrors()
    4.10 +    }
    4.11 +
    4.12  
    4.13      //Number of sections corresponding to SettingsSectionViewModel.SectionType count
    4.14      let sections = 4
    4.15 @@ -54,9 +59,25 @@
    4.16          XCTAssertTrue(thereIsOneLessAccount)
    4.17      }
    4.18  
    4.19 -    func givenThereAreTwoAccounts() {
    4.20 -        _ = SecretTestData().createWorkingCdAccount(number: 1, context: moc)
    4.21 -        moc.saveAndLogErrors()
    4.22 +    func testDeleteAccountWithMoreThanOneAccountUpdatesDefaultAccount() {
    4.23 +
    4.24 +        givenThereAreTwoAccounts()
    4.25 +        setupViewModel()
    4.26 +
    4.27 +        let firstAccountPosition = (0,0)
    4.28 +        let secondAccountPosition = (0,0)
    4.29 +        let defaultAddress = (settingsVM[0][0] as? SettingsCellViewModel)?.account?.user.address
    4.30 +
    4.31 +        AppSettings.defaultAccount = defaultAddress
    4.32 +        XCTAssertEqual(AppSettings.defaultAccount, defaultAddress)
    4.33 +
    4.34 +        settingsVM.delete(section: firstAccountPosition.0, cell: firstAccountPosition.1)
    4.35 +
    4.36 +        XCTAssertNotEqual(AppSettings.defaultAccount, defaultAddress)
    4.37 +        XCTAssertNotNil(AppSettings.defaultAccount)
    4.38 +        let newDefaultAddress = (settingsVM[secondAccountPosition.0][secondAccountPosition.1] as? SettingsCellViewModel)?.account?.user.address
    4.39 +        XCTAssertEqual(AppSettings.defaultAccount, newDefaultAddress)
    4.40 +
    4.41      }
    4.42  
    4.43      func testLeaveDeviceGroupPressed() {