Skip to content

Commit 767e89a

Browse files
author
smyrick
committed
test: add a unit test for missing coverage
1 parent 88c6eeb commit 767e89a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/test/kotlin/com/expedia/graphql/execution/FunctionDataFetcherTest.kt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ import com.expedia.graphql.exceptions.CouldNotCastArgumentException
55
import graphql.schema.DataFetchingEnvironment
66
import io.mockk.every
77
import io.mockk.mockk
8+
import kotlinx.coroutines.delay
89
import org.junit.jupiter.api.Test
10+
import java.util.concurrent.CompletableFuture
911
import kotlin.test.assertEquals
1012
import kotlin.test.assertFailsWith
1113
import kotlin.test.assertNull
14+
import kotlin.test.assertTrue
1215

1316
internal class FunctionDataFetcherTest {
1417

@@ -22,6 +25,11 @@ internal class FunctionDataFetcherTest {
2225
fun context(@GraphQLContext string: String) = string
2326

2427
fun dataFetchingEnvironment(environment: DataFetchingEnvironment) = environment.field.name
28+
29+
suspend fun suspendPrint(string: String): String = kotlinx.coroutines.coroutineScope {
30+
delay(10)
31+
string
32+
}
2533
}
2634

2735
@Test
@@ -105,4 +113,16 @@ internal class FunctionDataFetcherTest {
105113
}
106114
assertEquals(expected = "fooBarBaz", actual = dataFetcher.get(mockEnvironmet))
107115
}
116+
117+
@Test
118+
fun `suspend functions return value wrapped in CompletableFuture`() {
119+
val dataFetcher = FunctionDataFetcher(target = MyClass(), fn = MyClass::suspendPrint)
120+
val mockEnvironmet: DataFetchingEnvironment = mockk()
121+
every { mockEnvironmet.arguments } returns mapOf("string" to "hello")
122+
123+
val result = dataFetcher.get(mockEnvironmet)
124+
125+
assertTrue(result is CompletableFuture<*>)
126+
assertEquals(expected = "hello", actual = result.get())
127+
}
108128
}

0 commit comments

Comments
 (0)