diff options
author | Kseniya Tomskikh <ktomskih@datamonsters.co> | 2018-03-07 11:38:51 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-03-07 11:38:51 +0700 |
commit | fccdf351f8530bb30f7ec9ca61273f0be4c80221 (patch) | |
tree | c7038d501e37f37d6082f2c9495592b7c8085d6a /src/test/scala/xyz/driver | |
parent | 575872b556eeb403147df9fe96b58236e0402050 (diff) | |
parent | cfea2749380d367f4a525c90792b66241df42273 (diff) | |
download | driver-core-fccdf351f8530bb30f7ec9ca61273f0be4c80221.tar.gz driver-core-fccdf351f8530bb30f7ec9ca61273f0be4c80221.tar.bz2 driver-core-fccdf351f8530bb30f7ec9ca61273f0be4c80221.zip |
Merge pull request #134 from drivergroup/opt-paginationv1.8.8
Created directive for optional pagination
Diffstat (limited to 'src/test/scala/xyz/driver')
-rw-r--r-- | src/test/scala/xyz/driver/core/rest/RestTest.scala | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/test/scala/xyz/driver/core/rest/RestTest.scala b/src/test/scala/xyz/driver/core/rest/RestTest.scala index d36e04d..68fe419 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.optionalPagination { 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]) + } + } + } } |