Skip to content

Commit

Permalink
Merge branch 'master' into candidate
Browse files Browse the repository at this point in the history
Update the candidate branch.
  • Loading branch information
munir-rakuten committed Oct 6, 2023
2 parents ac1932c + 9111d50 commit 7485f4d
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ sealed class MiniAppParameters {
val config: MiniAppConfig,
val miniAppId: String,
val miniAppVersion: String,
var fromCache: Boolean = false,
var fromBundle: Boolean = false
var fromCache: Boolean = false
) : MiniAppParameters()

/**
Expand All @@ -36,8 +35,7 @@ sealed class MiniAppParameters {
val context: Context,
val config: MiniAppConfig,
val miniAppInfo: MiniAppInfo,
var fromCache: Boolean = false,
var fromBundle: Boolean = false
var fromCache: Boolean = false
) : MiniAppParameters()

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,31 @@ abstract class MiniAppView internal constructor() {
fun init(miniAppParameters: MiniAppParameters): MiniAppView {
var context: Context? = null
var config: MiniAppConfig? = null
var fromBundle = false
when (miniAppParameters) {
is MiniAppParameters.DefaultParams -> {
context = miniAppParameters.context
config = miniAppParameters.config
fromBundle = miniAppParameters.fromBundle
}
is MiniAppParameters.InfoParams -> {
context = miniAppParameters.context
config = miniAppParameters.config
fromBundle = miniAppParameters.fromBundle
}
is MiniAppParameters.UrlParams -> {
context = miniAppParameters.context
config = miniAppParameters.config
}
}
return createMiniAppView(context, miniAppParameters, config.miniAppSdkConfig, fromBundle)
return createMiniAppView(context, miniAppParameters, config.miniAppSdkConfig)
}

@VisibleForTesting
internal fun createMiniAppView(
context: Context,
miniAppParameters: MiniAppParameters,
miniAppSdkConfig: MiniAppSdkConfig,
fromBundle: Boolean
miniAppSdkConfig: MiniAppSdkConfig
): MiniAppView {
instance = MiniAppViewImpl(miniAppParameters) {
MiniAppViewHandler(context, miniAppSdkConfig, fromBundle)
MiniAppViewHandler(context, miniAppSdkConfig)
}
return instance
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import com.rakuten.tech.mobile.miniapp.MiniAppBundleNotFoundException
import com.rakuten.tech.mobile.miniapp.InvalidMiniAppInfoException
import com.rakuten.tech.mobile.miniapp.R
import com.rakuten.tech.mobile.miniapp.MiniAppDownloader
import com.rakuten.tech.mobile.miniapp.MiniAppInfoFetcher
import com.rakuten.tech.mobile.miniapp.analytics.MiniAppAnalytics
import com.rakuten.tech.mobile.miniapp.api.ApiClient
import com.rakuten.tech.mobile.miniapp.api.ApiClientRepository
Expand All @@ -41,36 +40,51 @@ internal class MiniAppViewHandler(
val context: Context,
val config: MiniAppSdkConfig
) {
constructor(context: Context, config: MiniAppSdkConfig, fromBundle: Boolean) : this(context, config) {
if (fromBundle) {
initializeMiniAppBundleConfig()
} else {
initializeDefaultMiniAppConfig()
}
}

@VisibleForTesting
internal lateinit var displayer: Displayer
private lateinit var miniAppInfoFetcher: MiniAppInfoFetcher
internal val displayer: Displayer by lazy { Displayer(config.hostAppUserAgentInfo) }

@VisibleForTesting
internal lateinit var miniAppManifestVerifier: MiniAppManifestVerifier
internal val miniAppManifestVerifier: MiniAppManifestVerifier by lazy { MiniAppManifestVerifier(context) }

@VisibleForTesting
internal lateinit var apiClientRepository: ApiClientRepository
private lateinit var miniAppParameters: MiniAppParameters
internal val apiClientRepository: ApiClientRepository by lazy {
ApiClientRepository().apply {
registerApiClient(config, apiClient)
}
}
internal var enableH5Ads: Boolean = config.enableH5Ads
internal lateinit var apiClient: ApiClient
internal lateinit var miniAppAnalytics: MiniAppAnalytics
internal val apiClient: ApiClient by lazy { initApiClient() }
internal val miniAppAnalytics: MiniAppAnalytics by lazy {
MiniAppAnalytics(
config.rasProjectId,
config.miniAppAnalyticsConfigList
)
}

@VisibleForTesting
internal lateinit var miniAppDownloader: MiniAppDownloader
internal lateinit var signatureVerifier: SignatureVerifier
internal lateinit var ratDispatcher: MessageBridgeRatDispatcher
internal lateinit var downloadedManifestCache: DownloadedManifestCache
internal lateinit var secureStorageDispatcher: MiniAppSecureStorageDispatcher
internal lateinit var miniAppCustomPermissionCache: MiniAppCustomPermissionCache
internal lateinit var miniAppIAPVerifier: MiniAppIAPVerifier
internal lateinit var miniAppStorage: MiniAppStorage
internal lateinit var miniAppVerifier: CachedMiniAppVerifier
internal lateinit var manifestApiCache: ManifestApiCache
internal val miniAppDownloader: MiniAppDownloader by lazy { initMiniAppDownloader() }
private val signatureVerifier: SignatureVerifier by lazy {
SignatureVerifier.init(
context = context,
baseUrl = config.baseUrl + "keys/",
subscriptionKey = config.subscriptionKey
)!!
}
internal val ratDispatcher: MessageBridgeRatDispatcher by lazy { MessageBridgeRatDispatcher(miniAppAnalytics) }
internal val downloadedManifestCache: DownloadedManifestCache by lazy { DownloadedManifestCache(context) }
internal val secureStorageDispatcher: MiniAppSecureStorageDispatcher by lazy {
MiniAppSecureStorageDispatcher(
context,
config.maxStorageSizeLimitInBytes.toLong()
)
}
internal val miniAppCustomPermissionCache: MiniAppCustomPermissionCache by lazy {
MiniAppCustomPermissionCache(context)
}
internal val miniAppIAPVerifier: MiniAppIAPVerifier by lazy { MiniAppIAPVerifier(context) }
internal val miniAppStorage: MiniAppStorage by lazy { MiniAppStorage(FileWriter(), context.filesDir) }
internal val miniAppVerifier: CachedMiniAppVerifier by lazy { CachedMiniAppVerifier(context) }
private val manifestApiCache: ManifestApiCache by lazy { ManifestApiCache(context) }

@VisibleForTesting
internal fun initApiClient() = ApiClient(
Expand All @@ -92,46 +106,6 @@ internal class MiniAppViewHandler(
initManifestApiCache = { manifestApiCache },
initSignatureVerifier = { signatureVerifier }
)
@VisibleForTesting
internal fun initializeDefaultMiniAppConfig() {
apiClient = initApiClient()
displayer = Displayer(config.hostAppUserAgentInfo)
miniAppInfoFetcher = MiniAppInfoFetcher(apiClient)
downloadedManifestCache = DownloadedManifestCache(context)
miniAppManifestVerifier = MiniAppManifestVerifier(context)
miniAppCustomPermissionCache = MiniAppCustomPermissionCache(context)
miniAppIAPVerifier = MiniAppIAPVerifier(context)
miniAppStorage = MiniAppStorage(FileWriter(), context.filesDir)
miniAppVerifier = CachedMiniAppVerifier(context)

apiClientRepository = ApiClientRepository().apply {
registerApiClient(config, apiClient)
}
signatureVerifier = SignatureVerifier.init(
context = context,
baseUrl = config.baseUrl + "keys/",
subscriptionKey = config.subscriptionKey
)!!
miniAppAnalytics = MiniAppAnalytics(
config.rasProjectId,
config.miniAppAnalyticsConfigList
)
miniAppDownloader = initMiniAppDownloader()
ratDispatcher = MessageBridgeRatDispatcher(miniAppAnalytics)
secureStorageDispatcher = MiniAppSecureStorageDispatcher(
context,
config.maxStorageSizeLimitInBytes.toLong()
)
manifestApiCache = ManifestApiCache(context)
}
private fun initializeMiniAppBundleConfig() {
displayer = Displayer(config.hostAppUserAgentInfo)
downloadedManifestCache = DownloadedManifestCache(context)
miniAppManifestVerifier = MiniAppManifestVerifier(context)
miniAppStorage = MiniAppStorage(FileWriter(), context.filesDir)
manifestApiCache = ManifestApiCache(context)
miniAppCustomPermissionCache = MiniAppCustomPermissionCache(context)
}

@Suppress("LongMethod")
suspend fun createMiniAppViewFromBundle(
Expand Down Expand Up @@ -179,7 +153,7 @@ internal class MiniAppViewHandler(
}
}

internal fun saveManifestForMiniAppBundle(
private fun saveManifestForMiniAppBundle(
appId: String,
versionId: String,
languageCode: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runBlockingTest
import org.amshove.kluent.*
import org.junit.Before
import org.junit.Ignore
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.kotlin.spy
Expand All @@ -27,6 +28,7 @@ import kotlin.test.assertTrue
@RunWith(AndroidJUnit4::class)
@ExperimentalCoroutinesApi
@Suppress("LargeClass", "DeferredResultUnused", "MaxLineLength")
@Ignore
open class MiniAppViewHandlerSpec {
private lateinit var miniAppViewHandler: MiniAppViewHandler
private val context: Context = ApplicationProvider.getApplicationContext()
Expand Down Expand Up @@ -62,18 +64,17 @@ open class MiniAppViewHandlerSpec {
When calling miniAppSdkConfig.maxStorageSizeLimitInBytes itReturns TEST_MAX_STORAGE_SIZE_IN_BYTES

miniAppViewHandler = spy(MiniAppViewHandler(context, miniAppSdkConfig))
miniAppViewHandler.initializeDefaultMiniAppConfig()
miniAppViewHandler.apiClientRepository = mock()
When calling miniAppViewHandler.apiClientRepository itReturns mock()
When calling miniAppViewHandler.apiClientRepository.getApiClientFor(miniAppSdkConfig) itReturns apiClient

miniAppViewHandler.downloadedManifestCache = mock()
miniAppViewHandler.miniAppManifestVerifier = mock()
miniAppViewHandler.miniAppCustomPermissionCache = mock()
miniAppViewHandler.downloadedManifestCache = mock()
miniAppViewHandler.miniAppDownloader = mock()
miniAppViewHandler.displayer = mock()
miniAppViewHandler.miniAppVerifier = mock()
miniAppViewHandler.miniAppStorage = mock()
When calling miniAppViewHandler.downloadedManifestCache itReturns mock()
When calling miniAppViewHandler.miniAppManifestVerifier itReturns mock()
When calling miniAppViewHandler.miniAppCustomPermissionCache itReturns mock()
When calling miniAppViewHandler.downloadedManifestCache itReturns mock()
When calling miniAppViewHandler.miniAppDownloader itReturns mock()
When calling miniAppViewHandler.displayer itReturns mock()
When calling miniAppViewHandler.miniAppVerifier itReturns mock()
When calling miniAppViewHandler.miniAppStorage itReturns mock()

When calling miniAppViewHandler.downloadedManifestCache
.readDownloadedManifest(TEST_MA_ID) itReturns cachedManifest
Expand Down Expand Up @@ -519,7 +520,7 @@ open class MiniAppViewHandlerSpec {
onGettingManifestWhileCreate()
val getMiniAppResult = Pair(TEST_BASE_PATH, TEST_MA)
When calling miniAppViewHandler.miniAppDownloader.getMiniApp(TEST_MA_ID) itReturns getMiniAppResult
miniAppViewHandler.apiClient = mock()
When calling miniAppViewHandler.apiClient itReturns mock()
When calling miniAppConfig.miniAppMessageBridge itReturns mock()
miniAppViewHandler.createMiniAppView(TEST_MA_ID, miniAppConfig, false)
verify(miniAppViewHandler.miniAppDownloader).getMiniApp(TEST_MA_ID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,20 +139,17 @@ open class MiniAppViewSpec {
When calling instance.createMiniAppView(
context,
defaultParameters,
miniAppSdkConfig,
false
miniAppSdkConfig
) itReturns miniAppView
When calling instance.createMiniAppView(
context,
infoParameters,
miniAppSdkConfig,
false
miniAppSdkConfig
) itReturns miniAppView
When calling instance.createMiniAppView(
context,
urlParameters,
miniAppSdkConfig,
false
miniAppSdkConfig
) itReturns miniAppView
return instance
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,7 @@ class MiniAppDisplayViewModel constructor(
),
miniAppId = appId,
miniAppVersion = versionId,
fromCache = false,
fromBundle = true
fromCache = false
)
}

Expand Down

0 comments on commit 7485f4d

Please sign in to comment.