Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasPfeifer committed Feb 28, 2020
1 parent c38240e commit 2f25426
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 2 deletions.
50 changes: 50 additions & 0 deletions core/src/test/scala/caliban/TestUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,55 @@ object TestUtils {
resolverIO.queryResolver,
WrongMutationUnion(_ => UIO.unit)
)

@GQLInterface
sealed trait InterfaceEmpty
object InterfaceEmpty {
case class A(x: String) extends InterfaceEmpty
case class B(y: String) extends InterfaceEmpty
}

case class TestEmpty(i: InterfaceEmpty)
val resolverEmptyInferface = RootResolver(
TestEmpty(InterfaceEmpty.A("a"))
)

@GQLInterface
sealed trait InterfaceWrongFieldName
object InterfaceWrongFieldName {
case class A(__name: String) extends InterfaceWrongFieldName
case class B(__name: String) extends InterfaceWrongFieldName
}

case class TestWrongFieldName(i: InterfaceWrongFieldName)
val resolverInferfaceWrongFieldName = RootResolver(
TestWrongFieldName(InterfaceWrongFieldName.A("a"))
)

case class WrongArgumentName(__name: String)

@GQLInterface
sealed trait InterfaceWrongArgumentName
object InterfaceWrongArgumentName {
case class A(x: WrongArgumentName => UIO[Unit]) extends InterfaceWrongArgumentName
case class B(x: WrongArgumentName => UIO[Unit]) extends InterfaceWrongArgumentName
}

case class TestWrongArgumentName(i: InterfaceWrongArgumentName)
val resolverInterfaceWrongArgumentName = RootResolver(
TestWrongArgumentName(InterfaceWrongArgumentName.A(_ => UIO.unit))
)

@GQLInterface
sealed trait InterfaceWrongArgumentInputType
object InterfaceWrongArgumentInputType {
case class A(x: UnionInputObjectArg => UIO[Unit]) extends InterfaceWrongArgumentInputType
case class B(x: UnionInputObjectArg => UIO[Unit]) extends InterfaceWrongArgumentInputType
}

case class TestWrongArgumentType(i: InterfaceWrongArgumentInputType)
val resolverInterfaceWrongArgumentInputType = RootResolver(
TestWrongArgumentType(InterfaceWrongArgumentInputType.A(_ => UIO.unit))
)
}
}
30 changes: 28 additions & 2 deletions core/src/test/scala/caliban/validation/ValidationSchemaSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object ValidationSchemaSpec
def check(gql: GraphQL[Any], expectedMessage: String): IO[ValidationError, TestResult] =
assertM(gql.interpreter.run, fails[ValidationError](hasField("msg", _.msg, equalTo(expectedMessage))))

suite("ValidationSchemaSpec")({
suite("ValidationSchemaSpec")(
suite("InputObjects")(
testM("name can't start with '__'") {
check(
Expand All @@ -27,6 +27,32 @@ object ValidationSchemaSpec
"UnionInput is of kind UNION, must be an InputType"
)
}
),
suite("Interface")(
testM("must define one or more fields") {
check(
graphQL(resolverEmptyInferface),
"message"
)
},
testM("field name can't start with '__'") {
check(
graphQL(resolverInferfaceWrongFieldName),
"A field in Interface can't start with '__': __name"
)
},
testM("field argument name can't start with '__'") {
check(
graphQL(resolverInterfaceWrongArgumentName),
"A argument input value in Interface can't start with '__': __name"
)
},
testM("field argument can't be output type") {
check(
graphQL(resolverInterfaceWrongArgumentInputType),
"UnionInput is of kind UNION, must be an InputType"
)
}
)
})
)
})

0 comments on commit 2f25426

Please sign in to comment.