test: sharedInboxにPOSTしたときのテストを追加

This commit is contained in:
usbharu 2023-04-10 14:48:33 +09:00
parent c5566253fa
commit 47b6683ca0
Signed by: usbharu
GPG Key ID: 6556747BF94EEBC8
1 changed files with 29 additions and 0 deletions

View File

@ -7,13 +7,21 @@ import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
import dev.usbharu.hideout.plugins.configureRouting import dev.usbharu.hideout.plugins.configureRouting
import dev.usbharu.hideout.plugins.configureSerialization import dev.usbharu.hideout.plugins.configureSerialization
import dev.usbharu.hideout.plugins.configureStatusPages
import dev.usbharu.hideout.service.activitypub.ActivityPubService
import dev.usbharu.hideout.service.activitypub.ActivityPubUserService
import dev.usbharu.hideout.service.impl.UserService
import dev.usbharu.hideout.service.signature.HttpSignatureVerifyService
import io.ktor.client.request.* import io.ktor.client.request.*
import io.ktor.client.statement.* import io.ktor.client.statement.*
import io.ktor.http.* import io.ktor.http.*
import io.ktor.server.config.* import io.ktor.server.config.*
import io.ktor.server.testing.* import io.ktor.server.testing.*
import junit.framework.TestCase.assertEquals
import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.mockito.kotlin.any
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock import org.mockito.kotlin.mock
class InboxRoutingKtTest { class InboxRoutingKtTest {
@ -30,4 +38,25 @@ class InboxRoutingKtTest {
Assertions.assertEquals(HttpStatusCode.MethodNotAllowed, it.status) Assertions.assertEquals(HttpStatusCode.MethodNotAllowed, it.status)
} }
} }
@Test
fun `sharedInboxに空のリクエストボディでPOSTしたら400が帰ってくる`() = testApplication {
environment {
config = ApplicationConfig("empty.conf")
}
val httpSignatureVerifyService = mock<HttpSignatureVerifyService>{
on { verify(any()) } doReturn true
}
val activityPubService = mock<ActivityPubService>()
val userService = mock<UserService>()
val activityPubUserService = mock<ActivityPubUserService>()
application {
configureStatusPages()
configureSerialization()
configureRouting(httpSignatureVerifyService, activityPubService, userService, activityPubUserService)
}
client.post("/inbox").let {
Assertions.assertEquals(HttpStatusCode.BadRequest, it.status)
}
}
} }