All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.arildo.iris.mock.dsl.ScopeDsl.kt Maven / Gradle / Ivy

Go to download

A kotlin-first tool to intercept android network calls, modify requests/responses and mock entire APIs

There is a newer version: 1.1.0
Show newest version
@file:JvmMultifileClass
@file:Suppress("unused", "UnusedReceiverParameter")

package dev.arildo.iris.mock.dsl

import dev.arildo.iris.mock.IrisMock
import dev.arildo.iris.mock.IrisMockScope
import dev.arildo.iris.mock.util.readRequestBody
import okhttp3.Interceptor
import okhttp3.Response

/**
 * Starts a new `IrisMockScope`, where all DSL functions will be available.
 * @return the result [Response] to be consumed by `OkHttp` interceptor
 */
fun irisMockScope(
    chain: Interceptor.Chain,
    block: IrisMockScope.() -> Unit
): Response = IrisMockScope(chain).also(block).build()

/**
 * Verify if the [value] is included on request body
 * @return true if it's included
 */
fun IrisMockScope.requestBodyContains(value: String, ignoreCase: Boolean = true): Boolean =
    readRequestBody(request).contains(value, ignoreCase)

/**
 * Enable logs for all calls.
 */
fun IrisMockScope.enableLogs() {
    IrisMock.enableLogs = true
}

/**
 * Disable logs for all calls.
 */
fun IrisMockScope.disableLogs() {
    IrisMock.enableLogs = false
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy