Skip to content

Commit

Permalink
test: update failing testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath committed Apr 9, 2023
1 parent 4a215e9 commit 234c870
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ object TSchema {

def empty: TSchema = TSchema.Obj(Map.empty)

def int: TSchema = TSchema.Num
def num: TSchema = TSchema.Num

def obj(map: Map[String, TSchema]): TSchema = TSchema.Obj(map)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ trait Config2Blueprint {

case None => field.typeOf match {
case "String" => TSchema.string
case "Int" => TSchema.int
case "Int" => TSchema.num
case "Boolean" => TSchema.bool
case _ => TSchema.string // TODO: default to string?
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object Endpoint2GraphQLSchemaSpec extends ZIOSpecDefault with Endpoint2Config {
assertSchema(endpoint)(expected.trim)
},
test("nested output schema") {
val output = TSchema.obj("a" -> TSchema.obj("b" -> TSchema.obj("c" -> TSchema.int)))
val output = TSchema.obj("a" -> TSchema.obj("b" -> TSchema.obj("c" -> TSchema.num)))
val endpoint = Endpoint.make("abc.com").withOutput(Option(output)).withPath("/abc")
val expected = """
|schema @server(baseURL: "http://abc.com") {
Expand Down Expand Up @@ -97,8 +97,8 @@ object Endpoint2GraphQLSchemaSpec extends ZIOSpecDefault with Endpoint2Config {
},
test("nested argument schema") {
val endpoint = Endpoint.make("abc.com")
.withInput(Option(TSchema.obj("a" -> TSchema.obj("b" -> TSchema.obj("c" -> TSchema.int)))))
.withOutput(Option(TSchema.int))
.withInput(Option(TSchema.obj("a" -> TSchema.obj("b" -> TSchema.obj("c" -> TSchema.num)))))
.withOutput(Option(TSchema.num))

val expected = """
|schema @server(baseURL: "http://abc.com") {
Expand Down
34 changes: 17 additions & 17 deletions runtime/src/test/scala/tailcall/runtime/JsonValue2TSchemaSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,40 +13,40 @@ object JsonValue2TSchemaSpec extends ZIOSpecDefault with JsonValue2TSchema {
suite("json to TSchema")(
suite("unify")(
test("removes duplicates") {
val schema = unify(TSchema.int, TSchema.int)
assertZIO(schema.toZIO)(isSome(equalTo(TSchema.int)))
val schema = unify(TSchema.num, TSchema.num)
assertZIO(schema.toZIO)(isSome(equalTo(TSchema.num)))
},
test("objects") {
val schema = unify(TSchema.obj("a" -> TSchema.int), TSchema.obj("b" -> TSchema.int))
assertZIO(schema.toZIO)(isSome(equalTo(TSchema.obj("a" -> TSchema.int.opt, "b" -> TSchema.int.opt))))
val schema = unify(TSchema.obj("a" -> TSchema.num), TSchema.obj("b" -> TSchema.num))
assertZIO(schema.toZIO)(isSome(equalTo(TSchema.obj("a" -> TSchema.num.opt, "b" -> TSchema.num.opt))))
},
test("array") {
val schema = unify(TSchema.obj("a" -> TSchema.int).arr, TSchema.obj("b" -> TSchema.int).arr)
assertZIO(schema.toZIO)(isSome(equalTo(TSchema.obj("a" -> TSchema.int.opt, "b" -> TSchema.int.opt).arr)))
val schema = unify(TSchema.obj("a" -> TSchema.num).arr, TSchema.obj("b" -> TSchema.num).arr)
assertZIO(schema.toZIO)(isSome(equalTo(TSchema.obj("a" -> TSchema.num.opt, "b" -> TSchema.num.opt).arr)))
},
test("optional(a) b") {
val schema = unify(TSchema.obj("a" -> TSchema.int.opt), TSchema.obj("a" -> TSchema.int))
assertZIO(schema.toZIO)(isSome(equalTo(TSchema.obj("a" -> TSchema.int.opt))))
val schema = unify(TSchema.obj("a" -> TSchema.num.opt), TSchema.obj("a" -> TSchema.num))
assertZIO(schema.toZIO)(isSome(equalTo(TSchema.obj("a" -> TSchema.num.opt))))
},
test("a optional(b)") {
val schema = unify(TSchema.obj("a" -> TSchema.int), TSchema.obj("a" -> TSchema.int.opt))
assertZIO(schema.toZIO)(isSome(equalTo(TSchema.obj("a" -> TSchema.int.opt))))
val schema = unify(TSchema.obj("a" -> TSchema.num), TSchema.obj("a" -> TSchema.num.opt))
assertZIO(schema.toZIO)(isSome(equalTo(TSchema.obj("a" -> TSchema.num.opt))))
},
test("optional(a) optional(b)") {
val schema = unify(TSchema.obj("a" -> TSchema.int.opt), TSchema.obj("a" -> TSchema.int.opt))
assertZIO(schema.toZIO)(isSome(equalTo(TSchema.obj("a" -> TSchema.int.opt))))
val schema = unify(TSchema.obj("a" -> TSchema.num.opt), TSchema.obj("a" -> TSchema.num.opt))
assertZIO(schema.toZIO)(isSome(equalTo(TSchema.obj("a" -> TSchema.num.opt))))
},
test("int and string") {
val schema = unify(TSchema.int, TSchema.string)
val schema = unify(TSchema.num, TSchema.string)
assertZIO(schema.toZIO)(isNone)
},
test("deeply nested") {
val schema = unify(
TSchema.obj("a" -> TSchema.obj("b" -> TSchema.obj("x" -> TSchema.int))),
TSchema.obj("a" -> TSchema.obj("b" -> TSchema.obj("y" -> TSchema.int))),
TSchema.obj("a" -> TSchema.obj("b" -> TSchema.obj("x" -> TSchema.num))),
TSchema.obj("a" -> TSchema.obj("b" -> TSchema.obj("y" -> TSchema.num))),
)
assertZIO(schema.toZIO)(isSome(
equalTo(TSchema.obj("a" -> TSchema.obj("b" -> TSchema.obj("x" -> TSchema.int.opt, "y" -> TSchema.int.opt))))
equalTo(TSchema.obj("a" -> TSchema.obj("b" -> TSchema.obj("x" -> TSchema.num.opt, "y" -> TSchema.num.opt))))
))
},
),
Expand Down Expand Up @@ -79,7 +79,7 @@ object JsonValue2TSchemaSpec extends ZIOSpecDefault with JsonValue2TSchema {
test("nullables with multiple keys to TSchema") {
val json = Json
.Arr(Json.Obj("a" -> Json.Num(1), "b" -> Json.Null), Json.Obj("a" -> Json.Null, "b" -> Json.Num(1)))
val expected = TSchema.arr(TSchema.obj("a" -> TSchema.int.opt, "b" -> TSchema.int.opt))
val expected = TSchema.arr(TSchema.obj("a" -> TSchema.num.opt, "b" -> TSchema.num.opt))
assertZIO(toTSchema(json).toZIO)(equalTo(expected))
},
test("numeric keys") {
Expand Down
6 changes: 3 additions & 3 deletions runtime/src/test/scala/tailcall/runtime/LambdaSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,14 @@ object LambdaSpec extends ZIOSpecDefault {
suite("unsafe")(
test("endpoint /users/1") {
val endpoint = Endpoint.make("jsonplaceholder.typicode.com").withPath("/users/{{id}}")
.withOutput(Option(TSchema.obj("id" -> TSchema.int, "name" -> TSchema.string)))
.withOutput(Option(TSchema.obj("id" -> TSchema.num, "name" -> TSchema.string)))
val program = Lambda.unsafe.fromEndpoint(endpoint)
val expected = DynamicValueUtil.record("id" -> DynamicValue(1), "name" -> DynamicValue("Leanne Graham"))
val expected = DynamicValueUtil.record("id" -> DynamicValue(1L), "name" -> DynamicValue("Leanne Graham"))
assertZIO(program.evaluate(DynamicValue(Map("id" -> 1))))(equalTo(expected))
},
test("error") {
val endpoint = Endpoint.make("jsonplaceholder.typicode.com").withPath("/users/{{id}}")
.withOutput(Option(TSchema.obj("id" -> TSchema.int, "name" -> TSchema.string)))
.withOutput(Option(TSchema.obj("id" -> TSchema.num, "name" -> TSchema.string)))
val program = Lambda.unsafe.fromEndpoint(endpoint).evaluate(DynamicValue(Map("id" -> 100))).flip
.map(_.getMessage)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tailcall.runtime

import caliban.{CalibanError, InputValue}
import tailcall.runtime.http.HttpClient
import tailcall.runtime.model.Orc.{Field, FieldSet}
import tailcall.runtime.model.{Blueprint, Orc}
import tailcall.runtime.remote._
import tailcall.runtime.service.DataLoader.HttpDataLoader
Expand All @@ -11,8 +12,6 @@ import zio.http.Client
import zio.test.Assertion.equalTo
import zio.test.{ZIOSpecDefault, assertZIO}

import Orc.{Field, FieldSet}

object StepGeneratorSpec extends ZIOSpecDefault {

def spec = {
Expand Down Expand Up @@ -85,12 +84,12 @@ object StepGeneratorSpec extends ZIOSpecDefault {
test("with nesting level 3") {
// type Query {foo: Foo}
// type Foo {bar: [Bar]}
// type Bar {baz: [Baz]}
// type Bar {baz: Baz}
// type Baz{value: Int}
val orc = Orc(
"Query" -> FieldSet("foo" -> Field.output.to("Foo")),
"Foo" -> FieldSet("bar" -> Field.output.to("Bar").asList.resolveWith(List(100, 200, 300))),
"Bar" -> FieldSet("baz" -> Field.output.to("Baz").asList.resolveWithFunction {
"Bar" -> FieldSet("baz" -> Field.output.to("Baz").resolveWithFunction {
_.toTypedPath[Int]("value").map(_ + Remote(1)).toDynamic
}),
"Baz" -> FieldSet("value" -> Field.output.to("Int").resolveWithFunction {
Expand All @@ -100,7 +99,7 @@ object StepGeneratorSpec extends ZIOSpecDefault {

val program = execute(orc)("query {foo { bar { baz {value} }}}")
assertZIO(program)(equalTo(
"""{"foo":{"bar":[{"baz":[{"value":102}]},{"baz":[{"value":202}]},{"baz":[{"value":302}]}]}}"""
"""{"foo":{"bar":[{"baz":{"value":102}},{"baz":{"value":202}},{"baz":{"value":302}}]}}"""
))
},
test("parent") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ object TestGen {

def genVersion: Gen[Any, Int] = Gen.int(0, 10)

def genScalar: Gen[Any, TSchema] = Gen.fromIterable(List(TSchema.string, TSchema.int, TSchema.bool))
def genScalar: Gen[Any, TSchema] = Gen.fromIterable(List(TSchema.string, TSchema.num, TSchema.bool))

def genField: Gen[Any, (String, TSchema)] =
for {
Expand Down

0 comments on commit 234c870

Please sign in to comment.