From 9a8fd22b92afba51d08518f62e971fcfdd743a68 Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Tue, 16 Jan 2024 15:14:47 +0900 Subject: [PATCH] =?UTF-8?q?test:=20=E3=83=AD=E3=83=BC=E3=82=AB=E3=83=AB?= =?UTF-8?q?=E6=8A=95=E7=A8=BF=E5=89=8A=E9=99=A4=E3=81=AE=E9=85=8D=E9=80=81?= =?UTF-8?q?=E3=83=86=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 --- .../core/service/post/PostServiceImplTest.kt | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/test/kotlin/dev/usbharu/hideout/core/service/post/PostServiceImplTest.kt b/src/test/kotlin/dev/usbharu/hideout/core/service/post/PostServiceImplTest.kt index 5a76ea07..733e8f93 100644 --- a/src/test/kotlin/dev/usbharu/hideout/core/service/post/PostServiceImplTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/core/service/post/PostServiceImplTest.kt @@ -1,6 +1,7 @@ package dev.usbharu.hideout.core.service.post import dev.usbharu.hideout.activitypub.service.activity.create.ApSendCreateService +import dev.usbharu.hideout.activitypub.service.activity.delete.APSendDeleteService import dev.usbharu.hideout.application.config.CharacterLimit import dev.usbharu.hideout.core.domain.exception.resource.DuplicateException import dev.usbharu.hideout.core.domain.model.actor.ActorRepository @@ -43,6 +44,9 @@ class PostServiceImplTest { @Mock private lateinit var reactionRepository: ReactionRepository + @Mock + private lateinit var apSendDeleteService: APSendDeleteService + @InjectMocks private lateinit var postServiceImpl: PostServiceImpl @@ -130,4 +134,32 @@ class PostServiceImplTest { verify(postRepository, times(1)).save(eq(post)) verify(timelineService, times(1)).publishTimeline(eq(post), eq(false)) } + + @Test + fun `deleteLocal Deleteが配送される`() = runTest { + val post = PostBuilder.of() + + val localUserOf = UserBuilder.localUserOf() + + whenever(actorRepository.findById(eq(post.actorId))).doReturn(localUserOf) + + postServiceImpl.deleteLocal(post) + + verify(reactionRepository, times(1)).deleteByPostId(eq(post.id)) + verify(postRepository, times(1)).save(eq(post.delete())) + verify(apSendDeleteService, times(1)).sendDeleteNote(eq(post)) + verify(actorRepository, times(1)).save(eq(localUserOf.decrementPostsCount())) + } + + @Test + fun `deleteLocal 削除済み投稿は何もしない`() = runTest { + val delete = PostBuilder.of().delete() + + postServiceImpl.deleteLocal(delete) + + verify(reactionRepository, never()).deleteByPostId(any()) + verify(postRepository, never()).save(any()) + verify(apSendDeleteService, never()).sendDeleteNote(any()) + verify(actorRepository, never()).save(any()) + } }