* fix(#478): rework default login to use unified ConnectionProfile model - AuthManager: drop legacy auth_token path; getToken/setToken now delegate to the selected profile (profile token only, no global fallback) - setHost/setPort always write the selected profile (no top-level host/port branch) - Add DEFAULT_PROFILE_ID + ensureDefaultProfile()/ensureDefaultSelected() so the selected profile is never null; ensureDefaultSelected() only falls back when nothing is selected (never clobbers an existing choice); ensureDefaultProfile() only injects a Default profile on fresh install, never into an existing list - One-time migration folds legacy standalone auth_token into the Default profile, batched into a single SharedPreferences transaction (guarded by legacy_default_migrated) - ConnectViewModel.connect() persists via setToken/setHost/setPort (delegate to the selected profile) — keeps the existing persistence contract - Connect/Settings: remove the '(none)'/standalone profile option; deleteProfile falls back to Default profile instead of null selection - Update AuthManagerTest/ConnectViewModelTest to the unified model; fix test stub ordering + migration re-init; remove dead connect_profile_none / settings_profile_none strings Closes #478 * fix: stub AuthManager.ensureDefaultSelected() in E2eIntegrationTest The #478 ConnectViewModel.connect() success branch now calls AuthManager.ensureDefaultSelected() on the non-saveProfile path. E2eIntegrationTest.setUp() mocks AuthManager as a non-relaxed mockkObject but never stubs that method, so the unstubbed call throws MockKException inside viewModelScope.launch, leaving connectionSuccess unset and failing 3 tests: - testFullUserSessionFlow - testConnectViewModel_onPairingString_base64Format - testConnectViewModel_onPairingString_urlFormat Add the missing stub. Verified locally: full suite 322/322 passing. --------- Co-authored-by: ronia <ronia@m57>
This commit is contained in:
1 parent
b65d0297e0
commit
aa59e704a4
11 files changed
+229
-155
No files matched your search
@@ -18,7 +18,6 @@ import kotlinx.coroutines.test.setMain
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertNull
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
|
||||
@@ -133,18 +132,18 @@ class SettingsViewModelTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testSelectProfile_nullClearsSelection() {
|
||||
fun testSelectProfile_nullFallsBackToDefault() {
|
||||
every { AuthManager.getConnectionProfiles() } returns testProfiles
|
||||
storedSelectedProfileId = "prof-1"
|
||||
|
||||
val viewModel = createViewModel()
|
||||
|
||||
viewModel.selectProfile(null)
|
||||
viewModel.selectProfile(AuthManager.DEFAULT_PROFILE_ID)
|
||||
testDispatcher.scheduler.advanceUntilIdle()
|
||||
|
||||
verify { AuthManager.setSelectedProfileId(null) }
|
||||
verify { AuthManager.setSelectedProfileId(AuthManager.DEFAULT_PROFILE_ID) }
|
||||
verify { ApiClient.rebuild() }
|
||||
assertNull(viewModel.uiState.value.selectedProfileId)
|
||||
assertEquals(AuthManager.DEFAULT_PROFILE_ID, viewModel.uiState.value.selectedProfileId)
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -199,12 +198,12 @@ class SettingsViewModelTest {
|
||||
|
||||
verify { AuthManager.saveConnectionProfiles(any()) }
|
||||
verify { AuthManager.setProfileToken("prof-1", null) }
|
||||
verify { AuthManager.setSelectedProfileId(null) }
|
||||
verify { AuthManager.setSelectedProfileId(AuthManager.DEFAULT_PROFILE_ID) }
|
||||
verify { ApiClient.rebuild() }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDeleteProfile_nonSelected_doesNotClearSelectedId() {
|
||||
fun testDeleteProfile_nonSelected_doesNotChangeSelectedId() {
|
||||
every { AuthManager.getConnectionProfiles() } returns testProfiles
|
||||
every { AuthManager.getSelectedProfileId() } returns "prof-1"
|
||||
|
||||
@@ -214,8 +213,8 @@ class SettingsViewModelTest {
|
||||
|
||||
verify { AuthManager.saveConnectionProfiles(any()) }
|
||||
verify { AuthManager.setProfileToken("prof-2", null) }
|
||||
// Selected profile (prof-1) was NOT deleted — should NOT clear selection
|
||||
verify(exactly = 0) { AuthManager.setSelectedProfileId(null) }
|
||||
// Selected profile (prof-1) was NOT deleted — should NOT change selection
|
||||
verify(exactly = 0) { AuthManager.setSelectedProfileId(any()) }
|
||||
verify { ApiClient.rebuild() }
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user