-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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)
- Loading branch information
Showing
1 changed file
with
40 additions
and
0 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
src/test/kotlin/com/expedia/graphql/integration/OptionalResultsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |