From 22c6a8a1bcd18045873158df76bc196503814bdb Mon Sep 17 00:00:00 2001 From: Brandon McAnsh Date: Wed, 5 Aug 2026 14:59:30 -0400 Subject: [PATCH] test(auth): fix AuthManager onboarding-resume tests for display-name gate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The onboarding display-name change reordered AuthManager.login()'s resume logic: a missing display name now resumes at ResumePoint.DisplayName (after the access key) before falling through to PostAccessKey. The existing AuthManagerTest cases mocked a relaxed UserManager whose profile was null, so displayNameMissing was true and the registered / flags-exhausted cases resolved to DisplayName instead of the asserted PostAccessKey — failing on code/cash after the merge. - Default the mocked profile to one with a display name in setUp, so the post-access-key resume paths behave as before. - Add coverage for the new DisplayName resume path (access key seen, registered, no display name set). --- .../com/flipcash/app/auth/AuthManagerTest.kt | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/apps/flipcash/shared/authentication/src/test/kotlin/com/flipcash/app/auth/AuthManagerTest.kt b/apps/flipcash/shared/authentication/src/test/kotlin/com/flipcash/app/auth/AuthManagerTest.kt index 9dc861a89..d9dfee698 100644 --- a/apps/flipcash/shared/authentication/src/test/kotlin/com/flipcash/app/auth/AuthManagerTest.kt +++ b/apps/flipcash/shared/authentication/src/test/kotlin/com/flipcash/app/auth/AuthManagerTest.kt @@ -16,6 +16,7 @@ import com.flipcash.services.controllers.AccountController import com.flipcash.services.controllers.ProfileController import com.flipcash.services.controllers.PushController import com.flipcash.services.models.UserFlags +import com.flipcash.services.models.UserProfile import com.flipcash.services.user.AuthState import com.flipcash.services.user.UserManager import io.mockk.coEvery @@ -75,6 +76,11 @@ class AuthManagerTest { Dispatchers.setMain(testDispatcher) every { userManager.state } returns userManagerState + // Default to a profile that already has a display name so onboarding resume falls through + // to the post-access-key path. Tests exercising the DisplayName step override this. + every { userManager.profile } returns mockk(relaxed = true) { + every { displayName } returns "Test User" + } every { networkConnectivityListener.isConnected } returns true coEvery { pushTokenProvider.getToken() } returns "fake-token" @@ -288,6 +294,30 @@ class AuthManagerTest { verify { userManager.set(AuthState.Onboarding(AuthState.ResumePoint.PostAccessKey)) } } + @Test + fun `login resumes at DisplayName when access key seen but no display name set`() = runTest { + val entropy = "dGVzdGVudHJvcHkxMjM0NQ==" + val accountMetadata: AccountMetadata = mockk(relaxed = true) + val testId = listOf(1, 2, 3) + every { accountMetadata.id } returns testId + + coEvery { credentialManager.login(entropy, any()) } returns Result.success(accountMetadata) + coEvery { credentialManager.hasCompletedOnboarding() } returns false + // Access key seen, registered, but the display name hasn't been set yet. + every { userManager.profile } returns mockk(relaxed = true) { + every { displayName } returns "" + } + + val flags = UserFlags.Default.copy(isRegistered = true) + coEvery { accountController.getUserFlags() } returns Result.success(flags) + + val result = authManager.login(entropyB64 = entropy) + + assertTrue(result.isSuccess) + verify { userManager.set(flags) } + verify { userManager.set(AuthState.Onboarding(AuthState.ResumePoint.DisplayName)) } + } + @Test fun `login falls back to Ready when flags exhausted but onboarding completed`() = runTest { val entropy = "dGVzdGVudHJvcHkxMjM0NQ=="