Merge pull request #242 from usbharu/bugfix/deliver-local-post-delete

Bugfix/deliver local post delete
This commit is contained in:
usbharu 2024-01-16 16:21:16 +09:00 committed by GitHub
commit a4865be4a7
2 changed files with 37 additions and 1 deletions

View File

@ -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.core.domain.exception.UserNotFoundException
import dev.usbharu.hideout.core.domain.exception.resource.DuplicateException
import dev.usbharu.hideout.core.domain.exception.resource.PostNotFoundException
@ -21,7 +22,8 @@ class PostServiceImpl(
private val timelineService: TimelineService,
private val postBuilder: Post.PostBuilder,
private val apSendCreateService: ApSendCreateService,
private val reactionRepository: ReactionRepository
private val reactionRepository: ReactionRepository,
private val apSendDeleteService: APSendDeleteService
) : PostService {
override suspend fun createLocal(post: PostCreateDto): Post {
@ -50,6 +52,8 @@ class PostServiceImpl(
val actor = actorRepository.findById(post.actorId)
?: throw IllegalStateException("actor: ${post.actorId} was not found.")
apSendDeleteService.sendDeleteNote(post)
actorRepository.save(actor.decrementPostsCount())
}

View File

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