mirror of https://github.com/readrops/Readrops.git
Fix FeverDataSource tests
This commit is contained in:
parent
89c4dfad1a
commit
ba964ccce2
|
@ -1,19 +1,15 @@
|
|||
package com.readrops.api.services.fever.adapters
|
||||
package com.readrops.api.services.fever
|
||||
|
||||
import com.readrops.api.TestUtils
|
||||
import com.readrops.api.apiModule
|
||||
import com.readrops.api.services.fever.FeverCredentials
|
||||
import com.readrops.api.services.fever.FeverDataSource
|
||||
import com.readrops.api.utils.ApiUtils
|
||||
import com.readrops.api.utils.AuthInterceptor
|
||||
import com.readrops.api.utils.exceptions.LoginFailedException
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import okhttp3.OkHttpClient
|
||||
import okhttp3.mockwebserver.MockResponse
|
||||
import okhttp3.mockwebserver.MockWebServer
|
||||
import okio.Buffer
|
||||
import org.junit.After
|
||||
import org.junit.Assert.assertThrows
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
@ -24,6 +20,8 @@ import org.koin.test.KoinTestRule
|
|||
import org.koin.test.get
|
||||
import java.net.HttpURLConnection
|
||||
import java.util.concurrent.TimeUnit
|
||||
import kotlin.test.assertFalse
|
||||
import kotlin.test.assertTrue
|
||||
|
||||
class FeverDataSourceTest : KoinTest {
|
||||
|
||||
|
@ -59,30 +57,28 @@ class FeverDataSourceTest : KoinTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
fun loginSuccessfulTest() {
|
||||
fun loginSuccessfulTest() = runTest {
|
||||
val stream = TestUtils.loadResource("services/fever/successful_auth.json")
|
||||
|
||||
mockServer.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_OK)
|
||||
mockServer.enqueue(
|
||||
MockResponse().setResponseCode(HttpURLConnection.HTTP_OK)
|
||||
.addHeader(ApiUtils.CONTENT_TYPE_HEADER, "application/json")
|
||||
.setBody(Buffer().readFrom(stream)))
|
||||
.setBody(Buffer().readFrom(stream))
|
||||
)
|
||||
|
||||
runBlocking {
|
||||
dataSource.login("","")
|
||||
}
|
||||
assertTrue { dataSource.login("", "") }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun loginFailedTest() {
|
||||
fun loginFailedTest() = runTest {
|
||||
val stream = TestUtils.loadResource("services/fever/failed_auth.json")
|
||||
|
||||
mockServer.enqueue(MockResponse().setResponseCode(HttpURLConnection.HTTP_OK)
|
||||
mockServer.enqueue(
|
||||
MockResponse().setResponseCode(HttpURLConnection.HTTP_OK)
|
||||
.addHeader(ApiUtils.CONTENT_TYPE_HEADER, "application/json")
|
||||
.setBody(Buffer().readFrom(stream)))
|
||||
.setBody(Buffer().readFrom(stream))
|
||||
)
|
||||
|
||||
assertThrows(LoginFailedException::class.java) {
|
||||
runBlocking {
|
||||
dataSource.login("","")
|
||||
}
|
||||
}
|
||||
assertFalse { dataSource.login("", "") }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue