Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating sprint domain module #236

Merged
merged 1 commit into from
May 31, 2024
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 app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ dependencies {
kover(project(":domain:common"))
kover(project(":domain:races"))
kover(project(":domain:raceresults"))
kover(project(":domain:sprintresults"))
kover(project(":feature:standings"))
kover(project(":feature:settings"))
kover(project(":feature:races"))
Expand Down
1 change: 1 addition & 0 deletions domain/sprintresults/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
17 changes: 17 additions & 0 deletions domain/sprintresults/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
plugins {
id("boxbox.android.library")
id("boxbox.android.hilt")
}

android {
namespace = "com.toquete.boxbox.domain.sprintresults"
}

dependencies {
implementation(project(":core:model"))
implementation(project(":core:common"))
implementation(project(":data:sprintresults"))
implementation(project(":domain:common"))

testImplementation(project(":core:testing"))
}
4 changes: 4 additions & 0 deletions domain/sprintresults/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.toquete.boxbox.domain.sprintresults.usecase

import com.toquete.boxbox.core.model.RaceResult
import com.toquete.boxbox.data.sprintresults.repository.SprintResultRepository
import com.toquete.boxbox.domain.common.usecase.GetTodayLocalDateUseCase
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class GetCurrentSeasonSprintResultsUseCase @Inject constructor(
private val sprintResultRepository: SprintResultRepository,
private val getTodayLocalDateUseCase: GetTodayLocalDateUseCase
) {

operator fun invoke(round: Int): Flow<List<RaceResult>> {
return sprintResultRepository.getSprintResultsBySeasonAndRound(
season = getTodayLocalDateUseCase().year.toString(),
round
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.toquete.boxbox.domain.sprintresults.usecase

import com.toquete.boxbox.core.testing.data.sprintRaceResults
import com.toquete.boxbox.data.sprintresults.repository.SprintResultRepository
import com.toquete.boxbox.domain.common.usecase.GetTodayLocalDateUseCase
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.runTest
import kotlinx.datetime.LocalDate
import org.junit.Test
import kotlin.test.assertContentEquals

class GetCurrentSeasonSprintResultsUseCaseTest {

private val sprintResultRepository: SprintResultRepository = mockk(relaxed = true)
private val getTodayLocalDateUseCase: GetTodayLocalDateUseCase = mockk(relaxed = true)
private val useCase = GetCurrentSeasonSprintResultsUseCase(
sprintResultRepository = sprintResultRepository,
getTodayLocalDateUseCase = getTodayLocalDateUseCase
)

@Test
fun `invoke should return current season race results`() = runTest {
every {
sprintResultRepository.getSprintResultsBySeasonAndRound(any(), any())
} returns flowOf(sprintRaceResults)
every { getTodayLocalDateUseCase() } returns LocalDate(year = 2023, monthNumber = 1, dayOfMonth = 1)

val result = useCase(round = 1).first()

verify { sprintResultRepository.getSprintResultsBySeasonAndRound(season = "2023", round = 1) }
assertContentEquals(sprintRaceResults, result)
}
}
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ include(":data:sprintresults")
include(":domain:common")
include(":domain:races")
include(":domain:raceresults")
include(":domain:sprintresults")
include(":feature:standings")
include(":feature:settings")
include(":feature:races")
Expand Down
Loading