diff --git a/src/test/kotlin/ext/TestExt.kt b/src/test/kotlin/ext/TestExt.kt new file mode 100644 index 00000000..78ba3e69 --- /dev/null +++ b/src/test/kotlin/ext/TestExt.kt @@ -0,0 +1,20 @@ +package ext + +import kotlin.random.Random +import kotlin.random.nextInt + +const val CLIENT_ID = "A1234567890" +const val FTK = "test" +const val HOST = "http://localhost" +val ACCESS_CODE = "9900" + (1..16).map { Random.nextInt(0..9) }.joinToString("") + +inline fun String.json() = try { + JACKSON.readValue(this, T::class.java) +} +catch (e: Exception) { + println("Failed to parse JSON: $this") + throw e +} + +fun String.jsonMap(): Map = json() +fun String.jsonArray(): List> = json() \ No newline at end of file diff --git a/src/test/kotlin/test/Mai2Test.kt b/src/test/kotlin/test/Mai2Test.kt index c7be1ee5..1a35710c 100644 --- a/src/test/kotlin/test/Mai2Test.kt +++ b/src/test/kotlin/test/Mai2Test.kt @@ -1,8 +1,6 @@ package test -import ext.HTTP -import ext.JACKSON -import ext.ensureEndingSlash +import ext.* import icu.samnyan.aqua.sega.util.Compression import io.kotest.core.spec.style.StringSpec import io.kotest.matchers.shouldBe @@ -10,19 +8,11 @@ import io.ktor.client.call.* import io.ktor.client.request.* import io.ktor.client.statement.* import io.ktor.http.* -import kotlin.random.Random -import kotlin.random.nextInt - -const val CLIENT_ID = "A1234567890" -const val FTK = "test" -const val HOST = "http://localhost" -const val BASE_URL = "$HOST/gs/A1234567890/mai2" var USER_ID = 0L -val ACCESS_CODE = "9900" + (1..16).map { Random.nextInt(0..9) }.joinToString("") suspend fun post(url: String, body: String): Pair> { - val resp = HTTP.post(BASE_URL.ensureEndingSlash() + url) { + val resp = HTTP.post("$HOST/gs/$CLIENT_ID/mai2".ensureEndingSlash() + url) { contentType(ContentType.Application.Json) setBody(body) } @@ -32,20 +22,6 @@ suspend fun post(url: String, body: String): Pair()).decodeToString().jsonMap()) } -suspend fun post(url: String, body: Map): Pair> = - post(url, JACKSON.writeValueAsString(body)) - -inline fun String.json() = try { - JACKSON.readValue(this, T::class.java) -} -catch (e: Exception) { - println("Failed to parse JSON: $this") - throw e -} - -fun String.jsonMap(): Map = json() -fun String.jsonArray(): List> = json() - class Mai2Test : StringSpec({ beforeTest { if (USER_ID != 0L) return@beforeTest