Skip to content

Commit

Permalink
Added missing tests for pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
MateuszKubuszok committed Jul 21, 2019
1 parent d251979 commit eacc7f7
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions modules/core/src/test/scala/io/scalaland/ocdquery/RepoSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.scalaland.ocdquery
import java.time.LocalDate

import cats.Id
import cats.implicits._
import doobie._
import doobie.implicits._
import io.scalaland.ocdquery.example.{ TicketF, TicketRepo }
Expand Down Expand Up @@ -97,5 +98,43 @@ final class RepoSpec extends Specification with WithH2Database {

test.transact(transactor).unsafeRunSync() === None
}

"generate valid pagination" in {
val now = LocalDate.now()

val names = List("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k")

val toCreate = names.map { name =>
TicketF[Id, UnitF](
id = (),
name = name,
surname = "Test",
from = "Test",
to = "Test",
date = now
)
}

val filter = TicketF[Selectable, Selectable](
id = Skipped,
name = Skipped,
surname = Fixed("Test"),
from = Fixed("Test"),
to = Fixed("Test"),
date = Skipped
)

val test = for {
inserted <- toCreate.traverse(TicketRepo.insert(_).run).map(_.sum)
_ = inserted === toCreate.length
all <- TicketRepo.fetch(filter).to[List]
_ = all.map(_.name).toSet === names.toSet
firstHalf <- TicketRepo.fetch(filter, Some("name" -> Repo.Sort.Ascending), None, Some(5)).to[List]
_ = firstHalf.map(_.name) === names.take(5)
secondHalf <- TicketRepo.fetch(filter, Some("name" -> Repo.Sort.Ascending), Some(5), None).to[List]
} yield secondHalf.map(_.name)

test.transact(transactor).unsafeRunSync() === names.drop(5)
}
}
}

0 comments on commit eacc7f7

Please sign in to comment.