Package-level declarations

Types

Link copied to clipboard
class FakeApiClient(handler: suspend (FakeApiClient.RecordedRequest) -> Any? = { Unit }) : NetworkDataSource

A scriptable NetworkDataSource (and therefore ApiClient) that never touches HTTP: every call is recorded and answered by handler. Use it to unit-test code that sits above the client — a GenericRepository, a MutationQueue, a ViewModel — without building a MockEngine or encoding JSON.

Link copied to clipboard
class FakeAuthorizationProvider(initialToken: String? = "token", refreshedToken: String? = "refreshed-token", refreshSucceeds: Boolean = true) : AuthorizationProvider

A scriptable AuthorizationProvider for tests. Tracks how many times a refresh was requested and can simulate refresh success or failure.

Link copied to clipboard
class FakeReachabilityGate(reachable: Boolean = true) : ReachabilityGate

A controllable ReachabilityGate for tests. Starts reachable (default true, so awaitReachable returns immediately); flip it with setReachable to make a pending awaitReachable resume. awaitCount records how many times the gate was awaited.

Link copied to clipboard

A StructuredLogSink that records every line KenworkLogger emits, attributes included, so tests can assert on logging (e.g. that nothing sensitive is logged). Prefer withRecordedLogs, which installs one and restores the previous logger state afterwards.

Link copied to clipboard

A NetworkEventListener that records every emitted NetworkEvent for assertions.

Link copied to clipboard
class RecordingRetryPolicy(delegate: RetryPolicy = DefaultRetryPolicy()) : RetryPolicy

A RetryPolicy that records every decision and forwards to delegate, so tests can assert how many retries happened, for which errors, and with what delays. Defaults to wrapping a DefaultRetryPolicy.

Functions

Link copied to clipboard
fun MockRequestHandleScope.jsonResponse(body: String, status: HttpStatusCode = HttpStatusCode.OK): HttpResponseData

Responds with a JSON body and the given status.

Link copied to clipboard
fun mockNetworkClient(json: Json = DefaultKenworkJson, authorizationProvider: AuthorizationProvider? = null, maxAuthRefreshAttempts: Int = 1, retryDelayMillis: Long = 0, retryPolicy: RetryPolicy = RetryPolicy.None, reachabilityGate: ReachabilityGate? = null, eventListener: NetworkEventListener? = null, requestInterceptor: RequestInterceptor? = null, requestHeaderProvider: RequestHeaderProvider? = null, handler: suspend MockRequestHandleScope.(HttpRequestData) -> HttpResponseData): NetworkClient

Builds a NetworkClient backed by a Ktor MockEngine driven by handler. Intended for unit tests of code that depends on kenwork — no real sockets are opened.

Link copied to clipboard
inline fun <T> withRecordedLogs(level: LogLevel = LogLevel.DEBUG, block: (RecordingLogSink) -> T): T

Routes KenworkLogger to a fresh RecordingLogSink at level for the duration of block, then restores the previous sink and level — even if block throws.