diff options
author | kseniya <ktomskih@datamonsters.co> | 2017-09-20 18:01:15 +0700 |
---|---|---|
committer | kseniya <ktomskih@datamonsters.co> | 2017-09-20 18:01:15 +0700 |
commit | 9968eaefa2a97ebe495fa51b640e31c78db61ac6 (patch) | |
tree | 4eed12a4ebb2829e336a3da673c7c8462e7ab845 /src/test/scala/xyz/driver/pdsuicommon/parsers/PaginationParserSuite.scala | |
parent | d5ecec043a3d70dd09bda8a79fcd188f411b47df (diff) | |
parent | d4b18efda238f506103dddbf3b400ae17c797276 (diff) | |
download | rest-query-9968eaefa2a97ebe495fa51b640e31c78db61ac6.tar.gz rest-query-9968eaefa2a97ebe495fa51b640e31c78db61ac6.tar.bz2 rest-query-9968eaefa2a97ebe495fa51b640e31c78db61ac6.zip |
Merge branch 'master' into slick-query-builder
Diffstat (limited to 'src/test/scala/xyz/driver/pdsuicommon/parsers/PaginationParserSuite.scala')
-rw-r--r-- | src/test/scala/xyz/driver/pdsuicommon/parsers/PaginationParserSuite.scala | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/src/test/scala/xyz/driver/pdsuicommon/parsers/PaginationParserSuite.scala b/src/test/scala/xyz/driver/pdsuicommon/parsers/PaginationParserSuite.scala new file mode 100644 index 0000000..48fc99b --- /dev/null +++ b/src/test/scala/xyz/driver/pdsuicommon/parsers/PaginationParserSuite.scala @@ -0,0 +1,95 @@ +package xyz.driver.pdsuicommon.parsers + +import xyz.driver.pdsuicommon.db.Pagination +import xyz.driver.pdsuicommon.parsers.TestUtils._ +import org.scalatest.{FreeSpecLike, MustMatchers} + +import scala.util.{Failure, Try} + +class PaginationParserSuite extends FreeSpecLike with MustMatchers { + + "parse" - { + "pageSize" - { + "should parse positive value" in { + val pagination = PaginationParser.parse(Seq( + "pageSize" -> "10", + "pageNumber" -> "1" + )) + pagination must success + pagination.get.pageSize mustBe 10 + } + + "should return a default value if there is no one" in { + val pagination = PaginationParser.parse(Seq( + "pageNumber" -> "1" + )) + pagination must success + pagination.get.pageSize mustBe 100 + } + + "should return a error for zero value" in { + val pagination = PaginationParser.parse(Seq( + "pageSize" -> "0", + "pageNumber" -> "1" + )) + + checkFailedValidationOnlyOn(pagination, "pageSize") + } + + "should return a error for negative value" in { + val pagination = PaginationParser.parse(Seq( + "pageSize" -> "-10", + "pageNumber" -> "1" + )) + + checkFailedValidationOnlyOn(pagination, "pageSize") + } + } + + "pageNumber" - { + "should parse positive value" in { + val pagination = PaginationParser.parse(Seq( + "pageSize" -> "1", + "pageNumber" -> "1" + )) + pagination must success + pagination.get.pageSize mustBe 1 + } + + "should return a default value if there is no one" in { + val pagination = PaginationParser.parse(Seq( + "pageSize" -> "1" + )) + pagination must success + pagination.get.pageNumber mustBe 1 + } + + "should return a error for zero value" in { + val pagination = PaginationParser.parse(Seq( + "pageSize" -> "1", + "pageNumber" -> "0" + )) + + checkFailedValidationOnlyOn(pagination, "pageNumber") + } + + "should return a error for negative value" in { + val pagination = PaginationParser.parse(Seq( + "pageSize" -> "1", + "pageNumber" -> "-1" + )) + + checkFailedValidationOnlyOn(pagination, "pageNumber") + } + } + } + + private def checkFailedValidationOnlyOn(pagination: Try[Pagination], key: String): Unit = { + pagination must failWith[ParseQueryArgException] + + val Failure(e: ParseQueryArgException) = pagination + e.errors.size mustBe 1 + e.errors.head._1 mustBe key + } + +} |