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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ internal fun PresentationModule(
inAppInteractor = inAppInteractor,
defaultDispatcher = Dispatchers.IO,
monitoringInteractor = monitoringInteractor,
sessionStorageManager = sessionStorageManager
sessionStorageManager = sessionStorageManager,
userVisitManager = userVisitManager
)
}
override val clipboardManager: ClipboardManager by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class SessionStorageManager(private val timeProvider: TimeProvider) {
ProductSegmentationFetchStatus.SEGMENTATION_NOT_FETCHED
var inAppProductSegmentations: HashMap<String, Set<ProductSegmentationResponseWrapper>> =
HashMap()
var currentSessionInApps: List<InApp> = mutableListOf()
var currentSessionInApps: List<InApp> = emptyList()
var shownInAppIdsWithEvents = mutableMapOf<String, MutableSet<Int>>()
var configFetchingError: Boolean = false
var lastTrackVisitSendTime: Long = 0L
Expand Down Expand Up @@ -55,6 +55,21 @@ internal class SessionStorageManager(private val timeProvider: TimeProvider) {
mindboxLogI("$checkingSessionResultLog. New lastTrackVisitSendTime = $currentTime")
}

fun clearSessionData() {
inAppCustomerSegmentations = null
unShownOperationalInApps.clear()
operationalInApps.clear()
isInAppMessageShown = false
customerSegmentationFetchStatus = CustomerSegmentationFetchStatus.SEGMENTATION_NOT_FETCHED
geoFetchStatus = GeoFetchStatus.GEO_NOT_FETCHED
productSegmentationFetchStatus = ProductSegmentationFetchStatus.SEGMENTATION_NOT_FETCHED
inAppProductSegmentations.clear()
currentSessionInApps = emptyList()
shownInAppIdsWithEvents.clear()
configFetchingError = false
sessionTime = 0L
}

private fun notifySessionExpired() {
sessionExpirationListeners.forEach {
loggingRunCatching {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import cloud.mindbox.mobile_sdk.logger.MindboxLoggerImpl
import cloud.mindbox.mobile_sdk.logger.mindboxLogD
import cloud.mindbox.mobile_sdk.logger.mindboxLogI
import cloud.mindbox.mobile_sdk.managers.MindboxEventManager
import cloud.mindbox.mobile_sdk.managers.UserVisitManager
import cloud.mindbox.mobile_sdk.monitoring.domain.interfaces.MonitoringInteractor
import cloud.mindbox.mobile_sdk.repository.MindboxPreferences
import cloud.mindbox.mobile_sdk.utils.LoggingExceptionHandler
Expand All @@ -20,7 +21,8 @@ internal class InAppMessageManagerImpl(
private val inAppInteractor: InAppInteractor,
private val defaultDispatcher: CoroutineDispatcher,
private val monitoringInteractor: MonitoringInteractor,
private val sessionStorageManager: SessionStorageManager
private val sessionStorageManager: SessionStorageManager,
private val userVisitManager: UserVisitManager
) : InAppMessageManager {

init {
Expand Down Expand Up @@ -141,6 +143,8 @@ internal class InAppMessageManagerImpl(
inAppMessageViewDisplayer.hideCurrentInApp()
processingJob?.cancel()
inAppInteractor.resetInAppConfigAndEvents()
sessionStorageManager.clearSessionData()
userVisitManager.saveUserVisit()
InitializeLock.reset(InitializeLock.State.APP_STARTED)
listenEventAndInApp()
initLogs()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package cloud.mindbox.mobile_sdk.inapp.data.managers

import cloud.mindbox.mobile_sdk.inapp.domain.models.CustomerSegmentationFetchStatus
import cloud.mindbox.mobile_sdk.inapp.domain.models.GeoFetchStatus
import cloud.mindbox.mobile_sdk.inapp.domain.models.ProductSegmentationFetchStatus
import cloud.mindbox.mobile_sdk.utils.TimeProvider
import io.mockk.*
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test

Expand Down Expand Up @@ -91,4 +97,37 @@ class SessionStorageManagerTest {
assertEquals(sessionStorageManager.lastTrackVisitSendTime, 1500L)
verify(exactly = 0) { listener.invoke() }
}

@Test
fun `clearSessionData should reset all fields to default values`() {
sessionStorageManager.apply {
inAppCustomerSegmentations = mockk()
unShownOperationalInApps["test"] = mutableListOf(mockk())
operationalInApps["test"] = mutableListOf(mockk())
isInAppMessageShown = true
customerSegmentationFetchStatus = CustomerSegmentationFetchStatus.SEGMENTATION_FETCH_SUCCESS
geoFetchStatus = GeoFetchStatus.GEO_FETCH_SUCCESS
productSegmentationFetchStatus = ProductSegmentationFetchStatus.SEGMENTATION_FETCH_SUCCESS
inAppProductSegmentations["test"] = setOf(mockk())
currentSessionInApps = listOf(mockk())
shownInAppIdsWithEvents["event"] = mutableSetOf(1, 2, 3)
configFetchingError = true
sessionTime = 1000L
}

sessionStorageManager.clearSessionData()

assertNull(sessionStorageManager.inAppCustomerSegmentations)
assertTrue(sessionStorageManager.unShownOperationalInApps.isEmpty())
assertTrue(sessionStorageManager.operationalInApps.isEmpty())
assertFalse(sessionStorageManager.isInAppMessageShown)
assertEquals(CustomerSegmentationFetchStatus.SEGMENTATION_NOT_FETCHED, sessionStorageManager.customerSegmentationFetchStatus)
assertEquals(GeoFetchStatus.GEO_NOT_FETCHED, sessionStorageManager.geoFetchStatus)
assertEquals(ProductSegmentationFetchStatus.SEGMENTATION_NOT_FETCHED, sessionStorageManager.productSegmentationFetchStatus)
assertTrue(sessionStorageManager.inAppProductSegmentations.isEmpty())
assertTrue(sessionStorageManager.currentSessionInApps.isEmpty())
assertTrue(sessionStorageManager.shownInAppIdsWithEvents.isEmpty())
assertFalse(sessionStorageManager.configFetchingError)
assertEquals(0L, sessionStorageManager.sessionTime)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import cloud.mindbox.mobile_sdk.Mindbox
import cloud.mindbox.mobile_sdk.inapp.data.managers.SessionStorageManager
import cloud.mindbox.mobile_sdk.inapp.domain.interfaces.interactors.InAppInteractor
import cloud.mindbox.mobile_sdk.logger.MindboxLoggerImpl
import cloud.mindbox.mobile_sdk.managers.UserVisitManager
import cloud.mindbox.mobile_sdk.models.InAppStub
import cloud.mindbox.mobile_sdk.monitoring.domain.interfaces.MonitoringInteractor
import cloud.mindbox.mobile_sdk.repository.MindboxPreferences
Expand Down Expand Up @@ -42,6 +43,8 @@ internal class InAppMessageManagerTest {

private val sessionStorageManager = mockk<SessionStorageManager>(relaxUnitFun = true)

private val userVisitManager = mockk<UserVisitManager>()

@OptIn(DelicateCoroutinesApi::class)
private val mainThreadSurrogate = newSingleThreadContext("UI thread")

Expand Down Expand Up @@ -76,7 +79,8 @@ internal class InAppMessageManagerTest {
inAppMessageViewDisplayer,
inAppMessageInteractor,
StandardTestDispatcher(testScheduler), monitoringRepository,
sessionStorageManager
sessionStorageManager,
userVisitManager
)
coEvery {
inAppMessageInteractor.fetchMobileConfig()
Expand All @@ -94,7 +98,8 @@ internal class InAppMessageManagerTest {
inAppMessageViewDisplayer,
inAppMessageInteractor,
StandardTestDispatcher(testScheduler), monitoringRepository,
sessionStorageManager
sessionStorageManager,
userVisitManager
)
mockkObject(LoggingExceptionHandler)
every { MindboxPreferences.inAppConfig } returns "test"
Expand Down Expand Up @@ -124,7 +129,8 @@ internal class InAppMessageManagerTest {
inAppMessageInteractor,
StandardTestDispatcher(testScheduler),
monitoringRepository,
sessionStorageManager
sessionStorageManager,
userVisitManager
)
coEvery {
inAppMessageInteractor.processEventAndConfig()
Expand Down Expand Up @@ -162,7 +168,8 @@ internal class InAppMessageManagerTest {
inAppMessageInteractor,
StandardTestDispatcher(testScheduler),
monitoringRepository,
sessionStorageManager
sessionStorageManager,
userVisitManager
)
coEvery {
inAppMessageInteractor.listenToTargetingEvents()
Expand Down Expand Up @@ -199,7 +206,8 @@ internal class InAppMessageManagerTest {
inAppMessageViewDisplayer,
inAppMessageInteractor,
StandardTestDispatcher(testScheduler), monitoringRepository,
sessionStorageManager
sessionStorageManager,
userVisitManager
)
every {
runBlocking {
Expand Down Expand Up @@ -238,7 +246,8 @@ internal class InAppMessageManagerTest {
inAppMessageViewDisplayer,
inAppMessageInteractor,
StandardTestDispatcher(testScheduler), monitoringRepository,
sessionStorageManager
sessionStorageManager,
userVisitManager
)
mockkConstructor(NetworkResponse::class)
val networkResponse = mockk<NetworkResponse>()
Expand Down Expand Up @@ -268,7 +277,8 @@ internal class InAppMessageManagerTest {
inAppMessageViewDisplayer,
inAppMessageInteractor,
StandardTestDispatcher(testScheduler), monitoringRepository,
sessionStorageManager
sessionStorageManager,
userVisitManager
)
mockkConstructor(NetworkResponse::class)
val networkResponse = mockk<NetworkResponse>()
Expand Down