From 88276588e6abab82ebe7a7d84be482f93063da33 Mon Sep 17 00:00:00 2001 From: Brandon McAnsh Date: Thu, 27 Aug 2026 15:49:40 -0400 Subject: [PATCH] test(tokens): supply accountController to SwapViewModel #1341 added a required `accountController` parameter to `SwapViewModel` and changed only `SwapViewModel.kt`, so `SwapViewModelErrorTest.createViewModel()` still calls the old constructor. The module's unit tests have not compiled since it merged, which fails every PR built against `code/cash`. Add the mock in constructor order and stub `observeHasAccountFor` to return false. Nothing in this file exercises the first-buy/top-up branch it feeds, and an explicit answer is steadier than a relaxed mock's empty flow. `SwapViewModelStateTest` never constructs the view model, so it needs nothing. --- .../com/flipcash/app/tokens/ui/SwapViewModelErrorTest.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apps/flipcash/shared/tokens/src/test/kotlin/com/flipcash/app/tokens/ui/SwapViewModelErrorTest.kt b/apps/flipcash/shared/tokens/src/test/kotlin/com/flipcash/app/tokens/ui/SwapViewModelErrorTest.kt index f8ab546d6..3b77ba4f6 100644 --- a/apps/flipcash/shared/tokens/src/test/kotlin/com/flipcash/app/tokens/ui/SwapViewModelErrorTest.kt +++ b/apps/flipcash/shared/tokens/src/test/kotlin/com/flipcash/app/tokens/ui/SwapViewModelErrorTest.kt @@ -9,6 +9,7 @@ import com.flipcash.app.tokens.TokenCoordinator import com.flipcash.app.tokens.UsdcDepositSweep import com.flipcash.services.user.UserManager import com.getcode.manager.BottomBarManager +import com.getcode.opencode.controllers.AccountController import com.getcode.opencode.controllers.TransactionOperations import com.getcode.opencode.exchange.Exchange import com.getcode.opencode.exchange.VerifiedFiat @@ -58,6 +59,7 @@ class SwapViewModelErrorTest { var mainCoroutineRule = MainCoroutineRule(UnconfinedTestDispatcher()) private val userManager = mockk(relaxed = true) + private val accountController = mockk(relaxed = true) private val exchange = mockk(relaxed = true) private val verifiedFiatCalculator = mockk(relaxed = true) // Mockito for Result-returning methods (MockK double-boxes Result inline class) @@ -87,6 +89,11 @@ class SwapViewModelErrorTest { every { userManager.accountCluster } returns accountCluster + // A Get asks whether the mint already has a token account to decide first-buy vs top-up. + // Nothing here exercises that branch, so answer "no" rather than leaving it on a relaxed + // mock's empty flow. + every { accountController.observeHasAccountFor(any()) } returns MutableStateFlow(false) + // Stub limits StateFlow so init block doesn't NPE on null flow whenever(transactionController.limits).thenReturn(MutableStateFlow(null)) @@ -107,6 +114,7 @@ class SwapViewModelErrorTest { private fun createViewModel(): SwapViewModel { return SwapViewModel( userManager = userManager, + accountController = accountController, exchange = exchange, verifiedFiatCalculator = verifiedFiatCalculator, transactionController = transactionController,