Skip to content

Commit 4d230fc

Browse files
d4rkensmyrick
authored andcommitted
An integration test for optional results (#151)
* An integration test for optional results. See #150 * Refactoring into current package structure. * Cleanup (this will be squashed :o)
1 parent 1d78a12 commit 4d230fc

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package com.expedia.graphql.integration
2+
3+
import com.expedia.graphql.TopLevelObject
4+
import com.expedia.graphql.testSchemaConfig
5+
import com.expedia.graphql.toSchema
6+
import graphql.GraphQL
7+
import kotlin.test.Test
8+
import kotlin.test.assertEquals
9+
import kotlin.test.assertNotNull
10+
import kotlin.test.assertNull
11+
12+
class OptionalResultsTest {
13+
@Test
14+
fun `SchemaGenerator generates a simple GraphQL schema`() {
15+
val schema = toSchema(
16+
listOf(TopLevelObject(QueryObject())),
17+
listOf(),
18+
config = testSchemaConfig
19+
)
20+
val graphQL = GraphQL.newGraphQL(schema).build()
21+
22+
val result = graphQL.execute("{optionalResults{required optional}}")
23+
val data: Map<String, Map<String, Any>>? = result.getData()
24+
25+
val optionalResults = data?.get("optionalResults")
26+
assertNotNull(optionalResults)
27+
assertEquals(2, optionalResults.size)
28+
assertEquals("req", optionalResults["required"])
29+
assertNull(optionalResults["optional"])
30+
}
31+
}
32+
33+
data class HasOptionalData(
34+
val required: String,
35+
val optional: String?
36+
)
37+
38+
class QueryObject {
39+
fun optionalResults() = HasOptionalData("req", null)
40+
}

0 commit comments

Comments
 (0)