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 @@ -6,7 +6,6 @@ import cloud.mindbox.mobile_sdk.inapp.data.dto.*
import cloud.mindbox.mobile_sdk.inapp.domain.interfaces.managers.MobileConfigSerializationManager
import cloud.mindbox.mobile_sdk.logger.MindboxLoggerImpl
import cloud.mindbox.mobile_sdk.logger.mindboxLogE
import cloud.mindbox.mobile_sdk.logger.mindboxLogW
import cloud.mindbox.mobile_sdk.models.TreeTargetingDto
import cloud.mindbox.mobile_sdk.models.operation.response.*
import cloud.mindbox.mobile_sdk.models.operation.response.InAppConfigResponseBlank.InAppDtoBlank
Expand Down Expand Up @@ -55,10 +54,10 @@ internal class MobileConfigSerializationManagerImpl(private val gson: Gson) :
return null
}

val inApps = deserializeInApps(jsonObject.getOrNull("inapps"))
val settings = deserializeSettings(jsonObject.getOrNull("settings"))
val abtests = deserializeAbtests(jsonObject.getOrNull("abtests"))
val monitoring = deserializeMonitoring(jsonObject.getOrNull("monitoring"))
val inApps = jsonObject.getOrNull("inapps")?.let { deserializeInApps(it) }
val settings = jsonObject.getOrNull("settings")?.let { deserializeSettings(it) }
val abtests = jsonObject.getOrNull("abtests")?.let { deserializeAbtests(it) }
val monitoring = jsonObject.getOrNull("monitoring")?.let { deserializeMonitoring(it) }

return InAppConfigResponseBlank(inApps, monitoring, settings, abtests)
}
Expand All @@ -70,7 +69,7 @@ internal class MobileConfigSerializationManagerImpl(private val gson: Gson) :
runCatching {
gson.fromJson(log, LogRequestDtoBlank::class.java)?.copy()
}.getOrNull {
mindboxLogW("Failed to parse log block", it)
mindboxLogE("Failed to parse logs block", it)
}
})
}.getOrNull {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import android.app.Application
import cloud.mindbox.mobile_sdk.di.MindboxDI
import cloud.mindbox.mobile_sdk.di.mindboxInject
import cloud.mindbox.mobile_sdk.inapp.data.managers.MobileConfigSerializationManagerImpl
import cloud.mindbox.mobile_sdk.logger.mindboxLogE
import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkStatic
import io.mockk.verify
import junit.framework.TestCase.assertNotNull
import junit.framework.TestCase.assertNull
import org.junit.Before
Expand Down Expand Up @@ -157,4 +160,64 @@ internal class ConfigSerializationManagerTest {
assertNotNull(config.settings)
assertNotNull(config.inApps)
}

@Test
fun `empty config`() {
// Key is `abtestsTest` instead of `abtests`
mockkStatic(::mindboxLogE)
val json = getJson("ConfigParsing/Config/EmptyConfigs/EmptyConfig.json")
val config = manager.deserializeToConfigDtoBlank(json.toString())!!

assertNull(config.abtests)
assertNull(config.monitoring)
assertNull(config.settings)
assertNull(config.inApps)

verify(exactly = 0) { mindboxLogE(any(), any()) }
}

@Test
fun `no monitoring in config`() {
// Key is `abtestsTest` instead of `abtests`
mockkStatic(::mindboxLogE)
val json = getJson("ConfigParsing/Config/EmptyConfigs/NoMonitoring.json")
val config = manager.deserializeToConfigDtoBlank(json.toString())!!

assertNull(config.monitoring)
assertNotNull(config.abtests)
assertNotNull(config.settings)
assertNotNull(config.inApps)

verify(exactly = 0) { mindboxLogE(any(), any()) }
}

@Test
fun `empty monitoring in config`() {
// Key is `abtestsTest` instead of `abtests`
mockkStatic(::mindboxLogE)
val json = getJson("ConfigParsing/Config/EmptyConfigs/EmptyMonitoring.json")
val config = manager.deserializeToConfigDtoBlank(json.toString())!!

assertNull(config.abtests)
assertNull(config.monitoring)
assertNull(config.settings)
assertNull(config.inApps)

verify(exactly = 0) { mindboxLogE(any(), any()) }
}

@Test
fun `empty monitoring logs in config`() {
// Key is `abtestsTest` instead of `abtests`
mockkStatic(::mindboxLogE)
val json = getJson("ConfigParsing/Config/EmptyConfigs/EmptyLogsMonitoring.json")
val config = manager.deserializeToConfigDtoBlank(json.toString())!!

assertNull(config.abtests)
assertNull(config.monitoring)
assertNull(config.settings)
assertNull(config.inApps)

verify(exactly = 0) { mindboxLogE(any(), any()) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import android.app.Application
import cloud.mindbox.mobile_sdk.di.MindboxDI
import cloud.mindbox.mobile_sdk.di.mindboxInject
import cloud.mindbox.mobile_sdk.inapp.data.managers.MobileConfigSerializationManagerImpl
import cloud.mindbox.mobile_sdk.inapp.domain.interfaces.managers.MobileConfigSerializationManager
import com.google.gson.Gson
import cloud.mindbox.mobile_sdk.logger.MindboxLoggerImpl
import io.mockk.every
import io.mockk.mockk
import io.mockk.mockkObject
import io.mockk.verify
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Before
Expand Down Expand Up @@ -68,19 +69,24 @@ class MonitoringMobileConfigSerializationManagerTest {
@Test
fun monitoringConfig_withLogsOneElementTypeError_shouldParseSuccessfullyRemainsElements() {
// Type of `requestId` is Int instead of String
mockkObject(MindboxLoggerImpl)
val json = getJson("ConfigParsing/Monitoring/MonitoringLogsOneElementTypeError.json")
val config = manager.deserializeMonitoring(json)!!

assertEquals(1, config.logs?.size)
verify(exactly = 1) { MindboxLoggerImpl.e(any(),"Failed to parse logs block", any()) }
}

@Test
fun monitoringConfig_withLogsTwoElementsError_shouldParseSuccessfullyRemainsElements() {
// Key is `request` instead `requestId` and key is `device` instead of `deviceUUID`
mockkObject(MindboxLoggerImpl)

val json = getJson("ConfigParsing/Monitoring/MonitoringLogsTwoElementsError.json")
val config = manager.deserializeMonitoring(json)!!

assertEquals(0, config.logs?.size)
verify(exactly = 2) { MindboxLoggerImpl.e(any(),"Failed to parse logs block", any()) }
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"monitoring": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"monitoring": {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"settings": {
"operations": {
"viewProduct": {
"systemName": "ViewProduct"
},
"viewCategory": {
"systemName": "ViewCategory"
},
"setCart": {
"systemName": "SetCart"
}
},
"ttl": {
"inapps": "1.00:00:00"
}
},
"abtests": [],
"inapps": []
}