From 75a66ee2d3ee8799aead6967de5d0c1aecea0b69 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Wed, 31 Jan 2024 14:40:11 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=E9=80=9A=E7=9F=A5API=E3=81=A8=E3=83=9A?= =?UTF-8?q?=E3=83=BC=E3=82=B8=E3=83=8D=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3?= =?UTF-8?q?=E3=81=AE=E3=83=AC=E3=82=B9=E3=83=9D=E3=83=B3=E3=82=B9=E3=83=81?= =?UTF-8?q?=E3=82=A7=E3=83=83=E3=82=AF=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notifications/NotificationsTest.kt | 56 ++++++++++++++++++- 1 file changed, 53 insertions(+), 3 deletions(-) diff --git a/src/intTest/kotlin/mastodon/notifications/NotificationsTest.kt b/src/intTest/kotlin/mastodon/notifications/NotificationsTest.kt index 4dbabab7..282a9605 100644 --- a/src/intTest/kotlin/mastodon/notifications/NotificationsTest.kt +++ b/src/intTest/kotlin/mastodon/notifications/NotificationsTest.kt @@ -1,7 +1,11 @@ package mastodon.notifications +import com.fasterxml.jackson.core.type.TypeReference +import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import dev.usbharu.hideout.SpringApplication +import dev.usbharu.hideout.domain.mastodon.model.generated.Notification import kotlinx.coroutines.test.runTest +import org.assertj.core.api.Assertions.assertThat import org.flywaydb.core.Flyway import org.junit.jupiter.api.AfterAll import org.junit.jupiter.api.BeforeEach @@ -34,7 +38,7 @@ class NotificationsTest { @Test fun `通知を取得できる`() = runTest { - mockMvc + val content = mockMvc .get("/api/v1/notifications") { with( SecurityMockMvcRequestPostProcessors.jwt() @@ -50,12 +54,19 @@ class NotificationsTest { ) } } + .andReturn() + .response + .contentAsString + val value = jacksonObjectMapper().readValue(content, object : TypeReference>() {}) + + assertThat(value.first().id).isEqualTo("65") + assertThat(value.last().id).isEqualTo("26") } @Test fun maxIdを指定して通知を取得できる() = runTest { - mockMvc + val content = mockMvc .get("/api/v1/notifications?max_id=26") { with( SecurityMockMvcRequestPostProcessors.jwt() @@ -71,12 +82,20 @@ class NotificationsTest { ) } } + .andReturn() + .response + .contentAsString + + val value = jacksonObjectMapper().readValue(content, object : TypeReference>() {}) + + assertThat(value.first().id).isEqualTo("25") + assertThat(value.last().id).isEqualTo("1") } @Test fun minIdを指定して通知を取得できる() = runTest { - mockMvc + val content = mockMvc .get("/api/v1/notifications?min_id=25") { with( SecurityMockMvcRequestPostProcessors.jwt() @@ -92,7 +111,38 @@ class NotificationsTest { ) } } + .andReturn() + .response + .contentAsString + val value = jacksonObjectMapper().readValue(content, object : TypeReference>() {}) + + assertThat(value.first().id).isEqualTo("65") + assertThat(value.last().id).isEqualTo("26") + } + + @Test + fun 結果が0件のときはページネーションのヘッダーがない() = runTest { + val content = mockMvc + .get("/api/v1/notifications?max_id=1") { + with( + SecurityMockMvcRequestPostProcessors.jwt() + .jwt { it.claim("uid", "1") }.authorities(SimpleGrantedAuthority("SCOPE_read")) + ) + } + .asyncDispatch() + .andExpect { + header { + doesNotExist("Link") + } + } + .andReturn() + .response + .contentAsString + + val value = jacksonObjectMapper().readValue(content, object : TypeReference>() {}) + + assertThat(value).size().isZero() } @BeforeEach