Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/flipcash/features/cash/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ android {
dependencies {
testImplementation(kotlin("test"))
testImplementation(libs.bundles.unit.testing)
testImplementation(testFixtures(project(":ui:resources")))
testImplementation(libs.mockito.kotlin)
testImplementation(libs.robolectric)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import com.flipcash.app.core.MainCoroutineRule
import com.flipcash.app.core.dispatchers.TestDispatchers
import com.flipcash.app.tokens.TokenCoordinator
import com.flipcash.features.cash.R
import com.getcode.manager.BottomBarManager
import com.getcode.opencode.controllers.TransactionOperations
import com.getcode.opencode.exchange.Exchange
Expand All @@ -19,7 +18,7 @@ import com.getcode.opencode.model.financial.SendLimit
import com.getcode.opencode.model.financial.Token
import com.getcode.opencode.model.financial.TokenWithLocalizedBalance
import com.getcode.solana.keys.Mint
import com.getcode.util.resources.ResourceHelper
import com.getcode.util.resources.FakeResourceHelper
import io.mockk.every
import io.mockk.mockk
import kotlinx.coroutines.ExperimentalCoroutinesApi
Expand All @@ -45,7 +44,7 @@ class CashScreenViewModelTest {
@get:Rule
var mainCoroutineRule = MainCoroutineRule(UnconfinedTestDispatcher())

private val resources: ResourceHelper = mockk(relaxed = true)
private val resources = FakeResourceHelper()
private val exchange: Exchange = mockk(relaxed = true)
private val verifiedFiatCalculator: VerifiedFiatCalculator = mockk(relaxed = true)
private val tokenCoordinator: TokenCoordinator = mockk(relaxed = true)
Expand All @@ -59,14 +58,6 @@ class CashScreenViewModelTest {
fun setUp() {
BottomBarManager.clear()

// Stub resource strings used by the ViewModel
every { resources.getString(R.string.error_title_youNeedMoreCash) } returns "error_title_youNeedMoreCash"
every { resources.getString(R.string.error_description_youNeedMoreCash) } returns "error_description_youNeedMoreCash"
every { resources.getString(R.string.action_addMoreCash) } returns "action_addMoreCash"
every { resources.getString(R.string.action_dismiss) } returns "action_dismiss"
every { resources.getString(R.string.error_title_sendLimitReached) } returns "error_title_sendLimitReached"
every { resources.getString(R.string.error_description_sendLimitReached) } returns "error_description_sendLimitReached"

// Default stubs for flows consumed in init
every { exchange.observePreferredRate() } returns emptyFlow()
every { exchange.preferredRate } returns Rate.oneToOne
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ android {
dependencies {
testImplementation(kotlin("test"))
testImplementation(libs.bundles.unit.testing)
testImplementation(testFixtures(project(":ui:resources")))
testImplementation(libs.mockito.kotlin)

implementation(libs.bundles.kotlinx.serialization)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package com.flipcash.app.contact.verification.internal.email

import com.flipcash.features.contact.verification.R
import com.flipcash.app.core.verification.email.EmailCodeChannel
import com.flipcash.services.controllers.ContactVerificationController
import com.flipcash.services.controllers.ProfileController
import com.flipcash.services.models.EmailVerificationError
import com.getcode.manager.BottomBarManager
import com.getcode.util.resources.ResourceHelper
import com.getcode.util.resources.FakeResourceHelper
import com.flipcash.app.core.MainCoroutineRule
import com.flipcash.app.core.dispatchers.TestDispatchers
import io.mockk.every
import io.mockk.mockk
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.UnconfinedTestDispatcher
Expand All @@ -33,26 +31,13 @@ class EmailVerificationViewModelErrorTest {
// Mockito for Result-returning methods (MockK double-boxes Result inline class)
private val verificationController: ContactVerificationController = mock()
private val profileController = mockk<ProfileController>(relaxed = true)
private val resources = mockk<ResourceHelper>(relaxed = true)
private val resources = FakeResourceHelper()

private lateinit var dispatchers: TestDispatchers

@Before
fun setUp() {
BottomBarManager.clear()

every { resources.getString(R.string.error_title_failedToSendCodeToEmail) } returns "error_title_failedToSendCodeToEmail"
every { resources.getString(R.string.error_description_failedToSendCodeToEmail) } returns "error_description_failedToSendCodeToEmail"
every { resources.getString(R.string.error_title_maxAttemptsReached) } returns "error_title_maxAttemptsReached"
every { resources.getString(R.string.error_description_maxAttemptsReached) } returns "error_description_maxAttemptsReached"
every { resources.getString(R.string.error_title_emailVerificationFailed) } returns "error_title_emailVerificationFailed"
every { resources.getString(R.string.error_description_emailVerificationFailed) } returns "error_description_emailVerificationFailed"
every { resources.getString(R.string.error_title_emailVerificationLinkInvalid) } returns "error_title_emailVerificationLinkInvalid"
every { resources.getString(R.string.error_description_emailVerificationLinkInvalid) } returns "error_description_emailVerificationLinkInvalid"
every { resources.getString(R.string.error_title_emailVerificationLinkExpired) } returns "error_title_emailVerificationLinkExpired"
every { resources.getString(R.string.error_description_emailVerificationLinkExpired) } returns "error_description_emailVerificationLinkExpired"
every { resources.getString(R.string.action_resendVerificationEmail) } returns "action_resendVerificationEmail"
every { resources.getString(R.string.action_ok) } returns "OK"
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,14 @@ package com.flipcash.app.contact.verification.internal.phone

import com.flipcash.app.featureflags.FeatureFlagController
import com.flipcash.app.phone.PhoneUtils
import com.flipcash.features.contact.verification.R
import com.flipcash.services.controllers.ContactVerificationController
import com.flipcash.services.controllers.ProfileController
import com.flipcash.services.models.PhoneVerificationError
import com.flipcash.services.user.UserManager
import com.getcode.manager.BottomBarManager
import com.getcode.util.resources.ResourceHelper
import com.getcode.util.resources.FakeResourceHelper
import com.flipcash.app.core.MainCoroutineRule
import com.flipcash.app.core.dispatchers.TestDispatchers
import io.mockk.every
import io.mockk.mockk
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.UnconfinedTestDispatcher
Expand All @@ -38,22 +36,13 @@ class PhoneVerificationViewModelErrorTest {
private val profileController = mockk<ProfileController>(relaxed = true)
private val userManager = mockk<UserManager>(relaxed = true)
private val featureFlags = mockk<FeatureFlagController>(relaxed = true)
private val resources = mockk<ResourceHelper>(relaxed = true)
private val resources = FakeResourceHelper()

private lateinit var dispatchers: TestDispatchers

@Before
fun setUp() {
BottomBarManager.clear()

every { resources.getString(R.string.error_title_failedToSendCodeToPhone) } returns "error_title_failedToSendCodeToPhone"
every { resources.getString(R.string.error_description_failedToSendCodeToPhone) } returns "error_description_failedToSendCodeToPhone"
every { resources.getString(R.string.error_title_maxAttemptsReached) } returns "error_title_maxAttemptsReached"
every { resources.getString(R.string.error_description_maxAttemptsReached) } returns "error_description_maxAttemptsReached"
every { resources.getString(R.string.error_title_deviceNotSupported) } returns "error_title_deviceNotSupported"
every { resources.getString(R.string.error_description_deviceNotSupported) } returns "error_description_deviceNotSupported"
every { resources.getString(R.string.error_description_invalidVerificationCode) } returns "error_description_invalidVerificationCode"
every { resources.getString(R.string.error_description_codeTimedOut) } returns "error_description_codeTimedOut"
}

@After
Expand Down
1 change: 1 addition & 0 deletions apps/flipcash/features/login/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ android {
dependencies {
testImplementation(kotlin("test"))
testImplementation(libs.bundles.unit.testing)
testImplementation(testFixtures(project(":ui:resources")))
testImplementation(libs.mockito.kotlin)

implementation(project(":apps:flipcash:shared:accesskey"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@ import com.flipcash.app.auth.AuthManager
import com.flipcash.app.featureflags.FeatureFlagController
import com.flipcash.app.core.MainCoroutineRule
import com.flipcash.app.core.dispatchers.TestDispatchers
import com.flipcash.features.login.R
import com.flipcash.services.controllers.AccountController
import com.flipcash.services.user.UserManager
import com.getcode.manager.BottomBarManager
import com.getcode.util.resources.ResourceHelper
import com.getcode.util.resources.FakeResourceHelper
import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkStatic
Expand Down Expand Up @@ -41,7 +40,7 @@ class LoginViewModelErrorTest {
private val accounts: AccountController = mock()

// MockK for everything else
private val resources: ResourceHelper = mockk(relaxed = true)
private val resources = FakeResourceHelper()
private val analytics: FlipcashAnalyticsService = mockk(relaxed = true)
private val userManager: UserManager = mockk(relaxed = true)
private val featureFlags: FeatureFlagController = mockk(relaxed = true)
Expand All @@ -54,10 +53,6 @@ class LoginViewModelErrorTest {
// android.util.Base64 is stubbed in unit tests; mock it so encodeBase64() doesn't NPE
mockkStatic(android.util.Base64::class)
every { android.util.Base64.encodeToString(any(), any()) } answers { java.util.Base64.getEncoder().encodeToString(firstArg()) }
every { resources.getString(R.string.error_title_createAccountFailed) } returns "error_title_createAccountFailed"
every { resources.getString(R.string.error_description_createAccountFailed) } returns "error_description_createAccountFailed"
every { resources.getString(R.string.error_title_loginFailed) } returns "error_title_loginFailed"
every { resources.getString(R.string.error_description_loginFailed) } returns "error_description_loginFailed"
}

@After
Expand Down
1 change: 1 addition & 0 deletions apps/flipcash/features/transactions/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ android {
dependencies {
testImplementation(kotlin("test"))
testImplementation(libs.bundles.unit.testing)
testImplementation(testFixtures(project(":ui:resources")))
testImplementation(libs.mockito.kotlin)

implementation(libs.compose.paging)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package com.flipcash.app.transactions.internal
import com.flipcash.app.activityfeed.ActivityFeedCoordinator
import com.flipcash.app.featureflags.FeatureFlagController
import com.flipcash.app.tokens.TokenCoordinator
import com.flipcash.features.transactions.R
import com.flipcash.services.user.UserManager
import com.getcode.manager.BottomBarManager
import com.getcode.opencode.controllers.TransactionOperations
import com.getcode.opencode.model.accounts.AccountCluster
import com.getcode.solana.keys.PublicKey
import com.getcode.util.resources.ResourceHelper
import com.getcode.util.resources.FakeResourceHelper
import com.flipcash.app.core.MainCoroutineRule
import com.flipcash.app.core.dispatchers.TestDispatchers
import io.mockk.every
Expand Down Expand Up @@ -39,7 +38,7 @@ class TransactionHistoryViewModelErrorTest {
private val transactionController: TransactionOperations = mock()
private val featureFlags = mockk<FeatureFlagController>(relaxed = true)
private val userManager = mockk<UserManager>(relaxed = true)
private val resources = mockk<ResourceHelper>(relaxed = true)
private val resources = FakeResourceHelper()

private val accountCluster = mockk<AccountCluster>(relaxed = true)

Expand All @@ -50,8 +49,6 @@ class TransactionHistoryViewModelErrorTest {
BottomBarManager.clear()

every { userManager.accountCluster } returns accountCluster
every { resources.getString(R.string.error_title_failedToCancelTransfer) } returns "error_title_failedToCancelTransfer"
every { resources.getString(R.string.error_description_failedToCancelTransfer) } returns "error_description_failedToCancelTransfer"
}

@After
Expand Down
1 change: 1 addition & 0 deletions apps/flipcash/features/withdrawal/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ android {
dependencies {
testImplementation(kotlin("test"))
testImplementation(libs.bundles.unit.testing)
testImplementation(testFixtures(project(":ui:resources")))
testImplementation(libs.bundles.compose.ui.testing)

implementation(project(":apps:flipcash:shared:amount-entry"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import com.flipcash.app.activityfeed.ActivityFeedCoordinator
import com.flipcash.app.analytics.FlipcashAnalyticsService
import com.flipcash.app.tokens.TokenCoordinator
import com.flipcash.app.userflags.UserFlagsCoordinator
import com.flipcash.features.withdrawal.R
import com.flipcash.services.user.UserManager
import com.getcode.manager.BottomBarManager
import com.getcode.opencode.controllers.TransactionOperations
import com.getcode.opencode.exchange.Exchange
import com.getcode.opencode.exchange.VerifiedFiatCalculator
import com.getcode.util.resources.ResourceHelper
import com.getcode.util.resources.FakeResourceHelper
import com.flipcash.app.core.MainCoroutineRule
import com.flipcash.app.core.dispatchers.TestDispatchers
import io.mockk.every
Expand All @@ -32,7 +31,7 @@ class WithdrawalViewModelErrorTest {
@get:Rule
var mainCoroutineRule = MainCoroutineRule(UnconfinedTestDispatcher())

private val resources = mockk<ResourceHelper>(relaxed = true)
private val resources = FakeResourceHelper()
private val exchange = mockk<Exchange>(relaxed = true)
private val verifiedFiatCalculator = mockk<VerifiedFiatCalculator>(relaxed = true)
private val userManager = mockk<UserManager>(relaxed = true)
Expand All @@ -48,9 +47,6 @@ class WithdrawalViewModelErrorTest {
@Before
fun setUp() {
BottomBarManager.clear()

every { resources.getString(R.string.error_title_failedWithdrawal) } returns "error_title_failedWithdrawal"
every { resources.getString(R.string.error_description_failedWithdrawal) } returns "error_description_failedWithdrawal"
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.test.TestCoroutineScheduler
import kotlinx.coroutines.test.advanceUntilIdle
import kotlinx.coroutines.test.advanceTimeBy
import kotlinx.coroutines.test.runCurrent
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Test
Expand Down Expand Up @@ -124,7 +125,8 @@ class ChatCoordinatorEagerBalanceTest {
triggerCollection()
val amount = Fiat(fiat = 5.0, currencyCode = CurrencyCode.CAD)
chatUpdatesChannel.send(chatUpdate(cashMessage(senderId = otherId, amount = amount)))
advanceUntilIdle()
advanceTimeBy(1_000)
runCurrent()

coVerify(exactly = 1) { tokenCoordinator.add(mint, amount) }
coordinator.reset()
Expand All @@ -134,7 +136,8 @@ class ChatCoordinatorEagerBalanceTest {
fun `self-sent cash message does not trigger tokenCoordinator add`() = runTest(testDispatchers.dispatcher) {
triggerCollection()
chatUpdatesChannel.send(chatUpdate(cashMessage(senderId = selfId)))
advanceUntilIdle()
advanceTimeBy(1_000)
runCurrent()

coVerify(exactly = 0) { tokenCoordinator.add(any<Mint>(), any()) }
coordinator.reset()
Expand All @@ -144,7 +147,8 @@ class ChatCoordinatorEagerBalanceTest {
fun `text message does not trigger tokenCoordinator add`() = runTest(testDispatchers.dispatcher) {
triggerCollection()
chatUpdatesChannel.send(chatUpdate(textMessage(senderId = otherId)))
advanceUntilIdle()
advanceTimeBy(1_000)
runCurrent()

coVerify(exactly = 0) { tokenCoordinator.add(any<Mint>(), any()) }
coordinator.reset()
Expand All @@ -160,7 +164,8 @@ class ChatCoordinatorEagerBalanceTest {
val msg2 = cashMessage(senderId = otherId, amount = amount2, mint = mintB).copy(messageId = 3L)

chatUpdatesChannel.send(chatUpdate(msg1, msg2))
advanceUntilIdle()
advanceTimeBy(1_000)
runCurrent()

coVerify(exactly = 1) { tokenCoordinator.add(mint, amount1) }
coVerify(exactly = 1) { tokenCoordinator.add(mintB, amount2) }
Expand All @@ -174,7 +179,8 @@ class ChatCoordinatorEagerBalanceTest {
val outgoing = cashMessage(senderId = selfId).copy(messageId = 3L)

chatUpdatesChannel.send(chatUpdate(incoming, outgoing))
advanceUntilIdle()
advanceTimeBy(1_000)
runCurrent()

coVerify(exactly = 1) { tokenCoordinator.add(any<Mint>(), any()) }
coordinator.reset()
Expand Down
1 change: 1 addition & 0 deletions apps/flipcash/shared/session/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ android {
dependencies {
testImplementation(kotlin("test"))
testImplementation(libs.bundles.unit.testing)
testImplementation(testFixtures(project(":ui:resources")))

implementation(project(":apps:flipcash:shared:chat"))
implementation(project(":apps:flipcash:shared:contacts"))
Expand Down
Loading
Loading