-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e1b7d31
commit b962f73
Showing
21 changed files
with
218 additions
and
47 deletions.
There are no files selected for viewing
6 changes: 0 additions & 6 deletions
6
common/src/main/kotlin/br/com/stonks/common/di/CommonModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,11 @@ | ||
package br.com.stonks.common.di | ||
|
||
import android.content.res.AssetManager | ||
import com.google.gson.Gson | ||
import org.koin.android.ext.koin.androidApplication | ||
import org.koin.dsl.module | ||
|
||
val commonModule = module { | ||
|
||
factory { | ||
Gson() | ||
} | ||
|
||
factory<AssetManager> { | ||
androidApplication().assets | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
common/src/test/kotlin/br/com/stonks/common/di/CommonModuleTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package br.com.stonks.common.di | ||
|
||
import android.app.Application | ||
import android.content.Context | ||
import io.mockk.mockk | ||
import io.mockk.mockkClass | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.koin.android.ext.koin.androidContext | ||
import org.koin.dsl.koinApplication | ||
import org.koin.test.KoinTest | ||
import org.koin.test.check.checkModules | ||
import org.koin.test.mock.MockProviderRule | ||
|
||
class CommonModuleTest : KoinTest { | ||
|
||
@get:Rule | ||
val mockProvider = MockProviderRule.create { clazz -> | ||
mockkClass(clazz) | ||
} | ||
|
||
@Test | ||
fun `given common di module then check dependency injections`() { | ||
koinApplication { | ||
androidContext(mockk(relaxed = true)) | ||
modules(commonModule) | ||
checkModules { | ||
withInstance<Application>() | ||
withInstance<Context>() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,6 @@ android { | |
|
||
dependencies { | ||
implementation(projects.common) | ||
|
||
testImplementation(libs.bundles.test.jvm) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 0 additions & 10 deletions
10
design-system/src/main/kotlin/br/com/stonks/designsystem/tokens/ShapeSizeToken.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions
6
...home/src/main/kotlin/br/com/stonks/feature/home/domain/usecase/DailyTransactionUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
package br.com.stonks.feature.home.domain.usecase | ||
|
||
import br.com.stonks.common.utils.asFlow | ||
import br.com.stonks.feature.home.domain.mapper.DailyTransactionMapper | ||
import br.com.stonks.feature.home.domain.mapper.DailyTransactionResponseToModelMapper | ||
import br.com.stonks.feature.home.domain.model.DailyTransactionModel | ||
import br.com.stonks.feature.home.repository.HomeRepository | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
internal class DailyTransactionUseCase( | ||
private val homeRepository: HomeRepository, | ||
private val dailyTransactionMapper: DailyTransactionMapper, | ||
private val dailyTransactionModelMapper: DailyTransactionResponseToModelMapper, | ||
) { | ||
|
||
suspend operator fun invoke(): Flow<List<DailyTransactionModel>> { | ||
return homeRepository.getTransactions().mapCatching { | ||
dailyTransactionMapper.mapper(it) | ||
dailyTransactionModelMapper.mapper(it) | ||
}.asFlow() | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
feature/home/src/main/kotlin/br/com/stonks/feature/home/domain/usecase/WalletUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
package br.com.stonks.feature.home.domain.usecase | ||
|
||
import br.com.stonks.common.utils.asFlow | ||
import br.com.stonks.feature.home.domain.mapper.WalletMapper | ||
import br.com.stonks.feature.home.domain.mapper.WalletResponseToModelMapper | ||
import br.com.stonks.feature.home.domain.model.WalletModel | ||
import br.com.stonks.feature.home.repository.HomeRepository | ||
import kotlinx.coroutines.flow.Flow | ||
|
||
internal class WalletUseCase( | ||
private val homeRepository: HomeRepository, | ||
private val walletMapper: WalletMapper, | ||
private val walletModelMapper: WalletResponseToModelMapper, | ||
) { | ||
|
||
suspend operator fun invoke(): Flow<WalletModel> { | ||
return homeRepository.getWallet().mapCatching { | ||
walletMapper.mapper(it) | ||
walletModelMapper.mapper(it) | ||
}.asFlow() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
...rc/test/kotlin/br/com/stonks/feature/home/domain/domain/usecase/HomeContentUseCaseTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package br.com.stonks.feature.home.domain.domain.usecase | ||
|
||
import app.cash.turbine.test | ||
import br.com.stonks.feature.home.domain.model.DailyTransactionModel | ||
import br.com.stonks.feature.home.domain.model.HomeContentModel | ||
import br.com.stonks.feature.home.domain.model.WalletModel | ||
import br.com.stonks.feature.home.domain.usecase.DailyTransactionUseCase | ||
import br.com.stonks.feature.home.domain.usecase.HomeContentUseCase | ||
import br.com.stonks.feature.home.domain.usecase.WalletUseCase | ||
import io.mockk.coEvery | ||
import io.mockk.mockk | ||
import kotlinx.coroutines.flow.flowOf | ||
import kotlinx.coroutines.test.runTest | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
import java.util.Date | ||
|
||
class HomeContentUseCaseTest { | ||
|
||
private val currentDate = Date() | ||
private val walletUseCaseMock = mockk<WalletUseCase>() | ||
private val dailyTransactionUseCaseMock = mockk<DailyTransactionUseCase>() | ||
private val sut = HomeContentUseCase(walletUseCaseMock, dailyTransactionUseCaseMock) | ||
|
||
@Test | ||
fun `given use case when fetch data with success then return valid result`() = runTest { | ||
coEvery { walletUseCaseMock() } returns flowOf(fakeWallet) | ||
coEvery { dailyTransactionUseCaseMock() } returns flowOf(fakeTransaction) | ||
|
||
sut.fetchData().test { | ||
assertEquals(fakeHomeContent(), awaitItem()) | ||
awaitComplete() | ||
} | ||
} | ||
|
||
private fun fakeHomeContent() = HomeContentModel( | ||
wallet = fakeWallet, | ||
dailyTransactions = fakeTransaction, | ||
) | ||
|
||
private val fakeWallet = WalletModel( | ||
availableBalance = 1.0, | ||
investedBalance = 1.0, | ||
totalAssets = 2.0, | ||
portfolio = emptyList(), | ||
) | ||
|
||
private val fakeTransaction = listOf( | ||
DailyTransactionModel( | ||
date = currentDate, | ||
dailyBalance = 1.0, | ||
transactions = emptyList(), | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.