test: inboxのコントローラーのテストにuser-inboxのテストを追加

This commit is contained in:
usbharu 2023-11-05 13:30:25 +09:00
parent a2420622c5
commit d650586a7a
1 changed files with 69 additions and 0 deletions

View File

@ -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() } }
}
}