package io.embrace.android.embracesdk.config.behavior import io.embrace.android.embracesdk.config.local.SessionLocalConfig import io.embrace.android.embracesdk.config.remote.RemoteConfig import io.embrace.android.embracesdk.config.remote.SessionRemoteConfig import io.embrace.android.embracesdk.fakes.fakeSessionBehavior import org.junit.Assert.assertEquals import org.junit.Assert.assertFalse import org.junit.Assert.assertNull import org.junit.Assert.assertTrue import org.junit.Test internal class SessionBehaviorTest { private val local = SessionLocalConfig( sessionComponents = setOf("breadcrumbs"), fullSessionEvents = setOf("crash"), sessionEnableErrorLogStrictMode = true ) private val remote = RemoteConfig( sessionConfig = SessionRemoteConfig( isEnabled = true, useV2Payload = true, sessionComponents = setOf("test"), fullSessionEvents = setOf("test2") ), maxSessionProperties = 57, ) @Test fun testDefaults() { with(fakeSessionBehavior()) { assertFalse(isSessionErrorLogStrictModeEnabled()) assertEquals(emptySet(), getFullSessionEvents()) assertNull(getSessionComponents()) assertFalse(isGatingFeatureEnabled()) assertFalse(isSessionControlEnabled()) assertEquals(10, getMaxSessionProperties()) assertFalse(useV2Payload()) } } @Test fun testLocalOnly() { with(fakeSessionBehavior(localCfg = { local })) { assertTrue(isSessionErrorLogStrictModeEnabled()) assertEquals(setOf("breadcrumbs"), getSessionComponents()) assertEquals(setOf("crash"), getFullSessionEvents()) assertTrue(isGatingFeatureEnabled()) assertFalse(useV2Payload()) } } @Test fun testRemoteAndLocal() { with(fakeSessionBehavior(localCfg = { local }, remoteCfg = { remote })) { assertTrue(isGatingFeatureEnabled()) assertTrue(isSessionControlEnabled()) assertEquals(setOf("test"), getSessionComponents()) assertEquals(setOf("test2"), getFullSessionEvents()) assertEquals(57, getMaxSessionProperties()) assertTrue(useV2Payload()) } } @Test fun `test upper case full session events`() { val behavior = fakeSessionBehavior( remoteCfg = { buildGatingConfig(setOf("CRASHES", "ERRORS")) } ) assertEquals(setOf("crashes", "errors"), behavior.getFullSessionEvents()) } @Test fun `test lower case full session events`() { val behavior = fakeSessionBehavior( remoteCfg = { buildGatingConfig(setOf("crashes", "errors")) } ) assertEquals(setOf("crashes", "errors"), behavior.getFullSessionEvents()) } private fun buildGatingConfig(events: Set) = RemoteConfig( sessionConfig = SessionRemoteConfig( fullSessionEvents = events ) ) }