test: ページネーション系のテストを追加

This commit is contained in:
usbharu 2024-01-30 14:12:46 +09:00
parent 71a14c65c8
commit 063692832d
2 changed files with 75 additions and 0 deletions

View File

@ -0,0 +1,27 @@
package dev.usbharu.hideout.application.infrastructure.exposed
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
class PageTest {
@Test
fun minIdが指定されているとsinceIdは無視される() {
val page = Page.of(1, 2, 3, 4)
assertThat(page.maxId).isEqualTo(1)
assertThat(page.sinceId).isNull()
assertThat(page.minId).isEqualTo(3)
assertThat(page.limit).isEqualTo(4)
}
@Test
fun minIdがnullのときはsinceIdが使われる() {
val page = Page.of(1, 2, null, 4)
assertThat(page.maxId).isEqualTo(1)
assertThat(page.minId).isNull()
assertThat(page.sinceId).isEqualTo(2)
assertThat(page.limit).isEqualTo(4)
}
}

View File

@ -0,0 +1,48 @@
package dev.usbharu.hideout.application.infrastructure.exposed
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
class PaginationListKtTest {
@Test
fun `toHttpHeader nextとprevがnullでない場合両方作成される`() {
val paginationList = PaginationList<String, Long>(emptyList(), 1, 2)
val httpHeader =
paginationList.toHttpHeader({ "https://example.com?max_id=$it" }, { "https://example.com?min_id=$it" })
assertThat(httpHeader).isEqualTo("<https://example.com?max_id=1>; rel=\"next\", <https://example.com?min_id=2>; rel=\"prev\"")
}
@Test
fun `toHttpHeader nextがnullなら片方だけ作成される`() {
val paginationList = PaginationList<String, Long>(emptyList(), 1,null)
val httpHeader =
paginationList.toHttpHeader({ "https://example.com?max_id=$it" }, { "https://example.com?min_id=$it" })
assertThat(httpHeader).isEqualTo("<https://example.com?max_id=1>; rel=\"next\"")
}
@Test
fun `toHttpHeader prevがnullなら片方だけ作成される`() {
val paginationList = PaginationList<String, Long>(emptyList(), null,2)
val httpHeader =
paginationList.toHttpHeader({ "https://example.com?max_id=$it" }, { "https://example.com?min_id=$it" })
assertThat(httpHeader).isEqualTo("<https://example.com?min_id=2>; rel=\"prev\"")
}
@Test
fun `toHttpHeader 両方nullならnullが返ってくる`() {
val paginationList = PaginationList<String, Long>(emptyList(), null, null)
val httpHeader =
paginationList.toHttpHeader({ "https://example.com?max_id=$it" }, { "https://example.com?min_id=$it" })
assertThat(httpHeader).isNull()
}
}