Skip to content

Commit

Permalink
[KAIZEN] Harden test suite for optional params (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kasper Kondzielski committed Mar 21, 2023
1 parent f686e25 commit 77ac0c9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
23 changes: 13 additions & 10 deletions server/test/src/io/iohk/armadillo/server/AbstractServerSuite.scala
Expand Up @@ -118,16 +118,6 @@ trait AbstractServerSuite[Raw, Body, Interpreter] extends AbstractBaseSuite[Raw,
expectedResponse = JsonRpcResponse.error_v2[Raw](json"""{"code": -32602, "message": "Invalid params"}""", 1)
)

test(echo_with_optional_param, "omitting optional param") { p => IO.pure(Right(p._1.map(_ + p._2).getOrElse(p._2))) }(
request = JsonRpcRequest.v2[Raw]("echo", json"""{"second": "Test!"}""", 1),
expectedResponse = JsonRpcResponse.v2[Raw](json""""Test!"""", 1)
)

test(echo_with_optional_param, "combining optional and required params") { p => IO.pure(Right(p._1.map(_ + p._2).getOrElse(p._2))) }(
request = JsonRpcRequest.v2[Raw]("echo", json"""{"first": "Test!", "second": "Test!"}""", 1),
expectedResponse = JsonRpcResponse.v2[Raw](json""""Test!Test!"""", 1)
)

test(empty, "empty response")(_ => IO.delay(Right(println("hello from server"))))(
request = JsonRpcRequest.v2[Raw]("empty", json"""[]""", 1),
expectedResponse = JsonRpcResponse.v2[Raw](Json.Null, 1)
Expand Down Expand Up @@ -375,6 +365,19 @@ trait AbstractServerSuite[Raw, Body, Interpreter] extends AbstractBaseSuite[Raw,
expectedResponse = JsonRpcResponse.v2[Raw](Json.Null, 1)
)

test(echo_with_optional_params, "omitting multiple optinal params") { p =>
IO.pure(Right(p._1.getOrElse("") ++ p._2.getOrElse("") ++ p._3))
}(
request = JsonRpcRequest.v2[Raw]("echo", json"""{"third": "Test!"}""", 1),
expectedResponse = JsonRpcResponse.v2[Raw](json""""Test!"""", 1)
)

test(echo_with_optional_params, "combining optional and required params and omitting one optinal param") { p =>
IO.pure(Right(p._1.getOrElse("") ++ p._2.getOrElse("") ++ p._3))
}(
request = JsonRpcRequest.v2[Raw]("echo", json"""{"first": "Test!", "third": "Test!"}""", 1),
expectedResponse = JsonRpcResponse.v2[Raw](json""""Test!Test!"""", 1)
)
test(output_without_params, "should return response when no params attribute is missing")(_ => IO.pure(Right("params is not required")))(
request = JsonRpcRequest.v2[Raw]("output_without_params", 1),
expectedResponse = JsonRpcResponse.v2[Raw](Json.fromString("params is not required"), 1)
Expand Down
4 changes: 2 additions & 2 deletions server/test/src/io/iohk/armadillo/server/Endpoints.scala
Expand Up @@ -102,8 +102,8 @@ trait Endpoints {
.out[String]("response")
}

val echo_with_optional_param: JsonRpcEndpoint[(Option[String], String), Unit, String] = jsonRpcEndpoint(m"echo")
.in(param[Option[String]]("first").and(param[String]("second")))
val echo_with_optional_params: JsonRpcEndpoint[(Option[String], Option[String], String), Unit, String] = jsonRpcEndpoint(m"echo")
.in(param[Option[String]]("first").and(param[Option[String]]("second")).and(param[String]("third")))
.out[String]("echoed")

val empty: JsonRpcEndpoint[Unit, Unit, Unit] = jsonRpcEndpoint(m"empty")
Expand Down

0 comments on commit 77ac0c9

Please sign in to comment.