From d650586a7ae389cbfbbabe96ecf38e12e056afa7 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Sun, 5 Nov 2023 13:30:25 +0900 Subject: [PATCH] =?UTF-8?q?test:=20inbox=E3=81=AE=E3=82=B3=E3=83=B3?= =?UTF-8?q?=E3=83=88=E3=83=AD=E3=83=BC=E3=83=A9=E3=83=BC=E3=81=AE=E3=83=86?= =?UTF-8?q?=E3=82=B9=E3=83=88=E3=81=ABuser-inbox=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 --- .../api/inbox/InboxControllerImplTest.kt | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/src/test/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/inbox/InboxControllerImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/inbox/InboxControllerImplTest.kt index 5bc960fa..f2dc7d53 100644 --- a/src/test/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/inbox/InboxControllerImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/inbox/InboxControllerImplTest.kt @@ -107,4 +107,73 @@ class InboxControllerImplTest { fun `inbox GETリクエストには504を返す`() { mockMvc.get("/inbox").andExpect { status { isMethodNotAllowed() } } } + + @Test + fun `user-inbox 正常なPOSTリクエストをしたときAcceptが返ってくる`() = runTest { + + + val json = """{"type":"Follow"}""" + whenever(apService.parseActivity(eq(json))).doReturn(ActivityType.Follow) + whenever(apService.processActivity(eq(json), eq(ActivityType.Follow))).doReturn( + ActivityPubStringResponse( + HttpStatusCode.Accepted, "" + ) + ) + + mockMvc + .post("/users/hoge/inbox") { + content = json + contentType = MediaType.APPLICATION_JSON + } + .asyncDispatch() + .andExpect { + status { isAccepted() } + } + + } + + @Test + fun `user-inbox parseActivityに失敗したときAcceptが返ってくる`() = runTest { + val json = """{"type":"Hoge"}""" + whenever(apService.parseActivity(eq(json))).doThrow(JsonParseException::class) + + mockMvc + .post("/users/hoge/inbox") { + content = json + contentType = MediaType.APPLICATION_JSON + } + .asyncDispatch() + .andExpect { + status { isAccepted() } + } + + } + + @Test + fun `user-inbox processActivityに失敗したときAcceptが返ってくる`() = runTest { + val json = """{"type":"Follow"}""" + whenever(apService.parseActivity(eq(json))).doReturn(ActivityType.Follow) + whenever( + apService.processActivity( + eq(json), + eq(ActivityType.Follow) + ) + ).doThrow(FailedToGetResourcesException::class) + + mockMvc + .post("/users/hoge/inbox") { + content = json + contentType = MediaType.APPLICATION_JSON + } + .asyncDispatch() + .andExpect { + status { isAccepted() } + } + + } + + @Test + fun `user-inbox GETリクエストには504を返す`() { + mockMvc.get("/users/hoge/inbox").andExpect { status { isMethodNotAllowed() } } + } }