Test for update checking
This commit is contained in:
@@ -10,7 +10,7 @@ class GithubRepository(private val okHttp: OkHttpClient) {
|
||||
suspend fun getLatestVersion(): AppVersion {
|
||||
val request = Request.Builder()
|
||||
.get()
|
||||
.url("https://api.github.com/repos/nv95/Kotatsu/releases/latest")
|
||||
.url("https://api.github.com/repos/KotatsuApp/Kotatsu/releases/latest")
|
||||
val json = okHttp.newCall(request.build()).await().parseJson()
|
||||
val asset = json.getJSONArray("assets").getJSONObject(0)
|
||||
return AppVersion(
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
package org.koitharu.kotatsu.core.github
|
||||
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.Request
|
||||
import okhttp3.internal.headersContentLength
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.koitharu.kotatsu.BuildConfig
|
||||
import org.koitharu.kotatsu.parsers.util.await
|
||||
|
||||
class GithubRepositoryTest {
|
||||
|
||||
private val okHttpClient = OkHttpClient()
|
||||
private val repository = GithubRepository(okHttpClient)
|
||||
|
||||
@Test
|
||||
fun getLatestVersion() = runTest {
|
||||
val version = repository.getLatestVersion()
|
||||
val versionId = VersionId(version.name)
|
||||
|
||||
val apkHead = okHttpClient.newCall(
|
||||
Request.Builder()
|
||||
.url(version.apkUrl)
|
||||
.head()
|
||||
.build()
|
||||
).await()
|
||||
|
||||
Assert.assertTrue(versionId <= VersionId(BuildConfig.VERSION_NAME))
|
||||
Assert.assertTrue(apkHead.isSuccessful)
|
||||
Assert.assertEquals(version.apkSize, apkHead.headersContentLength())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user