test: テストを修正

This commit is contained in:
usbharu 2023-12-13 17:02:00 +09:00
parent 9f05e296a6
commit 0f51ea7a17
2 changed files with 42 additions and 8 deletions

View File

@ -5,6 +5,7 @@ import dev.usbharu.hideout.application.config.CharacterLimit
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.post.Post import dev.usbharu.hideout.core.domain.model.post.Post
import dev.usbharu.hideout.core.domain.model.post.PostRepository import dev.usbharu.hideout.core.domain.model.post.PostRepository
import dev.usbharu.hideout.core.domain.model.reaction.ReactionRepository
import dev.usbharu.hideout.core.query.PostQueryService import dev.usbharu.hideout.core.query.PostQueryService
import dev.usbharu.hideout.core.service.timeline.TimelineService import dev.usbharu.hideout.core.service.timeline.TimelineService
import kotlinx.coroutines.test.runTest import kotlinx.coroutines.test.runTest
@ -45,6 +46,9 @@ class PostServiceImplTest {
@Mock @Mock
private lateinit var apSendCreateService: ApSendCreateService private lateinit var apSendCreateService: ApSendCreateService
@Mock
private lateinit var reactionRepository: ReactionRepository
@InjectMocks @InjectMocks
private lateinit var postServiceImpl: PostServiceImpl private lateinit var postServiceImpl: PostServiceImpl

View File

@ -4,9 +4,11 @@ package dev.usbharu.hideout.core.service.user
import dev.usbharu.hideout.application.config.ApplicationConfig import dev.usbharu.hideout.application.config.ApplicationConfig
import dev.usbharu.hideout.application.config.CharacterLimit import dev.usbharu.hideout.application.config.CharacterLimit
import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException
import dev.usbharu.hideout.core.domain.model.actor.Actor import dev.usbharu.hideout.core.domain.model.actor.Actor
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
import dev.usbharu.hideout.core.domain.model.post.Post import dev.usbharu.hideout.core.domain.model.post.Post
import dev.usbharu.hideout.core.query.DeletedActorQueryService
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.test.runTest import kotlinx.coroutines.test.runTest
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
@ -34,13 +36,19 @@ class ActorServiceTest {
} }
val userService = val userService =
UserServiceImpl( UserServiceImpl(
actorRepository, actorRepository = actorRepository,
userAuthService, userAuthService = userAuthService,
mock(), actorQueryService = mock(),
actorBuilder, actorBuilder = actorBuilder,
testApplicationConfig, applicationConfig = testApplicationConfig,
mock(), instanceService = mock(),
mock() userDetailRepository = mock(),
deletedActorRepository = mock(),
deletedActorQueryService = mock(),
reactionRepository = mock(),
relationshipRepository = mock(),
postService = mock(),
apSendDeleteService = mock()
) )
userService.createLocalUser(UserCreateDto("test", "testUser", "XXXXXXXXXXXXX", "test")) userService.createLocalUser(UserCreateDto("test", "testUser", "XXXXXXXXXXXXX", "test"))
verify(actorRepository, times(1)).save(any()) verify(actorRepository, times(1)).save(any())
@ -65,8 +73,30 @@ class ActorServiceTest {
val actorRepository = mock<ActorRepository> { val actorRepository = mock<ActorRepository> {
onBlocking { nextId() } doReturn 113345L onBlocking { nextId() } doReturn 113345L
} }
val deletedActorQueryService = mock<DeletedActorQueryService> {
onBlocking {
findByNameAndDomain(
eq("test"),
eq("remote.example.com")
)
} doAnswer { throw FailedToGetResourcesException() }
}
val userService = val userService =
UserServiceImpl(actorRepository, mock(), mock(), actorBuilder, testApplicationConfig, mock(), mock()) UserServiceImpl(
actorRepository = actorRepository,
userAuthService = mock(),
actorQueryService = mock(),
actorBuilder = actorBuilder,
applicationConfig = testApplicationConfig,
instanceService = mock(),
userDetailRepository = mock(),
deletedActorRepository = mock(),
deletedActorQueryService = deletedActorQueryService,
reactionRepository = mock(),
relationshipRepository = mock(),
postService = mock(),
apSendDeleteService = mock()
)
val user = RemoteUserCreateDto( val user = RemoteUserCreateDto(
name = "test", name = "test",
domain = "remote.example.com", domain = "remote.example.com",