TestMode

class TestMode(val storage: Storage, val isTestEnvironment: Boolean = Companion.isTestEnvironment, val getSuperwallProducts: suspend () -> Either<SuperwallProductsResponse, NetworkError> = { Either.Failure(NetworkError.Unknown()) }, val entitlements: Entitlements? = null, val activityProvider: () -> ActivityProvider? = { null }, val activityTracker: () -> CurrentActivityTracker? = { null }, val hasExternalPurchaseController: () -> Boolean = { false }, val apiKey: () -> String = { "" }, val dashboardBaseUrl: () -> String = { "" }, val tracker: suspend (TrackableSuperwallEvent) -> Unit = { }, val showModal: suspend (activity: Activity, reason: String, hasPurchaseController: Boolean, availableEntitlements: List<String>, apiKey: String, dashboardBaseUrl: String, savedSettings: TestModeSettings?) -> TestModeModalResult = { activity, reason, hasPC, available, ak, db, saved -> TestModeModal.show(activity, reason, hasPC, available, ak, db, saved) }, ioScope: CoroutineScope = IOScope(), val actor: StateActor<TestModeContext, TestModeState> = SequentialActor(TestModeState.Inactive, ioScope)) : TestModeContext(source)

Test-mode manager.

Implements TestModeContext directly so TestModeState.Actions receive this as their receiver — same pattern as com.superwall.sdk.identity.IdentityManager / com.superwall.sdk.identity.IdentityContext.

State is held in a SequentialActor; pure mutations go through update(Updates.X) (CAS-atomic), async work (network + modal) is dispatched as TestModeState.Actions.

Constructors

Link copied to clipboard
constructor(storage: Storage, isTestEnvironment: Boolean = Companion.isTestEnvironment, getSuperwallProducts: suspend () -> Either<SuperwallProductsResponse, NetworkError> = { Either.Failure(NetworkError.Unknown()) }, entitlements: Entitlements? = null, activityProvider: () -> ActivityProvider? = { null }, activityTracker: () -> CurrentActivityTracker? = { null }, hasExternalPurchaseController: () -> Boolean = { false }, apiKey: () -> String = { "" }, dashboardBaseUrl: () -> String = { "" }, tracker: suspend (TrackableSuperwallEvent) -> Unit = { }, showModal: suspend (activity: Activity, reason: String, hasPurchaseController: Boolean, availableEntitlements: List<String>, apiKey: String, dashboardBaseUrl: String, savedSettings: TestModeSettings?) -> TestModeModalResult = { activity, reason, hasPC, available, ak, db, saved -> TestModeModal.show(activity, reason, hasPC, available, ak, db, saved) }, ioScope: CoroutineScope = IOScope(), actor: StateActor<TestModeContext, TestModeState> = SequentialActor(TestModeState.Inactive, ioScope))

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val activityProvider: () -> ActivityProvider?
Link copied to clipboard
open override val activityTracker: () -> CurrentActivityTracker?
Link copied to clipboard
Link copied to clipboard
open override val apiKey: () -> String
Link copied to clipboard
open override val dashboardBaseUrl: () -> String
Link copied to clipboard
open override val entitlements: Entitlements?
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override val hasExternalPurchaseController: () -> Boolean
Link copied to clipboard
open override val isTestEnvironment: Boolean
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override val scope: CoroutineScope
Link copied to clipboard
open override val showModal: suspend (activity: Activity, reason: String, hasPurchaseController: Boolean, availableEntitlements: List<String>, apiKey: String, dashboardBaseUrl: String, savedSettings: TestModeSettings?) -> TestModeModalResult
Link copied to clipboard
open override val state: StateFlow<TestModeState>

Delegate state reads to the actor.

Link copied to clipboard
open override val storage: Storage
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override val tracker: suspend (TrackableSuperwallEvent) -> Unit

Functions

Link copied to clipboard
suspend fun activate(config: Config, justActivated: Boolean)

Refresh the test product catalog and (when justActivated) present the modal. Runs as a TestModeState.Actions.Activate action and suspends until it completes, so callers that must not wait on the modal's blocking UI (e.g. ConfigState) launch it in their own scope.

Link copied to clipboard
Link copied to clipboard
suspend fun awaitTestProducts(timeout: Duration = 5.seconds)

Suspend until the test product catalog has been loaded (or timeout elapses). No-op when inactive.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open fun delete(storable: Storable<*>)

Delete a value from storage.

Link copied to clipboard

Fire-and-forget dispatch of a sub-action on this context's actor.

Link copied to clipboard
Link copied to clipboard
fun evaluateTestMode(config: Config, bundleId: String, appUserId: String?, aliasId: String?, testModeBehavior: TestModeBehavior = TestModeBehavior.AUTOMATIC)
Link copied to clipboard
Link copied to clipboard
open suspend fun immediate(action: TypedAction<TestModeContext>)
Link copied to clipboard
open suspend fun immediateUntil(action: TypedAction<TestModeContext>, until: (TestModeState) -> Boolean)
Link copied to clipboard
Link copied to clipboard
open fun <T : Any> persist(storable: Storable<T>, value: T)

Persist a value to storage.

Link copied to clipboard
open fun <T : Any> read(storable: Storable<T>): Result<T>
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
fun setTestProducts(productsByFullId: Map<String, StoreProduct>)
Link copied to clipboard
fun shouldShowFreeTrial(hasFreeTrial: Boolean): Boolean
Link copied to clipboard
open fun sideEffect(what: suspend () -> Unit)
Link copied to clipboard
open fun track(event: TrackableSuperwallEvent)
Link copied to clipboard
open override fun update(reducer: Reducer<TestModeState>)

Apply a state reducer inline.