From 55dfee4187431bb5acb0b898ffb60111a47d9705 Mon Sep 17 00:00:00 2001 From: Kseniya Tomskikh Date: Tue, 6 Mar 2018 14:28:54 +0700 Subject: Created directive for optional pagination --- src/test/scala/xyz/driver/core/rest/RestTest.scala | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src/test/scala/xyz/driver/core/rest/RestTest.scala') diff --git a/src/test/scala/xyz/driver/core/rest/RestTest.scala b/src/test/scala/xyz/driver/core/rest/RestTest.scala index d36e04d..80e4fd5 100644 --- a/src/test/scala/xyz/driver/core/rest/RestTest.scala +++ b/src/test/scala/xyz/driver/core/rest/RestTest.scala @@ -47,4 +47,27 @@ class RestTest extends WordSpec with Matchers with ScalatestRouteTest with Direc } } } + + "optional paginated directive" should { + val route: Route = rest.optionalPaginated { paginated => + complete(StatusCodes.OK -> paginated.map(p => s"${p.pageNumber},${p.pageSize}").getOrElse("no pagination")) + } + "accept a pagination" in { + Get("/?pageNumber=2&pageSize=42") ~> route ~> check { + assert(status == StatusCodes.OK) + assert(entityAs[String] == "2,42") + } + } + "without pagination" in { + Get("/") ~> route ~> check { + assert(status == StatusCodes.OK) + assert(entityAs[String] == "no pagination") + } + } + "reject an invalid pagination" in { + Get("/?pageNumber=1") ~> route ~> check { + assert(rejection.isInstanceOf[ValidationRejection]) + } + } + } } -- cgit v1.2.3