Skip to content

Commit

Permalink
start of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
digitalbuddha committed Dec 21, 2022
1 parent 06dff8e commit cd047c0
Show file tree
Hide file tree
Showing 6 changed files with 2,545 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ data class Status(
@SerialName("visibility") val visibility: Privacy,
@SerialName("sensitive") val sensitive: Boolean,
@SerialName("spoiler_text") val spoilerText: String,
@SerialName("media_attachments") val mediaAttachments: List<Attachment>?,
@SerialName("media_attachments") val mediaAttachments: List<Attachment>? = emptyList(),
@SerialName("application") val application: Application?=null,

// rendering attributes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ import io.ktor.utils.io.ByteReadChannel
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import kotlinx.serialization.json.Json
import social.androiddev.common.network.fixtures.homeFeed
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertNull
import kotlin.test.assertTrue

@OptIn(ExperimentalCoroutinesApi::class)
class MastodonApiTests {
class MastodonApiTests {

@Test
fun `instance list should be parsed correctly`() = runTest {
Expand Down Expand Up @@ -214,6 +215,22 @@ class MastodonApiTests {
// then
assertTrue(actual = result.isSuccess)
}
//TODO MIKE: Harden tests to validate inputs
@Test
fun `view home feed should succeed`() = runTest {
val mastodonApi = MastodonApiKtor(
httpClient = createMockClient(
statusCode = HttpStatusCode.OK, content = ByteReadChannel(text = homeFeed)
)
)

// when
val result = mastodonApi.getHomeFeed("","")

// then
assertTrue(actual = result.isSuccess)
assertTrue { result.getOrThrow().isNotEmpty() }
}

private fun createMockClient(
statusCode: HttpStatusCode = HttpStatusCode.OK,
Expand Down
Loading

0 comments on commit cd047c0

Please sign in to comment.