Skip to content

Commit

Permalink
An integration test for optional results (#151)
Browse files Browse the repository at this point in the history
* An integration test for optional results.

See #150

* Refactoring into current package structure.

* Cleanup (this will be squashed :o)
  • Loading branch information
d4rken authored and smyrick committed Jan 22, 2019
1 parent 1d78a12 commit 4d230fc
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.expedia.graphql.integration

import com.expedia.graphql.TopLevelObject
import com.expedia.graphql.testSchemaConfig
import com.expedia.graphql.toSchema
import graphql.GraphQL
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertNull

class OptionalResultsTest {
@Test
fun `SchemaGenerator generates a simple GraphQL schema`() {
val schema = toSchema(
listOf(TopLevelObject(QueryObject())),
listOf(),
config = testSchemaConfig
)
val graphQL = GraphQL.newGraphQL(schema).build()

val result = graphQL.execute("{optionalResults{required optional}}")
val data: Map<String, Map<String, Any>>? = result.getData()

val optionalResults = data?.get("optionalResults")
assertNotNull(optionalResults)
assertEquals(2, optionalResults.size)
assertEquals("req", optionalResults["required"])
assertNull(optionalResults["optional"])
}
}

data class HasOptionalData(
val required: String,
val optional: String?
)

class QueryObject {
fun optionalResults() = HasOptionalData("req", null)
}

0 comments on commit 4d230fc

Please sign in to comment.