From 50ae04bb4e87d3018c8becea569aab8c6af67e6d Mon Sep 17 00:00:00 2001 From: Azalea <22280294+hykilpikonna@users.noreply.github.com> Date: Thu, 28 Mar 2024 01:22:16 -0400 Subject: [PATCH] [+] Wacca test (incomplete) --- .../samnyan/aqua/sega/wacca/WaccaServer.kt | 18 ++++----- src/test/kotlin/test/WaccaTest.kt | 38 +++++++++++++++++++ 2 files changed, 47 insertions(+), 9 deletions(-) create mode 100644 src/test/kotlin/test/WaccaTest.kt diff --git a/src/main/java/icu/samnyan/aqua/sega/wacca/WaccaServer.kt b/src/main/java/icu/samnyan/aqua/sega/wacca/WaccaServer.kt index 47e3269d..81ebbf50 100644 --- a/src/main/java/icu/samnyan/aqua/sega/wacca/WaccaServer.kt +++ b/src/main/java/icu/samnyan/aqua/sega/wacca/WaccaServer.kt @@ -50,7 +50,7 @@ class WaccaServer(val rp: WaccaRepos) { /** Handle all requests */ @API("/api/**") fun handle(req: HttpServletRequest, @RB body: String): Any { - val path = req.requestURI.removePrefix("/g/wacca").removePrefix("/api").lowercase() + val path = req.requestURI.removePrefix("/g/wacca").removePrefix("/api").removePrefix("/").lowercase() if (path in cacheMap) return resp(cacheMap[path]!!) if (path !in handlerMap) return resp("[]", 1, "Not Found") @@ -61,20 +61,20 @@ class WaccaServer(val rp: WaccaRepos) { } fun WaccaServer.api() { - "/housing/get" cached { ls("housingId" - 39, "isNewCab" - 0) } - "/housing/start" cached { ls("regionId" - 1, "recommendSongList" - ls(1269, 1007, 1270, 1002, 1020, 1003, 1008, + "housing/get" cached { ls("housingId" - 39, "isNewCab" - 0) } + "housing/start" cached { ls("regionId" - 1, "recommendSongList" - ls(1269, 1007, 1270, 1002, 1020, 1003, 1008, 1211, 1018, 1092, 1056, 32, 1260, 1230, 1258, 1251, 2212, 1264, 1125, 1037, 2001, 1272, 1126, 1119, 1104, 1070, 1047, 1044, 1027, 1004, 1001, 24, 2068, 2062, 2021, 1275, 1249, 1207, 1203, 1107, 1021, 1009, 9, 4, 3, 23, 22, 2014, 13, 1276, 1247, 1240, 1237, 1128, 1114, 1110, 1109, 1102, 1045, 1043, 1036, 1035, 1030, 1023, 1015)) } - "/advertise/GetRanking" cached { empty } - "/advertise/GetNews" cached { ls("notices" - empty, "copyright" - empty, empty, empty, empty, empty, empty, empty, empty) } - "/user/info/GetMyRoom" cached { ls(0, 0, 0, 0, 0, empty, 0, 0, 0) } - "/user/status/Logout" cached { empty } - "/user/info/GetRanking" cached { ls("totalScore#" - 0, "highScoreBySong#" - 0, "cumulativeScore#" - 0, + "advertise/GetRanking" cached { empty } + "advertise/GetNews" cached { ls("notices" - empty, "copyright" - empty, empty, empty, empty, empty, empty, empty, empty) } + "user/info/GetMyRoom" cached { ls(0, 0, 0, 0, 0, empty, 0, 0, 0) } + "user/status/Logout" cached { empty } + "user/info/GetRanking" cached { ls("totalScore#" - 0, "highScoreBySong#" - 0, "cumulativeScore#" - 0, "stateUpScore#" - 0, "otherScore#" - 0, "waccaPoints#" - 0) } - "/user/status/get" { req, (uid) -> + "user/status/get" { req, (uid) -> val ru = rp.user.findById(uid as Long)() val u = ru ?: WaccaUser() val o = options(u) diff --git a/src/test/kotlin/test/WaccaTest.kt b/src/test/kotlin/test/WaccaTest.kt new file mode 100644 index 00000000..6e5b829d --- /dev/null +++ b/src/test/kotlin/test/WaccaTest.kt @@ -0,0 +1,38 @@ +package test + +import ext.* +import io.kotest.core.spec.style.StringSpec +import io.kotest.matchers.shouldBe +import io.ktor.client.request.* +import io.ktor.client.statement.* +import io.ktor.http.* + +class WaccaTest : StringSpec({ + val version = "3.07.01.JPN.26935.S" + var uid = 0L + var requestNo = 10000 + + data class PostResp(val resp: HttpResponse, val res: List) + suspend fun post(url: String, par: String): PostResp { + requestNo++ + val resp = HTTP.post("$HOST/gs/$CLIENT_ID/wacca/api/$url") { + contentType(ContentType.Application.Json) + setBody("""{"requestNo": ${requestNo++},"appVersion": "$version","boardId": "$BOARD_ID","chipId": "$FULL_CLIENT_ID","params": $par}""") + } + + assert(resp.status.isSuccess()) { "Failed to post to $url: ${resp.status} - ${resp.bodyAsText()}" } + val res = resp.bodyAsText().jsonMap() + res["status"] shouldBe 0 + res.keys shouldBe setOf("status", "message", "serverTime", "maintNoticeTime", "maintNotPlayableTime", "maintStartTime", "params") + + return PostResp(resp, res["params"] as List) + } + + beforeTest { + if (uid == 0L) uid = registerUser() + } + + "housing/get" { + post("housing/get", "[]").res shouldBe "[39, 0]".jsonArray() + } +}) \ No newline at end of file