|
| 1 | +package com.mparticle.kits |
| 2 | + |
| 3 | +import com.mparticle.rokt.CacheConfig |
| 4 | +import com.mparticle.rokt.RoktConfig |
| 5 | +import com.rokt.roktsdk.RoktConfig as SdkRoktConfig |
| 6 | +import io.mockk.every |
| 7 | +import io.mockk.mockk |
| 8 | +import org.junit.Assert.assertEquals |
| 9 | +import org.junit.Test |
| 10 | +import org.junit.Assert.assertNotNull |
| 11 | + |
| 12 | +class RoktConfigExtensionsTest { |
| 13 | + |
| 14 | + @Test |
| 15 | + fun `toRoktSdkConfig maps color mode and edgeToEdge`() { |
| 16 | + val source = mockk<RoktConfig>() |
| 17 | + every { source.colorMode } returns RoktConfig.ColorMode.DARK |
| 18 | + every { source.edgeToEdgeDisplay } returns true |
| 19 | + every { source.cacheConfig } returns null |
| 20 | + |
| 21 | + val result: SdkRoktConfig = source.toRoktSdkConfig() |
| 22 | + |
| 23 | + assertEquals(SdkRoktConfig.ColorMode.DARK, result.colorMode) |
| 24 | + assertEquals(true, result.edgeToEdgeDisplay) |
| 25 | + } |
| 26 | + |
| 27 | + @Test |
| 28 | + fun `toRoktSdkConfig maps cacheConfig when present`() { |
| 29 | + val cacheAttributes = mapOf( |
| 30 | + "key1" to "value1", |
| 31 | + "key2" to "value2", |
| 32 | + ) |
| 33 | + |
| 34 | + val cacheConfig = mockk<CacheConfig>() |
| 35 | + every { cacheConfig.cacheDurationInSeconds } returns 3600 |
| 36 | + every { cacheConfig.cacheAttributes } returns cacheAttributes |
| 37 | + |
| 38 | + val source = mockk<RoktConfig>() |
| 39 | + every { source.colorMode } returns RoktConfig.ColorMode.LIGHT |
| 40 | + every { source.edgeToEdgeDisplay } returns false |
| 41 | + every { source.cacheConfig } returns cacheConfig |
| 42 | + |
| 43 | + val result: SdkRoktConfig = source.toRoktSdkConfig() |
| 44 | + |
| 45 | + assertEquals(SdkRoktConfig.ColorMode.LIGHT, result.colorMode) |
| 46 | + assertEquals(false, result.edgeToEdgeDisplay) |
| 47 | + assertNotNull(result.cacheConfig) |
| 48 | + assertEquals(3600L, result.cacheConfig?.cacheDurationInSeconds) |
| 49 | + assertEquals(cacheAttributes, result.cacheConfig?.cacheAttributes) |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + fun `toRoktSdkCacheConfig maps fields`() { |
| 54 | + val cacheAttributes = mapOf( |
| 55 | + "a" to "1", |
| 56 | + "b" to "2", |
| 57 | + ) |
| 58 | + val mpCache = mockk<CacheConfig>() |
| 59 | + every { mpCache.cacheDurationInSeconds } returns 120 |
| 60 | + every { mpCache.cacheAttributes } returns cacheAttributes |
| 61 | + |
| 62 | + val sdkCache = mpCache.toRoktSdkCacheConfig() |
| 63 | + |
| 64 | + assertEquals(120, sdkCache.cacheDurationInSeconds) |
| 65 | + assertEquals(cacheAttributes, sdkCache.cacheAttributes) |
| 66 | + } |
| 67 | +} |
0 commit comments