Skip to content

Commit

Permalink
unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chrishonson committed Nov 26, 2023
1 parent 6620c87 commit 418902b
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 26 deletions.
39 changes: 39 additions & 0 deletions shared/src/commonTest/kotlin/com/example/kmptemplate/Test.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.example.kmptemplate

import Greeting
import io.ktor.client.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.http.*
import io.ktor.serialization.kotlinx.json.*
import io.ktor.utils.io.*
import kotlinx.coroutines.test.runTest
import kotlinx.serialization.json.Json
import kotlin.test.Test
import kotlin.test.assertTrue

class CommonGreetingTest {

fun testExample() {
runTest{
val mockEngine = MockEngine { request ->
respond(
content = ByteReadChannel("""[{"name":"CTS21","flight_number":42,"success":true,"date_utc":"2021-09-15T00:00:00Z"}]"""),
status = HttpStatusCode.OK,
headers = headersOf(HttpHeaders.ContentType, ContentType.Application.Json.toString())
)
}

val mockHttpClient = HttpClient(mockEngine) {
install(ContentNegotiation) {
json(Json {
prettyPrint = true
isLenient = true
ignoreUnknownKeys = true
})
}
}
assertTrue("Check 2021-09 is mentioned", Greeting(mockHttpClient).greet().contains("Greetings!"))

}
}
}
13 changes: 0 additions & 13 deletions shared/src/commonTest/kotlin/com/example/leveldetektor/Test.kt

This file was deleted.

43 changes: 43 additions & 0 deletions shared/src/iosTest/kotlin/com/example/kmptemplate/Test.ios.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.example.kmptemplate

import Greeting
import io.ktor.client.*
import io.ktor.client.engine.mock.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.http.*
import io.ktor.serialization.kotlinx.json.*
import io.ktor.utils.io.*
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest
import kotlinx.serialization.json.Json
import kotlin.test.Test
import kotlin.test.assertTrue

class IosGreetingTest {

@OptIn(ExperimentalCoroutinesApi::class)
@Test
fun testExample() {
runTest{
val mockEngine = MockEngine { request ->
respond(
content = ByteReadChannel("""[{"name":"CTS21","flight_number":42,"success":true,"date_utc":"2021-09-15T00:00:00Z"}]"""),
status = HttpStatusCode.OK,
headers = headersOf(HttpHeaders.ContentType, ContentType.Application.Json.toString())
)
}

val mockHttpClient = HttpClient(mockEngine) {
install(ContentNegotiation) {
json(Json {
prettyPrint = true
isLenient = true
ignoreUnknownKeys = true
})
}
}
assertTrue("Check 2021-09 is mentioned", Greeting(mockHttpClient).greet().contains("Greetings!"))

}
}
}
13 changes: 0 additions & 13 deletions shared/src/iosTest/kotlin/com/example/leveldetektor/Test.ios.kt

This file was deleted.

0 comments on commit 418902b

Please sign in to comment.