Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ dependencies {
implementation 'androidx.annotation:annotation:1.5.0'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4'
implementation 'androidx.compose.runtime:runtime'
api 'com.rokt:roktsdk:4.13.1'
api 'com.rokt:roktsdk:4.14.0'

testImplementation files('libs/java-json.jar')
testImplementation 'com.squareup.assertj:assertj-android:1.2.0'
Expand Down
13 changes: 13 additions & 0 deletions src/main/kotlin/com/mparticle/kits/RoktKit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import com.rokt.roktsdk.Rokt.SdkFrameworkType.ReactNative
import com.rokt.roktsdk.RoktEvent
import com.rokt.roktsdk.RoktWidgetDimensionCallBack
import com.rokt.roktsdk.Widget
import com.rokt.roktsdk.logging.RoktLogLevel
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -86,6 +87,9 @@ class RoktKit :
val fontFilePathMap = roktOptions?.fontFilePathMap ?: emptyMap()
val fontPostScriptNames = roktOptions?.fontPostScriptNames ?: emptySet()

val mappedLogLevel = Logger.getMinLogLevel().toRoktLogLevel()
Rokt.setLogLevel(mappedLogLevel)

Rokt.init(
roktTagId = roktTagId,
appVersion = info.versionName,
Expand Down Expand Up @@ -161,6 +165,15 @@ class RoktKit :
Logger.error(t, "RoktKit: $message")
}

private fun MParticle.LogLevel.toRoktLogLevel(): RoktLogLevel = when (this) {
MParticle.LogLevel.VERBOSE -> RoktLogLevel.VERBOSE
MParticle.LogLevel.DEBUG -> RoktLogLevel.DEBUG
MParticle.LogLevel.INFO -> RoktLogLevel.INFO
MParticle.LogLevel.WARNING -> RoktLogLevel.WARNING
MParticle.LogLevel.ERROR -> RoktLogLevel.ERROR
MParticle.LogLevel.NONE -> RoktLogLevel.NONE
}

private fun throwOnKitCreateError(message: String): Unit = throw IllegalArgumentException(message)

/*
Expand Down
64 changes: 64 additions & 0 deletions src/test/kotlin/com/mparticle/kits/RoktKitTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.mparticle.kits.mocks.MockKitConfiguration
import com.rokt.roktsdk.FulfillmentAttributes
import com.rokt.roktsdk.Rokt
import com.rokt.roktsdk.RoktEvent
import com.rokt.roktsdk.logging.RoktLogLevel
import io.mockk.every
import io.mockk.just
import io.mockk.mockk
Expand Down Expand Up @@ -1439,4 +1440,67 @@ class RoktKitTests {
override fun onKitApiCalled(methodName: String?, kitId: Int, used: Boolean?, vararg objects: Any?) {}
}
}

@Test
fun testLogLevelMapping_VERBOSE() {
// Arrange
val method = RoktKit::class.java.getDeclaredMethod(
"toRoktLogLevel",
MParticle.LogLevel::class.java,
)
method.isAccessible = true

// Act & Assert
assertEquals(RoktLogLevel.VERBOSE, method.invoke(roktKit, MParticle.LogLevel.VERBOSE))
}

@Test
fun testLogLevelMapping_DEBUG() {
val method = RoktKit::class.java.getDeclaredMethod(
"toRoktLogLevel",
MParticle.LogLevel::class.java,
)
method.isAccessible = true
assertEquals(RoktLogLevel.DEBUG, method.invoke(roktKit, MParticle.LogLevel.DEBUG))
}

@Test
fun testLogLevelMapping_INFO() {
val method = RoktKit::class.java.getDeclaredMethod(
"toRoktLogLevel",
MParticle.LogLevel::class.java,
)
method.isAccessible = true
assertEquals(RoktLogLevel.INFO, method.invoke(roktKit, MParticle.LogLevel.INFO))
}

@Test
fun testLogLevelMapping_WARNING() {
val method = RoktKit::class.java.getDeclaredMethod(
"toRoktLogLevel",
MParticle.LogLevel::class.java,
)
method.isAccessible = true
assertEquals(RoktLogLevel.WARNING, method.invoke(roktKit, MParticle.LogLevel.WARNING))
}

@Test
fun testLogLevelMapping_ERROR() {
val method = RoktKit::class.java.getDeclaredMethod(
"toRoktLogLevel",
MParticle.LogLevel::class.java,
)
method.isAccessible = true
assertEquals(RoktLogLevel.ERROR, method.invoke(roktKit, MParticle.LogLevel.ERROR))
}

@Test
fun testLogLevelMapping_NONE() {
val method = RoktKit::class.java.getDeclaredMethod(
"toRoktLogLevel",
MParticle.LogLevel::class.java,
)
method.isAccessible = true
assertEquals(RoktLogLevel.NONE, method.invoke(roktKit, MParticle.LogLevel.NONE))
}
}