Skip to content

Commit

Permalink
Fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
gnawf committed Mar 11, 2024
1 parent e719a94 commit 2093b44
Showing 1 changed file with 35 additions and 33 deletions.
68 changes: 35 additions & 33 deletions lib/src/test/kotlin/graphql/nadel/NadelSchemasTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package graphql.nadel

import graphql.language.NamedNode
import graphql.language.SourceLocation
import graphql.nadel.engine.util.getField
import graphql.nadel.engine.util.makeFieldCoordinates
import graphql.nadel.schema.ServiceSchemaProblem
Expand All @@ -10,6 +11,7 @@ import graphql.schema.idl.SchemaParser
import graphql.schema.idl.TypeDefinitionRegistry
import io.kotest.core.spec.style.DescribeSpec
import org.junit.jupiter.api.assertThrows
import kotlin.test.assertTrue

val NadelDefinitionRegistry.typeNames: Set<String>
get() = definitions
Expand Down Expand Up @@ -73,9 +75,9 @@ class NadelSchemasTest : DescribeSpec({
.build()

// then
assert(schemas.engineSchema.userTypeNames == setOf("World", "Echo", "Query", "JSON"))
assertTrue(schemas.engineSchema.userTypeNames == setOf("World", "Echo", "Query", "JSON"))
val testService = schemas.services.single()
assert(testService.underlyingSchema.userTypeNames == setOf("World", "Echo", "Query", "Food"))
assertTrue(testService.underlyingSchema.userTypeNames == setOf("World", "Echo", "Query", "Food"))
}

it("throws wrapping ServiceSchemaProblem") {
Expand Down Expand Up @@ -104,8 +106,8 @@ class NadelSchemasTest : DescribeSpec({
}

// then
assert(ex.serviceName == "test")
assert(ex.message.contains("A schema MUST have a 'query' operation defined"))
assertTrue(ex.serviceName == "test")
assertTrue(ex.message.contains("A schema MUST have a 'query' operation defined"))
}

it("works if you exclusively supply type defs") {
Expand Down Expand Up @@ -149,9 +151,9 @@ class NadelSchemasTest : DescribeSpec({
.build()

// then
assert(schemas.engineSchema.userTypeNames == setOf("World", "Echo", "Query", "JSON"))
assertTrue(schemas.engineSchema.userTypeNames == setOf("World", "Echo", "Query", "JSON"))
val testService = schemas.services.single()
assert(testService.underlyingSchema.userTypeNames == setOf("World", "Echo", "Query", "Food"))
assertTrue(testService.underlyingSchema.userTypeNames == setOf("World", "Echo", "Query", "Food"))
}

it("works if you supply both type defs and readers") {
Expand Down Expand Up @@ -211,13 +213,13 @@ class NadelSchemasTest : DescribeSpec({
.build()

// then
assert(schemas.engineSchema.userTypeNames == setOf("World", "Echo", "Query", "Issue", "JSON"))
assertTrue(schemas.engineSchema.userTypeNames == setOf("World", "Echo", "Query", "Issue", "JSON"))

val issueService = schemas.services.single { it.name == "issue" }
assert(issueService.underlyingSchema.userTypeNames == setOf("Query", "Issue"))
assertTrue(issueService.underlyingSchema.userTypeNames == setOf("Query", "Issue"))

val testService = schemas.services.single { it.name == "test" }
assert(testService.underlyingSchema.userTypeNames == setOf("Query", "Echo", "World"))
assertTrue(testService.underlyingSchema.userTypeNames == setOf("Query", "Echo", "World"))
}

it("combines the overall schemas") {
Expand Down Expand Up @@ -272,7 +274,7 @@ class NadelSchemasTest : DescribeSpec({
.build()

// then
assert(schemas.engineSchema.userTypeNames == setOf("World", "Echo", "Query", "Issue", "JSON"))
assertTrue(schemas.engineSchema.userTypeNames == setOf("World", "Echo", "Query", "Issue", "JSON"))
}

it("does not validate the schemas") {
Expand Down Expand Up @@ -321,15 +323,15 @@ class NadelSchemasTest : DescribeSpec({
.build()

// then
assert(schemas.engineSchema.userTypeNames == setOf("Query", "World", "Echo", "Issue", "JSON"))
assertTrue(schemas.engineSchema.userTypeNames == setOf("Query", "World", "Echo", "Issue", "JSON"))

val testService = schemas.services.first { it.name == "test" }
assert(testService.definitionRegistry.typeNames == setOf("Query", "Echo", "World"))
assert(testService.underlyingSchema.userTypeNames == setOf("Query"))
assertTrue(testService.definitionRegistry.typeNames == setOf("Query", "Echo", "World"))
assertTrue(testService.underlyingSchema.userTypeNames == setOf("Query"))

val issueService = schemas.services.first { it.name == "issue" }
assert(issueService.underlyingSchema.userTypeNames == setOf("Query", "Task"))
assert(issueService.definitionRegistry.typeNames == setOf("Query", "Issue"))
assertTrue(issueService.underlyingSchema.userTypeNames == setOf("Query", "Task"))
assertTrue(issueService.definitionRegistry.typeNames == setOf("Query", "Issue"))
}

it("retains line numbers for string input") {
Expand Down Expand Up @@ -385,19 +387,19 @@ class NadelSchemasTest : DescribeSpec({
.build()

// then
assert(schemas.engineSchema.typeMap["Echo"]?.definition?.sourceLocation?.line == 4)
assert(schemas.engineSchema.typeMap["Issue"]?.definition?.sourceLocation?.line == 4)
assert(schemas.engineSchema.getField(echoCoordinates)?.definition?.sourceLocation?.line == 2)
assert(schemas.engineSchema.getField(worldCoordinates)?.definition?.sourceLocation?.line == 5)
assert(schemas.engineSchema.getField(issueIdCoordinates)?.definition?.sourceLocation?.line == 6)
assertTrue(schemas.engineSchema.typeMap["Echo"]?.definition?.sourceLocation?.line == 4)
assertTrue(schemas.engineSchema.typeMap["Issue"]?.definition?.sourceLocation?.line == 4)
assertTrue(schemas.engineSchema.getField(echoCoordinates)?.definition?.sourceLocation?.line == 2)
assertTrue(schemas.engineSchema.getField(worldCoordinates)?.definition?.sourceLocation?.line == 5)
assertTrue(schemas.engineSchema.getField(issueIdCoordinates)?.definition?.sourceLocation?.line == 6)

val testService = schemas.services.single { it.name == "test" }
assert(testService.underlyingSchema.typeMap["Echo"]?.definition?.sourceLocation?.line == 5)
assert(testService.underlyingSchema.getField(echoCoordinates)?.definition?.sourceLocation?.line == 2)
assert(testService.underlyingSchema.getField(worldCoordinates)?.definition?.sourceLocation?.line == 6)
assertTrue(testService.underlyingSchema.typeMap["Echo"]?.definition?.sourceLocation?.line == 5)
assertTrue(testService.underlyingSchema.getField(echoCoordinates)?.definition?.sourceLocation?.line == 2)
assertTrue(testService.underlyingSchema.getField(worldCoordinates)?.definition?.sourceLocation?.line == 6)

val issueService = schemas.services.single { it.name == "issue" }
assert(issueService.underlyingSchema.typeMap["Task"]?.definition?.sourceLocation?.line == 4)
assertTrue(issueService.underlyingSchema.typeMap["Task"]?.definition?.sourceLocation?.line == 4)
}

it("drops source location if not asked for") {
Expand Down Expand Up @@ -453,19 +455,19 @@ class NadelSchemasTest : DescribeSpec({
.build()

// then
assert(schemas.engineSchema.typeMap["Echo"]?.definition?.sourceLocation == null)
assert(schemas.engineSchema.typeMap["Issue"]?.definition?.sourceLocation == null)
assert(schemas.engineSchema.getField(echoCoordinates)?.definition?.sourceLocation == null)
assert(schemas.engineSchema.getField(worldCoordinates)?.definition?.sourceLocation == null)
assert(schemas.engineSchema.getField(issueIdCoordinates)?.definition?.sourceLocation == null)
assertTrue(schemas.engineSchema.typeMap["Echo"]?.definition?.sourceLocation == SourceLocation.EMPTY)
assertTrue(schemas.engineSchema.typeMap["Issue"]?.definition?.sourceLocation == SourceLocation.EMPTY)
assertTrue(schemas.engineSchema.getField(echoCoordinates)?.definition?.sourceLocation == SourceLocation.EMPTY)
assertTrue(schemas.engineSchema.getField(worldCoordinates)?.definition?.sourceLocation == SourceLocation.EMPTY)
assertTrue(schemas.engineSchema.getField(issueIdCoordinates)?.definition?.sourceLocation == SourceLocation.EMPTY)

val testService = schemas.services.single { it.name == "test" }
assert(testService.underlyingSchema.typeMap["Echo"]?.definition?.sourceLocation == null)
assert(testService.underlyingSchema.getField(echoCoordinates)?.definition?.sourceLocation == null)
assert(testService.underlyingSchema.getField(worldCoordinates)?.definition?.sourceLocation == null)
assertTrue(testService.underlyingSchema.typeMap["Echo"]?.definition?.sourceLocation == SourceLocation.EMPTY)
assertTrue(testService.underlyingSchema.getField(echoCoordinates)?.definition?.sourceLocation == SourceLocation.EMPTY)
assertTrue(testService.underlyingSchema.getField(worldCoordinates)?.definition?.sourceLocation == SourceLocation.EMPTY)

val issueService = schemas.services.single { it.name == "issue" }
assert(issueService.underlyingSchema.typeMap["Task"]?.definition?.sourceLocation == null)
assertTrue(issueService.underlyingSchema.typeMap["Task"]?.definition?.sourceLocation == SourceLocation.EMPTY)
}
}
})

0 comments on commit 2093b44

Please sign in to comment.