From 1089f63e36832ab3cae77a9eb699264f0defd76d Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Thu, 9 Nov 2023 15:32:35 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=E3=83=86=E3=82=B9=E3=83=88=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/outbox/OutboxControllerImplTest.kt | 4 ++++ .../reaction/ReactionServiceImplTest.kt | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/test/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/outbox/OutboxControllerImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/outbox/OutboxControllerImplTest.kt index bd333912..c22ddb3f 100644 --- a/src/test/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/outbox/OutboxControllerImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/activitypub/interfaces/api/outbox/OutboxControllerImplTest.kt @@ -28,6 +28,7 @@ class OutboxControllerImplTest { fun `outbox GETに501を返す`() { mockMvc .get("/outbox") + .asyncDispatch() .andDo { print() } .andExpect { status { isNotImplemented() } } } @@ -36,6 +37,7 @@ class OutboxControllerImplTest { fun `user-outbox GETに501を返す`() { mockMvc .get("/users/hoge/outbox") + .asyncDispatch() .andDo { print() } .andExpect { status { isNotImplemented() } } } @@ -44,6 +46,7 @@ class OutboxControllerImplTest { fun `outbox POSTに501を返す`() { mockMvc .post("/outbox") + .asyncDispatch() .andDo { print() } .andExpect { status { isNotImplemented() } } } @@ -52,6 +55,7 @@ class OutboxControllerImplTest { fun `user-outbox POSTに501を返す`() { mockMvc .post("/users/hoge/outbox") + .asyncDispatch() .andDo { print() } .andExpect { status { isNotImplemented() } } } diff --git a/src/test/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImplTest.kt index 8e39a439..e3cf0ddd 100644 --- a/src/test/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/core/service/reaction/ReactionServiceImplTest.kt @@ -3,6 +3,7 @@ package dev.usbharu.hideout.core.service.reaction import dev.usbharu.hideout.activitypub.service.activity.like.APReactionService import dev.usbharu.hideout.application.service.id.TwitterSnowflakeIdGenerateService +import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException import dev.usbharu.hideout.core.domain.model.reaction.Reaction import dev.usbharu.hideout.core.domain.model.reaction.ReactionRepository import dev.usbharu.hideout.core.query.ReactionQueryService @@ -88,7 +89,9 @@ class ReactionServiceImplTest { @Test fun `sendReaction リアクションが存在しないとき保存して配送する`() = runTest { val post = PostBuilder.of() - whenever(reactionQueryService.reactionAlreadyExist(eq(post.id), eq(post.userId), eq(0))).doReturn(false) + whenever(reactionQueryService.findByPostIdAndUserIdAndEmojiId(eq(post.id), eq(post.userId), eq(0))).doThrow( + FailedToGetResourcesException::class + ) val generateId = TwitterSnowflakeIdGenerateService.generateId() whenever(reactionRepository.generateId()).doReturn(generateId) @@ -101,23 +104,28 @@ class ReactionServiceImplTest { @Test fun `sendReaction リアクションが存在するときは削除して保存して配送する`() = runTest { val post = PostBuilder.of() - whenever(reactionQueryService.reactionAlreadyExist(eq(post.id), eq(post.userId), eq(0))).doReturn(true) + val id = TwitterSnowflakeIdGenerateService.generateId() + whenever(reactionQueryService.findByPostIdAndUserIdAndEmojiId(eq(post.id), eq(post.userId), eq(0))).doReturn( + Reaction(id, 0, post.id, post.userId) + ) val generateId = TwitterSnowflakeIdGenerateService.generateId() whenever(reactionRepository.generateId()).doReturn(generateId) reactionServiceImpl.sendReaction("❤", post.userId, post.id) - verify(reactionRepository, times(1)).delete(eq(Reaction(generateId, 0, post.id, post.userId))) + verify(reactionRepository, times(1)).delete(eq(Reaction(id, 0, post.id, post.userId))) verify(reactionRepository, times(1)).save(eq(Reaction(generateId, 0, post.id, post.userId))) - verify(apReactionService, times(1)).removeReaction(eq(Reaction(generateId, 0, post.id, post.userId))) + verify(apReactionService, times(1)).removeReaction(eq(Reaction(id, 0, post.id, post.userId))) verify(apReactionService, times(1)).reaction(eq(Reaction(generateId, 0, post.id, post.userId))) } @Test fun `removeReaction リアクションが存在する場合削除して配送`() = runTest { val post = PostBuilder.of() - whenever(reactionQueryService.reactionAlreadyExist(eq(post.id), eq(post.userId), eq(0))).doReturn(true) + whenever(reactionQueryService.findByPostIdAndUserIdAndEmojiId(eq(post.id), eq(post.userId), eq(0))).doReturn( + Reaction(0, 0, post.id, post.userId) + ) reactionServiceImpl.removeReaction(post.userId, post.id)