diff --git a/src/test/kotlin/dev/usbharu/hideout/application/infrastructure/exposed/PageTest.kt b/src/test/kotlin/dev/usbharu/hideout/application/infrastructure/exposed/PageTest.kt new file mode 100644 index 00000000..30f88c2c --- /dev/null +++ b/src/test/kotlin/dev/usbharu/hideout/application/infrastructure/exposed/PageTest.kt @@ -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) + } +} \ No newline at end of file diff --git a/src/test/kotlin/dev/usbharu/hideout/application/infrastructure/exposed/PaginationListKtTest.kt b/src/test/kotlin/dev/usbharu/hideout/application/infrastructure/exposed/PaginationListKtTest.kt new file mode 100644 index 00000000..a7f21eba --- /dev/null +++ b/src/test/kotlin/dev/usbharu/hideout/application/infrastructure/exposed/PaginationListKtTest.kt @@ -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(emptyList(), 1, 2) + + val httpHeader = + paginationList.toHttpHeader({ "https://example.com?max_id=$it" }, { "https://example.com?min_id=$it" }) + + assertThat(httpHeader).isEqualTo("; rel=\"next\", ; rel=\"prev\"") + } + + @Test + fun `toHttpHeader nextがnullなら片方だけ作成される`() { + val paginationList = PaginationList(emptyList(), 1,null) + + val httpHeader = + paginationList.toHttpHeader({ "https://example.com?max_id=$it" }, { "https://example.com?min_id=$it" }) + + assertThat(httpHeader).isEqualTo("; rel=\"next\"") + } + + @Test + fun `toHttpHeader prevがnullなら片方だけ作成される`() { + val paginationList = PaginationList(emptyList(), null,2) + + val httpHeader = + paginationList.toHttpHeader({ "https://example.com?max_id=$it" }, { "https://example.com?min_id=$it" }) + + assertThat(httpHeader).isEqualTo("; rel=\"prev\"") + } + + @Test + fun `toHttpHeader 両方nullならnullが返ってくる`() { + val paginationList = PaginationList(emptyList(), null, null) + + + val httpHeader = + paginationList.toHttpHeader({ "https://example.com?max_id=$it" }, { "https://example.com?min_id=$it" }) + + assertThat(httpHeader).isNull() + } +} \ No newline at end of file