diff options
| author | Peter Stone <thepeterstone@gmail.com> | 2026-04-04 07:45:41 +0000 |
|---|---|---|
| committer | Peter Stone <thepeterstone@gmail.com> | 2026-04-04 07:45:41 +0000 |
| commit | 97715ab4007ff3101f58edf4385cef1fc3d1615b (patch) | |
| tree | 464bdb1df8cfed31402f5316fe84df974c0e59e2 /android-app/app/src/test/kotlin/org | |
| parent | 9f01ddfba17dda7fb386e83f007c671fec6d5b8e (diff) | |
refactor: unify core models and finish org.terst.nav migration
Diffstat (limited to 'android-app/app/src/test/kotlin/org')
| -rw-r--r-- | android-app/app/src/test/kotlin/org/terst/nav/data/repository/WeatherRepositoryTest.kt | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/android-app/app/src/test/kotlin/org/terst/nav/data/repository/WeatherRepositoryTest.kt b/android-app/app/src/test/kotlin/org/terst/nav/data/repository/WeatherRepositoryTest.kt index 749630f..c455085 100644 --- a/android-app/app/src/test/kotlin/org/terst/nav/data/repository/WeatherRepositoryTest.kt +++ b/android-app/app/src/test/kotlin/org/terst/nav/data/repository/WeatherRepositoryTest.kt @@ -3,8 +3,7 @@ package org.terst.nav.data.repository import org.terst.nav.data.api.MarineApiService import org.terst.nav.data.api.WeatherApiService import org.terst.nav.data.model.* -import io.mockk.coEvery -import io.mockk.mockk +import io.mockk.* import kotlinx.coroutines.test.runTest import org.junit.Assert.* import org.junit.Before @@ -36,6 +35,9 @@ class WeatherRepositoryTest { time = listOf("2026-03-13T00:00", "2026-03-13T01:00"), waveHeight = listOf(1.2, 1.1), waveDirection = listOf(250.0, 255.0), + swellWaveHeight = emptyList(), + swellWaveDirection = emptyList(), + swellWavePeriod = emptyList(), oceanCurrentVelocity = listOf(0.3, 0.4), oceanCurrentDirection = listOf(180.0, 185.0) ) @@ -48,7 +50,7 @@ class WeatherRepositoryTest { @Test fun `fetchForecastItems maps weather response to ForecastItem list`() = runTest { - coEvery { weatherApi.getWeatherForecast(any(), any()) } returns weatherResponse + coEvery { weatherApi.getWeatherForecast(any(), any(), any(), any(), any()) } returns weatherResponse coEvery { marineApi.getMarineForecast(any(), any()) } returns marineResponse val result = repo.fetchForecastItems(37.5, -122.3) @@ -65,8 +67,25 @@ class WeatherRepositoryTest { } @Test + fun `fetchCurrentConditions maps responses to MarineConditions`() = runTest { + coEvery { weatherApi.getWeatherForecast(any(), any(), any(), eq(1), any()) } returns weatherResponse + coEvery { marineApi.getMarineForecast(any(), any()) } returns marineResponse + + val result = repo.fetchCurrentConditions(37.5, -122.3) + + if (result.isFailure) { + fail("fetchCurrentConditions failed with: ${result.exceptionOrNull()}") + } + val cond = result.getOrThrow() + assertEquals(15.0, cond.windSpeedKt!!, 0.001) + assertEquals(1.2, cond.waveHeightM!!, 0.001) + assertEquals(0.3 * 1.94384, cond.currentSpeedKt!!, 0.001) + assertEquals(180.0, cond.currentDirDeg!!, 0.001) + } + + @Test fun `fetchWindArrow returns WindArrow for first (current) hour`() = runTest { - coEvery { weatherApi.getWeatherForecast(any(), any()) } returns weatherResponse + coEvery { weatherApi.getWeatherForecast(any(), any(), any(), eq(1), any()) } returns weatherResponse coEvery { marineApi.getMarineForecast(any(), any()) } returns marineResponse val result = repo.fetchWindArrow(37.5, -122.3) @@ -81,7 +100,7 @@ class WeatherRepositoryTest { @Test fun `fetchForecastItems returns failure when weather API throws`() = runTest { - coEvery { weatherApi.getWeatherForecast(any(), any()) } throws RuntimeException("Network error") + coEvery { weatherApi.getWeatherForecast(any(), any(), any(), any(), any()) } throws RuntimeException("Network error") coEvery { marineApi.getMarineForecast(any(), any()) } returns marineResponse val result = repo.fetchForecastItems(37.5, -122.3) @@ -91,7 +110,7 @@ class WeatherRepositoryTest { @Test fun `fetchWindArrow returns failure when API throws`() = runTest { - coEvery { weatherApi.getWeatherForecast(any(), any()) } throws RuntimeException("Timeout") + coEvery { weatherApi.getWeatherForecast(any(), any(), any(), eq(1), any()) } throws RuntimeException("Timeout") coEvery { marineApi.getMarineForecast(any(), any()) } returns marineResponse val result = repo.fetchWindArrow(37.5, -122.3) |
