From 80bbe540607720eeab69bbab2a630fd608684b45 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Tue, 30 Jan 2024 14:12:46 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=E3=83=9A=E3=83=BC=E3=82=B8=E3=83=8D?= =?UTF-8?q?=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E7=B3=BB=E3=81=AE=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infrastructure/exposed/PageTest.kt | 27 +++++++++++ .../exposed/PaginationListKtTest.kt | 48 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 src/test/kotlin/dev/usbharu/hideout/application/infrastructure/exposed/PageTest.kt create mode 100644 src/test/kotlin/dev/usbharu/hideout/application/infrastructure/exposed/PaginationListKtTest.kt 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