diff --git a/.idea/runConfigurations/Home_Unit_Tests.xml b/.idea/runConfigurations/Home_Unit_Tests.xml new file mode 100644 index 00000000..fc4c95c2 --- /dev/null +++ b/.idea/runConfigurations/Home_Unit_Tests.xml @@ -0,0 +1,23 @@ + + + + + + + false + true + false + + + \ No newline at end of file diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/domain/usecases/CalculateCurrentStreakUC.kt b/home/src/main/java/com/jacob/wakatimeapp/home/domain/usecases/CalculateCurrentStreakUC.kt index a9e32989..99d965dc 100644 --- a/home/src/main/java/com/jacob/wakatimeapp/home/domain/usecases/CalculateCurrentStreakUC.kt +++ b/home/src/main/java/com/jacob/wakatimeapp/home/domain/usecases/CalculateCurrentStreakUC.kt @@ -8,7 +8,6 @@ import com.jacob.wakatimeapp.core.models.Error import com.jacob.wakatimeapp.core.models.Time import com.jacob.wakatimeapp.home.data.local.HomePageCache import com.jacob.wakatimeapp.home.domain.InstantProvider -import com.jacob.wakatimeapp.home.domain.RecalculateLatestStreakService import com.jacob.wakatimeapp.home.domain.getLatestStreakInRange import com.jacob.wakatimeapp.home.domain.models.StreakRange import javax.inject.Inject @@ -21,7 +20,7 @@ import kotlinx.datetime.minus class CalculateCurrentStreakUC @Inject constructor( private val homePageCache: HomePageCache, private val instantProvider: InstantProvider, - private val recalculateLatestStreakService: RecalculateLatestStreakService, + private val recalculateLatestStreakUC: RecalculateLatestStreakUC, ) { suspend operator fun invoke(): Either = either { @@ -61,7 +60,7 @@ class CalculateCurrentStreakUC @Inject constructor( private suspend fun whenFailedToCombine( recalculatedStreakForLast7Days: StreakRange, ) = when (recalculatedStreakForLast7Days.days) { - 7 -> recalculateLatestStreakService.calculate( + 7 -> recalculateLatestStreakUC.calculate( start = instantProvider.now().toDate().minus(7, DateTimeUnit.DAY), value = 1, unit = DateTimeUnit.MONTH diff --git a/home/src/main/java/com/jacob/wakatimeapp/home/domain/RecalculateLatestStreakService.kt b/home/src/main/java/com/jacob/wakatimeapp/home/domain/usecases/RecalculateLatestStreakUC.kt similarity index 90% rename from home/src/main/java/com/jacob/wakatimeapp/home/domain/RecalculateLatestStreakService.kt rename to home/src/main/java/com/jacob/wakatimeapp/home/domain/usecases/RecalculateLatestStreakUC.kt index ccb2832b..2894da92 100644 --- a/home/src/main/java/com/jacob/wakatimeapp/home/domain/RecalculateLatestStreakService.kt +++ b/home/src/main/java/com/jacob/wakatimeapp/home/domain/usecases/RecalculateLatestStreakUC.kt @@ -1,9 +1,10 @@ -package com.jacob.wakatimeapp.home.domain +package com.jacob.wakatimeapp.home.domain.usecases import arrow.core.Either import arrow.core.computations.either import com.jacob.wakatimeapp.core.models.Error import com.jacob.wakatimeapp.home.data.network.HomePageNetworkData +import com.jacob.wakatimeapp.home.domain.getLatestStreakInRange import com.jacob.wakatimeapp.home.domain.models.StreakRange import javax.inject.Inject import javax.inject.Singleton @@ -14,7 +15,7 @@ import kotlinx.datetime.daysUntil import kotlinx.datetime.minus @Singleton -class RecalculateLatestStreakService @Inject constructor( +class RecalculateLatestStreakUC @Inject constructor( private val homePageNetworkData: HomePageNetworkData, ) { suspend fun calculate( diff --git a/home/src/test/java/com/jacob/wakatimeapp/home/domain/usecases/CalculateCurrentStreakUCRobot.kt b/home/src/test/java/com/jacob/wakatimeapp/home/domain/usecases/CalculateCurrentStreakUCRobot.kt index 2130bb52..7dad6afb 100644 --- a/home/src/test/java/com/jacob/wakatimeapp/home/domain/usecases/CalculateCurrentStreakUCRobot.kt +++ b/home/src/test/java/com/jacob/wakatimeapp/home/domain/usecases/CalculateCurrentStreakUCRobot.kt @@ -5,7 +5,6 @@ import com.jacob.wakatimeapp.core.models.Error import com.jacob.wakatimeapp.core.models.Time import com.jacob.wakatimeapp.home.data.local.HomePageCache import com.jacob.wakatimeapp.home.domain.InstantProvider -import com.jacob.wakatimeapp.home.domain.RecalculateLatestStreakService import com.jacob.wakatimeapp.home.domain.models.Last7DaysStats import com.jacob.wakatimeapp.home.domain.models.StreakRange import io.kotest.assertions.asClue @@ -29,7 +28,7 @@ internal class CalculateCurrentStreakUCRobot { private var result: Either? = null private val mockCache: HomePageCache = mockk(relaxUnitFun = true) - private val mockRecalculateStreak: RecalculateLatestStreakService = mockk() + private val mockRecalculateStreak: RecalculateLatestStreakUC = mockk() fun buildUseCase() = apply { clearMocks(mockCache, mockRecalculateStreak) @@ -42,7 +41,7 @@ internal class CalculateCurrentStreakUCRobot { override fun now() = currentDayInstant }, homePageCache = mockCache, - recalculateLatestStreakService = mockRecalculateStreak, + recalculateLatestStreakUC = mockRecalculateStreak, ) } diff --git a/home/src/test/java/com/jacob/wakatimeapp/home/domain/RecalculateLatestStreakServiceRobot.kt b/home/src/test/java/com/jacob/wakatimeapp/home/domain/usecases/RecalculateLatestStreakUCRobot.kt similarity index 88% rename from home/src/test/java/com/jacob/wakatimeapp/home/domain/RecalculateLatestStreakServiceRobot.kt rename to home/src/test/java/com/jacob/wakatimeapp/home/domain/usecases/RecalculateLatestStreakUCRobot.kt index bf3a289b..ab42edcd 100644 --- a/home/src/test/java/com/jacob/wakatimeapp/home/domain/RecalculateLatestStreakServiceRobot.kt +++ b/home/src/test/java/com/jacob/wakatimeapp/home/domain/usecases/RecalculateLatestStreakUCRobot.kt @@ -1,4 +1,4 @@ -package com.jacob.wakatimeapp.home.domain +package com.jacob.wakatimeapp.home.domain.usecases import arrow.core.Either import com.jacob.wakatimeapp.core.models.DailyStats @@ -17,8 +17,8 @@ import kotlinx.datetime.DateTimeUnit import kotlinx.datetime.LocalDate import kotlinx.datetime.plus -internal class RecalculateLatestStreakServiceRobot { - private lateinit var service: RecalculateLatestStreakService +internal class RecalculateLatestStreakUCRobot { + private lateinit var useCase: RecalculateLatestStreakUC private val mockHomePageNetworkData: HomePageNetworkData = mockk() @@ -28,11 +28,11 @@ internal class RecalculateLatestStreakServiceRobot { clearMocks(mockHomePageNetworkData) result = null - service = RecalculateLatestStreakService(mockHomePageNetworkData) + useCase = RecalculateLatestStreakUC(mockHomePageNetworkData) } suspend fun calculate(start: LocalDate, value: Int, unit: DateTimeUnit.DateBased) = apply { - result = service.calculate( + result = useCase.calculate( start, value, unit, diff --git a/home/src/test/java/com/jacob/wakatimeapp/home/domain/RecalculateLatestStreakServiceTest.kt b/home/src/test/java/com/jacob/wakatimeapp/home/domain/usecases/RecalculateLatestStreakUCTest.kt similarity index 98% rename from home/src/test/java/com/jacob/wakatimeapp/home/domain/RecalculateLatestStreakServiceTest.kt rename to home/src/test/java/com/jacob/wakatimeapp/home/domain/usecases/RecalculateLatestStreakUCTest.kt index 2d0b5312..01bff848 100644 --- a/home/src/test/java/com/jacob/wakatimeapp/home/domain/RecalculateLatestStreakServiceTest.kt +++ b/home/src/test/java/com/jacob/wakatimeapp/home/domain/usecases/RecalculateLatestStreakUCTest.kt @@ -1,11 +1,11 @@ -package com.jacob.wakatimeapp.home.domain +package com.jacob.wakatimeapp.home.domain.usecases import arrow.core.right import com.jacob.wakatimeapp.core.models.Stats import com.jacob.wakatimeapp.core.models.StatsRange import com.jacob.wakatimeapp.core.models.Time -import com.jacob.wakatimeapp.home.domain.RecalculateLatestStreakServiceRobot.Companion.createDailyStats import com.jacob.wakatimeapp.home.domain.models.StreakRange +import com.jacob.wakatimeapp.home.domain.usecases.RecalculateLatestStreakUCRobot.Companion.createDailyStats import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.test.runTest import kotlinx.datetime.DateTimeUnit @@ -16,8 +16,8 @@ import kotlinx.datetime.toLocalDate import org.junit.jupiter.api.Test @OptIn(ExperimentalCoroutinesApi::class) -internal class RecalculateLatestStreakServiceTest { - private val robot = RecalculateLatestStreakServiceRobot() +internal class RecalculateLatestStreakUCTest { + private val robot = RecalculateLatestStreakUCRobot() @Test internal fun `when called with duration and there is no valid streak, then return empty streak`() =