Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ class MPRoktModuleImpl(
private val reactContext: ReactApplicationContext,
) {
init {
setWrapperSdk()
}

/**
* Reports the React Native wrapper SDK type to mParticle so it can be forwarded to kits.
*
* Called before every placement selection (mirroring the iOS implementation) rather than
* only once at module creation, because the one-shot call is silently dropped when
* MParticle has not been started yet or when kits have not finished initializing.
*/
fun setWrapperSdk() {
MParticle.getInstance()?.setWrapperSdk(WrapperSdk.WrapperSdkReactNative, "")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class MPRoktModule(
Logger.warning("selectPlacements failed. identifier cannot be empty")
return
}
impl.setWrapperSdk()
MParticle.getInstance()?.Rokt()?.events(identifier)?.let {
impl.startRoktEventListener(it, reactContext.currentActivity, identifier)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class MPRoktModule(
Logger.warning("selectPlacements failed. identifier cannot be empty")
return
}
impl.setWrapperSdk()
val uiManager = reactContext.getNativeModule(UIManagerModule::class.java)
MParticle.getInstance()?.Rokt()?.events(identifier)?.let {
impl.startRoktEventListener(it, reactContext.currentActivity, identifier)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.mparticle.react.rokt

import com.facebook.react.bridge.ReactApplicationContext
import com.mparticle.MParticle
import com.mparticle.WrapperSdk
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito
import org.mockito.junit.MockitoJUnitRunner

@RunWith(MockitoJUnitRunner::class)
class MPRoktModuleImplTest {
@Test
fun `setWrapperSdk is reported on module creation`() {
val mParticle = Mockito.mock(MParticle::class.java)
MParticle.setInstance(mParticle)

MPRoktModuleImpl(Mockito.mock(ReactApplicationContext::class.java))

Mockito.verify(mParticle).setWrapperSdk(WrapperSdk.WrapperSdkReactNative, "")
}

@Test
fun `setWrapperSdk reports wrapper type on each call`() {
val mParticle = Mockito.mock(MParticle::class.java)
MParticle.setInstance(mParticle)
val impl = MPRoktModuleImpl(Mockito.mock(ReactApplicationContext::class.java))

impl.setWrapperSdk()
impl.setWrapperSdk()

Mockito.verify(mParticle, Mockito.times(3)).setWrapperSdk(WrapperSdk.WrapperSdkReactNative, "")
}

@Test
fun `setWrapperSdk does not crash when MParticle is not started`() {
MParticle.setInstance(null)

val impl = MPRoktModuleImpl(Mockito.mock(ReactApplicationContext::class.java))

impl.setWrapperSdk()
}
}
Loading