resolve PR comment

This commit is contained in:
Jason Yao
2024-07-24 22:47:23 -07:00
parent f896183309
commit b3c9f5b03b
18 changed files with 121 additions and 88 deletions
@@ -4,7 +4,7 @@ import com.google.gson.Gson
import io.legado.app.exception.NoStackTraceException
import io.legado.app.help.http.okHttpClient
import io.legado.app.model.GithubRelease
import io.legado.app.utils.fromJsonArray
import io.legado.app.utils.fromJsonObject
import okhttp3.Request
import org.junit.Assert.assertTrue
import org.junit.Test
@@ -12,21 +12,41 @@ import org.junit.Test
class UpdateTest {
private val lastReleaseUrl =
"https://api.github.com/repos/gedoor/legado/releases?page=1?per_page=1"
"https://api.github.com/repos/gedoor/legado/releases/latest"
private val lastBetaReleaseUrl =
"https://api.github.com/repos/gedoor/legado/releases/tags/beta"
@Test
fun updateApp_beta() {
val body = okHttpClient.newCall(Request.Builder().url(lastBetaReleaseUrl).build()).execute()
.body!!.string()
val releaseList = Gson().fromJsonObject<GithubRelease>(body)
.getOrElse {
throw NoStackTraceException("获取新版本出错 " + it.localizedMessage)
}
.gitReleaseToAppReleaseInfo()
.sortedByDescending { it.createdAt }
assertTrue(releaseList.size == 2)
assertTrue(releaseList.all { it.downloadUrl.isNotBlank() })
assertTrue(releaseList.all { it.versionName.isNotBlank() })
}
@Test
fun updateApp() {
val body = okHttpClient.newCall(Request.Builder().url(lastReleaseUrl).build()).execute()
.body!!.string()
val releaseList = Gson().fromJsonArray<GithubRelease>(body)
val releaseList = Gson().fromJsonObject<GithubRelease>(body)
.getOrElse {
throw NoStackTraceException("获取新版本出错 " + it.localizedMessage)
}
.flatMap { it.gitReleaseToAppReleaseInfo() }
.gitReleaseToAppReleaseInfo()
.sortedByDescending { it.createdAt }
assertTrue(releaseList.isNotEmpty())
assertTrue(releaseList.size == 1)
assertTrue(releaseList.all { it.downloadUrl.isNotBlank() })
assertTrue(releaseList.all { it.versionName.isNotBlank() })
}