Skip to content

Commit

Permalink
added getCustomerIOBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
mrehan27 committed Sep 15, 2023
1 parent d1def35 commit beee2e5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import android.app.Application
import android.content.Context
import androidx.test.core.app.ApplicationProvider
import androidx.test.platform.app.InstrumentationRegistry
import io.customer.sdk.CustomerIO
import io.customer.sdk.CustomerIOConfig
import io.customer.sdk.data.model.Region
import io.customer.sdk.extensions.random

/**
* Base class for a integration test class to subclass. If you want to create unit tests, use [BaseTest].
Expand All @@ -31,20 +28,4 @@ abstract class BaseIntegrationTest : BaseTest() {
di.fileStorage.deleteAllSdkFiles()
di.sitePreferenceRepository.clearAll()
}

/**
* Create a new SDK instance with default configuration for integration tests.
*/
protected fun createSDKInstance() {
// Initialize the SDK but with an injected DI graph.
// Test setup should use the same SDK initialization that customers do to make test as close to production environment as possible.
CustomerIO.Builder(
siteId = siteId,
apiKey = String.random,
region = Region.US,
appContext = application
).apply {
overrideDiGraph = di
}.build()
}
}
26 changes: 26 additions & 0 deletions common-test/src/main/java/io/customer/commontest/BaseTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import io.customer.commontest.util.DispatchersProviderStub
import io.customer.sdk.CustomerIO
import io.customer.sdk.CustomerIOConfig
import io.customer.sdk.CustomerIOShared
import io.customer.sdk.data.model.Region
Expand All @@ -12,6 +13,7 @@ import io.customer.sdk.data.store.DeviceStore
import io.customer.sdk.di.CustomerIOComponent
import io.customer.sdk.di.CustomerIOSharedComponent
import io.customer.sdk.di.CustomerIOStaticComponent
import io.customer.sdk.extensions.random
import io.customer.sdk.module.CustomerIOModule
import io.customer.sdk.util.*
import okhttp3.ResponseBody.Companion.toResponseBody
Expand Down Expand Up @@ -133,4 +135,28 @@ abstract class BaseTest {
sharedDIComponent.reset()
di.reset()
}

/**
* Creates a new instance for SDK builder with default configuration for tests.
*/
protected fun getCustomerIOBuilder(
cioConfig: CustomerIOConfig = createConfig(),
siteId: String = this.siteId,
apiKey: String = String.random,
region: Region = Region.US,
application: Application = this.application
): CustomerIO.Builder {
setup(cioConfig = cioConfig)
// Initialize the SDK but with an injected DI graph.
// Test setup should prefer using the same SDK initialization that customers do to
// make test as close to production environment as possible.
return CustomerIO.Builder(
siteId = siteId,
apiKey = apiKey,
region = region,
appContext = application
).apply {
overrideDiGraph = di
}
}
}
17 changes: 0 additions & 17 deletions common-test/src/main/java/io/customer/commontest/BaseUnitTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@ package io.customer.commontest
import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import io.customer.sdk.CustomerIO
import io.customer.sdk.CustomerIOConfig
import io.customer.sdk.data.model.Region
import io.customer.sdk.data.store.DeviceStore
import io.customer.sdk.extensions.random
import io.customer.sdk.repository.preference.SharedPreferenceRepository
import io.customer.sdk.util.DateUtil
import io.customer.sdk.util.DispatchersProvider
Expand Down Expand Up @@ -41,18 +38,4 @@ abstract class BaseUnitTest : BaseTest() {
di.overrideDependency(DeviceStore::class.java, deviceStore)
di.overrideDependency(DispatchersProvider::class.java, dispatchersProviderStub)
}

/**
* Create a new SDK instance with default configuration for unit tests.
*/
protected fun createSDKInstance() {
CustomerIO.Builder(
siteId = siteId,
apiKey = String.random,
region = Region.US,
appContext = application
).apply {
overrideDiGraph = di
}.build()
}
}

0 comments on commit beee2e5

Please sign in to comment.