Skip to content

Commit 54c8fee

Browse files
authored
test(tokens): supply accountController to SwapViewModel (#1345)
#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.
1 parent 71644f7 commit 54c8fee

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

‎apps/flipcash/shared/tokens/src/test/kotlin/com/flipcash/app/tokens/ui/SwapViewModelErrorTest.kt‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import com.flipcash.app.tokens.TokenCoordinator
99
import com.flipcash.app.tokens.UsdcDepositSweep
1010
import com.flipcash.services.user.UserManager
1111
import com.getcode.manager.BottomBarManager
12+
import com.getcode.opencode.controllers.AccountController
1213
import com.getcode.opencode.controllers.TransactionOperations
1314
import com.getcode.opencode.exchange.Exchange
1415
import com.getcode.opencode.exchange.VerifiedFiat
@@ -58,6 +59,7 @@ class SwapViewModelErrorTest {
5859
var mainCoroutineRule = MainCoroutineRule(UnconfinedTestDispatcher())
5960

6061
private val userManager = mockk<UserManager>(relaxed = true)
62+
private val accountController = mockk<AccountController>(relaxed = true)
6163
private val exchange = mockk<Exchange>(relaxed = true)
6264
private val verifiedFiatCalculator = mockk<VerifiedFiatCalculator>(relaxed = true)
6365
// Mockito for Result-returning methods (MockK double-boxes Result inline class)
@@ -87,6 +89,11 @@ class SwapViewModelErrorTest {
8789

8890
every { userManager.accountCluster } returns accountCluster
8991

92+
// A Get asks whether the mint already has a token account to decide first-buy vs top-up.
93+
// Nothing here exercises that branch, so answer "no" rather than leaving it on a relaxed
94+
// mock's empty flow.
95+
every { accountController.observeHasAccountFor(any()) } returns MutableStateFlow(false)
96+
9097
// Stub limits StateFlow so init block doesn't NPE on null flow
9198
whenever(transactionController.limits).thenReturn(MutableStateFlow(null))
9299

@@ -107,6 +114,7 @@ class SwapViewModelErrorTest {
107114
private fun createViewModel(): SwapViewModel {
108115
return SwapViewModel(
109116
userManager = userManager,
117+
accountController = accountController,
110118
exchange = exchange,
111119
verifiedFiatCalculator = verifiedFiatCalculator,
112120
transactionController = transactionController,

0 commit comments

Comments
 (0)