Skip to content

Commit

Permalink
test: add more hook tests (#133)
Browse files Browse the repository at this point in the history
* test: add more hook tests

* fix: drop test helper

* Delete DataFetcherExecutionPredicateTest.kt
  • Loading branch information
smyrick authored and dariuszkuc committed Jan 7, 2019
1 parent b715ed9 commit d6159d5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.expedia.graphql.hooks

import com.expedia.graphql.generator.extensions.getTypeOfFirstArgument
import graphql.schema.DataFetcher
import graphql.schema.GraphQLFieldDefinition
import graphql.schema.GraphQLSchema
Expand Down Expand Up @@ -35,7 +36,7 @@ interface SchemaGeneratorHooks {
*/
fun willResolveMonad(type: KType): KType =
if (type.classifier == CompletableFuture::class) {
type.arguments.firstOrNull()?.type ?: type
type.getTypeOfFirstArgument()
} else {
type
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.expedia.graphql.hooks

import com.expedia.graphql.TopLevelObject
import com.expedia.graphql.extensions.deepName
import com.expedia.graphql.generator.extensions.getSimpleName
import com.expedia.graphql.getTestSchemaConfigWithHooks
import com.expedia.graphql.toSchema
import graphql.GraphQL
Expand All @@ -11,6 +12,7 @@ import graphql.schema.GraphQLFieldDefinition
import graphql.schema.GraphQLObjectType
import graphql.schema.GraphQLSchema
import graphql.schema.GraphQLType
import java.util.concurrent.CompletableFuture
import kotlin.reflect.KFunction
import kotlin.reflect.KProperty
import kotlin.reflect.KType
Expand Down Expand Up @@ -207,10 +209,30 @@ class SchemaGeneratorHooksTest {
assertEquals("Hijacked Description", query.description)
}

@Test
fun `willResolveMonad returns CompletableFuture wrapped type`() {
val hooks = NoopSchemaGeneratorHooks()
val type = TestQueryFuture::comepletableFutre.returnType

assertEquals(expected = "SomeData", actual = hooks.willResolveMonad(type).getSimpleName())
}

@Test
fun `willResolveMonad returns basic type`() {
val hooks = NoopSchemaGeneratorHooks()
val type = TestQuery::query.returnType

assertEquals(expected = "SomeData", actual = hooks.willResolveMonad(type).getSimpleName())
}

class TestQuery {
fun query(): SomeData = SomeData(0)
}

class TestQueryFuture {
fun comepletableFutre(): CompletableFuture<SomeData> = CompletableFuture.completedFuture(SomeData(1))
}

data class SomeData(val someNumber: Int)

private class WrappingDataFetcher(private val dataFetcher: DataFetcher<*>) : DataFetcher<Any> {
Expand Down

0 comments on commit d6159d5

Please sign in to comment.