mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 22:17:03 +05:30
feat(android): migrate away from kotest
This commit is contained in:
parent
ae66aced83
commit
ea40650214
2 changed files with 49 additions and 36 deletions
|
@ -74,7 +74,13 @@ dependencies {
|
||||||
|
|
||||||
kapt(libs.dagger.compiler)
|
kapt(libs.dagger.compiler)
|
||||||
|
|
||||||
testImplementation(libs.kotest.assertions.core)
|
testImplementation(libs.junit.jupiter.api)
|
||||||
testImplementation(libs.kotest.runner.junit5)
|
testImplementation(libs.truth) { exclude(group = "junit", module = "junit") }
|
||||||
|
testRuntimeOnly(libs.junit.jupiter.engine)
|
||||||
|
testRuntimeOnly(libs.junit.legacy) {
|
||||||
|
// See https://github.com/google/truth/issues/333
|
||||||
|
because("Truth needs it")
|
||||||
|
}
|
||||||
|
testImplementation(libs.kotlinx.coroutines.test)
|
||||||
testImplementation(libs.okhttp.mockwebserver)
|
testImplementation(libs.okhttp.mockwebserver)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,34 +6,40 @@
|
||||||
*/
|
*/
|
||||||
package dev.msfjarvis.claw.android.viewmodel
|
package dev.msfjarvis.claw.android.viewmodel
|
||||||
|
|
||||||
import io.kotest.core.spec.Spec
|
import com.google.common.truth.Truth.assertThat
|
||||||
import io.kotest.core.spec.style.FunSpec
|
|
||||||
import io.kotest.matchers.shouldBe
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
|
import kotlinx.coroutines.test.runTest
|
||||||
import okhttp3.OkHttpClient
|
import okhttp3.OkHttpClient
|
||||||
import okhttp3.mockwebserver.Dispatcher
|
import okhttp3.mockwebserver.Dispatcher
|
||||||
import okhttp3.mockwebserver.MockResponse
|
import okhttp3.mockwebserver.MockResponse
|
||||||
import okhttp3.mockwebserver.MockWebServer
|
import okhttp3.mockwebserver.MockWebServer
|
||||||
import okhttp3.mockwebserver.RecordedRequest
|
import okhttp3.mockwebserver.RecordedRequest
|
||||||
|
import org.junit.jupiter.api.BeforeAll
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
|
|
||||||
class CSRFRepositoryTest : FunSpec() {
|
@OptIn(ExperimentalCoroutinesApi::class)
|
||||||
private val server = MockWebServer()
|
class CSRFRepositoryTest {
|
||||||
|
@Test
|
||||||
init {
|
fun `correctly extracts CSRF token`() = runTest {
|
||||||
test("Correctly extracts CSRF token").config(coroutineTestScope = true) {
|
|
||||||
val repo =
|
val repo =
|
||||||
CSRFRepository(
|
CSRFRepository(
|
||||||
OkHttpClient.Builder().build(),
|
OkHttpClient.Builder().build(),
|
||||||
Dispatchers.Default,
|
Dispatchers.Default,
|
||||||
server.url("/").toString(),
|
server.url("/").toString(),
|
||||||
)
|
)
|
||||||
repo.extractToken() shouldBe
|
assertThat(repo.extractToken())
|
||||||
|
.isEqualTo(
|
||||||
"OZWykgFemPVeOSNmB53-ccKXe458X7xCInO1-qzFU6nk_9RCSrSQqS9OPmA5_pyy8qD3IYAIZ7XfAM3gdhJpkQ"
|
"OZWykgFemPVeOSNmB53-ccKXe458X7xCInO1-qzFU6nk_9RCSrSQqS9OPmA5_pyy8qD3IYAIZ7XfAM3gdhJpkQ"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override suspend fun beforeSpec(spec: Spec) {
|
companion object {
|
||||||
super.beforeSpec(spec)
|
private val server = MockWebServer()
|
||||||
|
|
||||||
|
@JvmStatic
|
||||||
|
@BeforeAll
|
||||||
|
fun setup() {
|
||||||
val dispatcher =
|
val dispatcher =
|
||||||
object : Dispatcher() {
|
object : Dispatcher() {
|
||||||
override fun dispatch(request: RecordedRequest): MockResponse {
|
override fun dispatch(request: RecordedRequest): MockResponse {
|
||||||
|
@ -54,3 +60,4 @@ class CSRFRepositoryTest : FunSpec() {
|
||||||
server.dispatcher = dispatcher
|
server.dispatcher = dispatcher
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue