package com.hermes.app.core.errors

import androidx.test.core.app.ApplicationProvider
import com.hermes.app.R
import com.hermes.app.core.localization.HermesLocalizationStore
import java.io.IOException
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNull
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config

@RunWith(RobolectricTestRunner::class)
@Config(sdk = [34])
class HermesErrorMapperTest {
    private val context = ApplicationProvider.getApplicationContext<android.content.Context>()
    private val store = HermesLocalizationStore(context)

    @Test
    fun mapsNetworkErrorsToLocalizedCopy() {
        assertEquals(
            "Nätverksfel. Kontrollera anslutningen.",
            mapUserFacingError(store, "sv", IOException("boom")),
        )
    }

    @Test
    fun mapsGenericErrorsToLocalizedCopy() {
        assertEquals(
            "Försök igen.",
            mapUserFacingError(store, "sv", IllegalStateException("boom")),
        )
    }

    @Test
    fun ignoresCancellation() {
        assertNull(mapUserFacingError(store, "en", kotlinx.coroutines.CancellationException()))
    }
}
