Skip to content

Commit

Permalink
Merge pull request #93 from hotwired/path-config-parsing
Browse files Browse the repository at this point in the history
Test that a malformed path configuration does not get cached
  • Loading branch information
jayohms authored Jan 27, 2025
2 parents 8d66697 + 9e01046 commit d7bf08b
Showing 1 changed file with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package dev.hotwire.core.turbo.config
import android.content.Context
import android.os.Build
import androidx.test.core.app.ApplicationProvider
import com.nhaarman.mockito_kotlin.mock
import com.nhaarman.mockito_kotlin.verify
import com.nhaarman.mockito_kotlin.*
import dev.hotwire.core.turbo.BaseRepositoryTest
import dev.hotwire.core.turbo.config.PathConfiguration.Location
import dev.hotwire.core.turbo.nav.PresentationContext
Expand Down Expand Up @@ -67,6 +66,42 @@ class PathConfigurationTest : BaseRepositoryTest() {
}
}

@Test
fun validConfigurationIsCached() {
pathConfiguration.loader = PathConfigurationLoader(context).apply {
repository = mockRepository
}

runBlocking {
val remoteUrl = "$url/demo/configurations/android-v1.json"
val location = Location(remoteFileUrl = remoteUrl)
val json = """{ "settings": {}, "rules": [] }"""

whenever(mockRepository.getRemoteConfiguration(remoteUrl)).thenReturn(json)

pathConfiguration.load(context, location)
verify(mockRepository).cacheConfigurationForUrl(eq(context), eq(remoteUrl), any())
}
}

@Test
fun malformedConfigurationIsNotCached() {
pathConfiguration.loader = PathConfigurationLoader(context).apply {
repository = mockRepository
}

runBlocking {
val remoteUrl = "$url/demo/configurations/android-v1.json"
val location = Location(remoteFileUrl = remoteUrl)
val json = "malformed-json"

whenever(mockRepository.getRemoteConfiguration(remoteUrl)).thenReturn(json)

pathConfiguration.load(context, location)
verify(mockRepository, never()).cacheConfigurationForUrl(any(), any(), any())
}
}

@Test
fun globalSetting() {
assertThat(pathConfiguration.settings.size).isEqualTo(1)
Expand Down

0 comments on commit d7bf08b

Please sign in to comment.