mirror of https://github.com/usbharu/Hideout.git
test: テストを修正
This commit is contained in:
parent
e3a819f94d
commit
e7743c77f2
|
@ -37,13 +37,12 @@ class ReactionServiceImpl(
|
|||
val findByPostIdAndUserIdAndEmojiId =
|
||||
reactionRepository.findByPostIdAndActorIdAndEmojiId(postId, actorId, 0)
|
||||
|
||||
if (findByPostIdAndUserIdAndEmojiId == null) {
|
||||
LOGGER.warn("FAILED Send reaction. $postId $actorId")
|
||||
return
|
||||
if (findByPostIdAndUserIdAndEmojiId != null) {
|
||||
apReactionService.removeReaction(findByPostIdAndUserIdAndEmojiId)
|
||||
reactionRepository.delete(findByPostIdAndUserIdAndEmojiId)
|
||||
}
|
||||
|
||||
apReactionService.removeReaction(findByPostIdAndUserIdAndEmojiId)
|
||||
reactionRepository.delete(findByPostIdAndUserIdAndEmojiId)
|
||||
|
||||
val reaction = Reaction(reactionRepository.generateId(), 0, postId, actorId)
|
||||
reactionRepository.save(reaction)
|
||||
apReactionService.reaction(reaction)
|
||||
|
|
|
@ -5,7 +5,7 @@ import dev.usbharu.hideout.activitypub.domain.model.Key
|
|||
import dev.usbharu.hideout.activitypub.domain.model.Person
|
||||
import dev.usbharu.hideout.activitypub.service.objects.user.APUserService
|
||||
import dev.usbharu.hideout.application.config.ActivityPubConfig
|
||||
import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException
|
||||
import dev.usbharu.hideout.core.domain.exception.resource.UserNotFoundException
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
|
@ -75,7 +75,7 @@ class ActorAPControllerImplTest {
|
|||
|
||||
@Test
|
||||
fun `userAP 存在しないユーザーにGETすると404が返ってくる`() = runTest {
|
||||
whenever(apUserService.getPersonByName(eq("fuga"))).doThrow(FailedToGetResourcesException::class)
|
||||
whenever(apUserService.getPersonByName(eq("fuga"))).doThrow(UserNotFoundException::class)
|
||||
|
||||
mockMvc
|
||||
.get("/users/fuga")
|
||||
|
|
|
@ -5,7 +5,7 @@ import com.fasterxml.jackson.module.kotlin.readValue
|
|||
import dev.usbharu.hideout.activitypub.domain.model.webfinger.WebFinger
|
||||
import dev.usbharu.hideout.activitypub.service.webfinger.WebFingerApiService
|
||||
import dev.usbharu.hideout.application.config.ApplicationConfig
|
||||
import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException
|
||||
import dev.usbharu.hideout.core.domain.exception.resource.UserNotFoundException
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
|
@ -82,9 +82,12 @@ class WebFingerControllerTest {
|
|||
|
||||
@Test
|
||||
fun `webfinger 存在しないacctを指定したとき404 Not Foundが返ってくる`() = runTest {
|
||||
whenever(webFingerApiService.findByNameAndDomain(eq("fuga"), eq("example.com"))).doThrow(
|
||||
FailedToGetResourcesException::class
|
||||
)
|
||||
whenever(
|
||||
webFingerApiService.findByNameAndDomain(
|
||||
eq("fuga"),
|
||||
eq("example.com")
|
||||
)
|
||||
).doThrow(UserNotFoundException::class)
|
||||
|
||||
mockMvc.perform(get("/.well-known/webfinger?resource=acct:fuga@example.com"))
|
||||
.andDo(print())
|
||||
|
|
|
@ -3,6 +3,7 @@ package dev.usbharu.hideout.activitypub.service.activity.accept
|
|||
import dev.usbharu.hideout.activitypub.domain.model.Accept
|
||||
import dev.usbharu.hideout.activitypub.domain.model.Follow
|
||||
import dev.usbharu.hideout.activitypub.service.common.APRequestService
|
||||
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
|
||||
import dev.usbharu.hideout.core.external.job.DeliverAcceptJob
|
||||
import dev.usbharu.hideout.core.external.job.DeliverAcceptJobParam
|
||||
import kotlinx.coroutines.test.runTest
|
||||
|
@ -24,7 +25,7 @@ class APDeliverAcceptJobProcessorTest {
|
|||
private lateinit var apRequestService: APRequestService
|
||||
|
||||
@Mock
|
||||
private lateinit var actorQueryService: ActorQueryService
|
||||
private lateinit var actorRepository: ActorRepository
|
||||
|
||||
@Mock
|
||||
private lateinit var deliverAcceptJob: DeliverAcceptJob
|
||||
|
@ -39,7 +40,7 @@ class APDeliverAcceptJobProcessorTest {
|
|||
fun `process apPostが発行される`() = runTest {
|
||||
val user = UserBuilder.localUserOf()
|
||||
|
||||
whenever(actorQueryService.findById(eq(1))).doReturn(user)
|
||||
whenever(actorRepository.findById(eq(1))).doReturn(user)
|
||||
|
||||
val accept = Accept(
|
||||
apObject = Follow(
|
||||
|
|
|
@ -7,6 +7,7 @@ import dev.usbharu.hideout.activitypub.domain.model.Like
|
|||
import dev.usbharu.hideout.activitypub.service.common.ActivityPubProcessContext
|
||||
import dev.usbharu.hideout.activitypub.service.common.ActivityType
|
||||
import dev.usbharu.hideout.application.config.ActivityPubConfig
|
||||
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
|
||||
import dev.usbharu.hideout.core.service.relationship.RelationshipService
|
||||
import dev.usbharu.httpsignature.common.HttpHeaders
|
||||
import dev.usbharu.httpsignature.common.HttpMethod
|
||||
|
@ -33,7 +34,7 @@ import java.net.URL
|
|||
class ApAcceptProcessorTest {
|
||||
|
||||
@Mock
|
||||
private lateinit var actorQueryService: ActorQueryService
|
||||
private lateinit var actorRepository: ActorRepository
|
||||
|
||||
@Mock
|
||||
private lateinit var relationshipService: RelationshipService
|
||||
|
@ -66,9 +67,9 @@ class ApAcceptProcessorTest {
|
|||
)
|
||||
|
||||
val user = UserBuilder.localUserOf()
|
||||
whenever(actorQueryService.findByUrl(eq("https://example.com"))).doReturn(user)
|
||||
whenever(actorRepository.findByUrl(eq("https://example.com"))).doReturn(user)
|
||||
val remoteUser = UserBuilder.remoteUserOf()
|
||||
whenever(actorQueryService.findByUrl(eq("https://remote.example.com"))).doReturn(remoteUser)
|
||||
whenever(actorRepository.findByUrl(eq("https://remote.example.com"))).doReturn(remoteUser)
|
||||
|
||||
apAcceptProcessor.internalProcess(activity)
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import dev.usbharu.hideout.activitypub.query.NoteQueryService
|
|||
import dev.usbharu.hideout.activitypub.service.objects.note.APNoteServiceImpl
|
||||
import dev.usbharu.hideout.application.config.ActivityPubConfig
|
||||
import dev.usbharu.hideout.application.config.ApplicationConfig
|
||||
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
|
||||
import dev.usbharu.hideout.core.external.job.DeliverPostJob
|
||||
import dev.usbharu.hideout.core.query.FollowerQueryService
|
||||
import dev.usbharu.hideout.core.service.job.JobQueueParentService
|
||||
|
@ -35,7 +36,7 @@ class ApSendCreateServiceImplTest {
|
|||
private lateinit var jobQueueParentService: JobQueueParentService
|
||||
|
||||
@Mock
|
||||
private lateinit var actorQueryService: ActorQueryService
|
||||
private lateinit var actorRepository: ActorRepository
|
||||
|
||||
@Mock
|
||||
private lateinit var noteQueryService: NoteQueryService
|
||||
|
@ -67,7 +68,7 @@ class ApSendCreateServiceImplTest {
|
|||
)
|
||||
|
||||
whenever(followerQueryService.findFollowersById(eq(post.actorId))).doReturn(followers)
|
||||
whenever(actorQueryService.findById(eq(post.actorId))).doReturn(user)
|
||||
whenever(actorRepository.findById(eq(post.actorId))).doReturn(user)
|
||||
whenever(noteQueryService.findById(eq(post.id))).doReturn(note to post)
|
||||
|
||||
apSendCreateServiceImpl.createNote(post)
|
||||
|
|
|
@ -2,6 +2,8 @@ package dev.usbharu.hideout.activitypub.service.activity.like
|
|||
|
||||
|
||||
import dev.usbharu.hideout.application.service.id.TwitterSnowflakeIdGenerateService
|
||||
import dev.usbharu.hideout.core.domain.model.actor.ActorRepository
|
||||
import dev.usbharu.hideout.core.domain.model.post.PostRepository
|
||||
import dev.usbharu.hideout.core.domain.model.reaction.Reaction
|
||||
import dev.usbharu.hideout.core.external.job.DeliverReactionJob
|
||||
import dev.usbharu.hideout.core.external.job.DeliverRemoveReactionJob
|
||||
|
@ -21,7 +23,7 @@ class APReactionServiceImplTest {
|
|||
val user = UserBuilder.localUserOf()
|
||||
val post = PostBuilder.of()
|
||||
|
||||
val postQueryService = mock<PostQueryService> {
|
||||
val postQueryService = mock<PostRepository> {
|
||||
onBlocking { findById(eq(post.id)) } doReturn post
|
||||
}
|
||||
val followerQueryService = mock<FollowerQueryService> {
|
||||
|
@ -32,11 +34,14 @@ class APReactionServiceImplTest {
|
|||
)
|
||||
}
|
||||
val jobQueueParentService = mock<JobQueueParentService>()
|
||||
val actorRepository = mock<ActorRepository> {
|
||||
onBlocking { findById(eq(user.id)) }.doReturn(user)
|
||||
}
|
||||
val apReactionServiceImpl = APReactionServiceImpl(
|
||||
jobQueueParentService = jobQueueParentService,
|
||||
actorQueryService = mock(),
|
||||
actorRepository = actorRepository,
|
||||
followerQueryService = followerQueryService,
|
||||
postQueryService = postQueryService,
|
||||
postRepository = postQueryService,
|
||||
objectMapper = objectMapper
|
||||
)
|
||||
|
||||
|
@ -58,7 +63,7 @@ class APReactionServiceImplTest {
|
|||
val user = UserBuilder.localUserOf()
|
||||
val post = PostBuilder.of()
|
||||
|
||||
val postQueryService = mock<PostQueryService> {
|
||||
val postQueryService = mock<PostRepository> {
|
||||
onBlocking { findById(eq(post.id)) } doReturn post
|
||||
}
|
||||
val followerQueryService = mock<FollowerQueryService> {
|
||||
|
@ -69,11 +74,14 @@ class APReactionServiceImplTest {
|
|||
)
|
||||
}
|
||||
val jobQueueParentService = mock<JobQueueParentService>()
|
||||
val actorRepository = mock<ActorRepository> {
|
||||
onBlocking { findById(eq(user.id)) }.doReturn(user)
|
||||
}
|
||||
val apReactionServiceImpl = APReactionServiceImpl(
|
||||
jobQueueParentService = jobQueueParentService,
|
||||
actorQueryService = mock(),
|
||||
actorRepository = actorRepository,
|
||||
followerQueryService = followerQueryService,
|
||||
postQueryService = postQueryService,
|
||||
postRepository = postQueryService,
|
||||
objectMapper = objectMapper
|
||||
)
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@ import dev.usbharu.hideout.activitypub.service.objects.note.APNoteServiceImpl.Co
|
|||
import dev.usbharu.hideout.activitypub.service.objects.user.APUserService
|
||||
import dev.usbharu.hideout.application.config.CharacterLimit
|
||||
import dev.usbharu.hideout.application.service.id.TwitterSnowflakeIdGenerateService
|
||||
import dev.usbharu.hideout.core.domain.exception.FailedToGetResourcesException
|
||||
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.PostRepository
|
||||
import dev.usbharu.hideout.core.service.post.PostService
|
||||
|
@ -50,7 +50,7 @@ class APNoteServiceImplTest {
|
|||
val post = PostBuilder.of()
|
||||
|
||||
val user = UserBuilder.localUserOf(id = post.actorId)
|
||||
val actorQueryService = mock<ActorQueryService> {
|
||||
val actorQueryService = mock<ActorRepository> {
|
||||
onBlocking { findById(eq(post.actorId)) } doReturn user
|
||||
}
|
||||
val expected = Note(
|
||||
|
@ -86,13 +86,9 @@ class APNoteServiceImplTest {
|
|||
val url = "https://example.com/note"
|
||||
val post = PostBuilder.of()
|
||||
|
||||
val postQueryService = mock<PostQueryService> {
|
||||
onBlocking { findByApId(eq(post.apId)) } doReturn post
|
||||
}
|
||||
|
||||
val user = UserBuilder.localUserOf(id = post.actorId)
|
||||
val actorQueryService = mock<ActorQueryService> {
|
||||
onBlocking { findById(eq(post.actorId)) } doReturn user
|
||||
}
|
||||
|
||||
val note = Note(
|
||||
id = post.apId,
|
||||
attributedTo = user.url,
|
||||
|
@ -107,7 +103,7 @@ class APNoteServiceImplTest {
|
|||
onBlocking { resolve<Note>(eq(url), any(), isNull<Long>()) } doReturn note
|
||||
}
|
||||
val noteQueryService = mock<NoteQueryService> {
|
||||
onBlocking { findByApid(eq(url)) } doThrow FailedToGetResourcesException()
|
||||
onBlocking { findByApid(eq(url)) } doReturn null
|
||||
}
|
||||
val person = Person(
|
||||
name = user.name,
|
||||
|
@ -132,7 +128,7 @@ class APNoteServiceImplTest {
|
|||
following = user.following,
|
||||
manuallyApprovesFollowers = false
|
||||
|
||||
)
|
||||
)
|
||||
val apUserService = mock<APUserService> {
|
||||
onBlocking { fetchPersonWithEntity(eq(note.attributedTo!!), isNull()) } doReturn (person to user)
|
||||
}
|
||||
|
@ -159,25 +155,7 @@ class APNoteServiceImplTest {
|
|||
fun `fetchNote(String,String) ノートをリモートから取得した際にエラーが返ってきたらFailedToGetActivityPubResourceExceptionがthrowされる`() =
|
||||
runTest {
|
||||
val url = "https://example.com/note"
|
||||
val post = PostBuilder.of()
|
||||
|
||||
val postQueryService = mock<PostQueryService> {
|
||||
onBlocking { findByApId(eq(post.apId)) } doReturn post
|
||||
}
|
||||
val user = UserBuilder.localUserOf(id = post.actorId)
|
||||
val actorQueryService = mock<ActorQueryService> {
|
||||
onBlocking { findById(eq(post.actorId)) } doReturn user
|
||||
}
|
||||
val note = Note(
|
||||
id = post.apId,
|
||||
attributedTo = user.url,
|
||||
content = post.text,
|
||||
published = Instant.ofEpochMilli(post.createdAt).toString(),
|
||||
to = listOfNotNull(public, user.followers),
|
||||
sensitive = post.sensitive,
|
||||
cc = listOfNotNull(public, user.followers),
|
||||
inReplyTo = null
|
||||
)
|
||||
val apResourceResolveService = mock<APResourceResolveService> {
|
||||
val responseData = HttpResponseData(
|
||||
HttpStatusCode.BadRequest,
|
||||
|
@ -203,7 +181,7 @@ class APNoteServiceImplTest {
|
|||
)
|
||||
}
|
||||
val noteQueryService = mock<NoteQueryService> {
|
||||
onBlocking { findByApid(eq(url)) } doThrow FailedToGetResourcesException()
|
||||
onBlocking { findByApid(eq(url)) } doReturn null
|
||||
}
|
||||
val apNoteServiceImpl = APNoteServiceImpl(
|
||||
postRepository = mock(),
|
||||
|
@ -253,7 +231,7 @@ class APNoteServiceImplTest {
|
|||
}
|
||||
val postService = mock<PostService>()
|
||||
val noteQueryService = mock<NoteQueryService> {
|
||||
onBlocking { findByApid(eq(post.apId)) } doThrow FailedToGetResourcesException()
|
||||
onBlocking { findByApid(eq(post.apId)) } doReturn null
|
||||
}
|
||||
val apNoteServiceImpl = APNoteServiceImpl(
|
||||
postRepository = postRepository,
|
||||
|
@ -294,9 +272,6 @@ class APNoteServiceImplTest {
|
|||
val user = UserBuilder.localUserOf()
|
||||
val post = PostBuilder.of(userId = user.id)
|
||||
|
||||
val actorQueryService = mock<ActorQueryService> {
|
||||
onBlocking { findById(eq(user.id)) } doReturn user
|
||||
}
|
||||
val note = Note(
|
||||
id = post.apId,
|
||||
attributedTo = user.url,
|
||||
|
|
|
@ -2,6 +2,7 @@ package dev.usbharu.hideout.core.service.post
|
|||
|
||||
import dev.usbharu.hideout.activitypub.service.activity.create.ApSendCreateService
|
||||
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
|
||||
import dev.usbharu.hideout.core.domain.model.post.Post
|
||||
import dev.usbharu.hideout.core.domain.model.post.PostRepository
|
||||
|
@ -9,7 +10,6 @@ import dev.usbharu.hideout.core.domain.model.reaction.ReactionRepository
|
|||
import dev.usbharu.hideout.core.service.timeline.TimelineService
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.jetbrains.exposed.exceptions.ExposedSQLException
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
import org.mockito.InjectMocks
|
||||
|
@ -19,7 +19,6 @@ import org.mockito.Mockito.mockStatic
|
|||
import org.mockito.Spy
|
||||
import org.mockito.junit.jupiter.MockitoExtension
|
||||
import org.mockito.kotlin.*
|
||||
import org.springframework.dao.DuplicateKeyException
|
||||
import utils.PostBuilder
|
||||
import utils.UserBuilder
|
||||
import java.time.Instant
|
||||
|
@ -35,10 +34,6 @@ class PostServiceImplTest {
|
|||
|
||||
@Mock
|
||||
private lateinit var timelineService: TimelineService
|
||||
|
||||
@Mock
|
||||
private lateinit var postQueryService: PostQueryService
|
||||
|
||||
@Spy
|
||||
private var postBuilder: Post.PostBuilder = Post.PostBuilder(CharacterLimit())
|
||||
|
||||
|
@ -57,7 +52,7 @@ class PostServiceImplTest {
|
|||
val now = Instant.now()
|
||||
val post = PostBuilder.of(createdAt = now.toEpochMilli())
|
||||
|
||||
whenever(postRepository.save(eq(post))).doReturn(true)
|
||||
whenever(postRepository.save(eq(post))).doReturn(post)
|
||||
whenever(postRepository.generateId()).doReturn(post.id)
|
||||
whenever(actorRepository.findById(eq(post.actorId))).doReturn(UserBuilder.localUserOf(id = post.actorId))
|
||||
whenever(timelineService.publishTimeline(eq(post), eq(true))).doReturn(Unit)
|
||||
|
@ -90,7 +85,7 @@ class PostServiceImplTest {
|
|||
val post = PostBuilder.of()
|
||||
|
||||
whenever(actorRepository.findById(eq(post.actorId))).doReturn(UserBuilder.remoteUserOf(id = post.actorId))
|
||||
whenever(postRepository.save(eq(post))).doReturn(true)
|
||||
whenever(postRepository.save(eq(post))).doReturn(post)
|
||||
whenever(timelineService.publishTimeline(eq(post), eq(false))).doReturn(Unit)
|
||||
|
||||
|
||||
|
@ -108,23 +103,8 @@ class PostServiceImplTest {
|
|||
val post = PostBuilder.of()
|
||||
|
||||
whenever(actorRepository.findById(eq(post.actorId))).doReturn(UserBuilder.remoteUserOf(id = post.actorId))
|
||||
whenever(postRepository.save(eq(post))).doReturn(false)
|
||||
|
||||
val createLocal = postServiceImpl.createRemote(post)
|
||||
|
||||
assertThat(createLocal).isEqualTo(post)
|
||||
|
||||
verify(postRepository, times(1)).save(eq(post))
|
||||
verify(timelineService, times(0)).publishTimeline(any(), any())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `createRemote 既に作成されていることを検知できず例外が発生した場合はDBから取得して返す`() = runTest {
|
||||
val post = PostBuilder.of()
|
||||
|
||||
whenever(actorRepository.findById(eq(post.actorId))).doReturn(UserBuilder.remoteUserOf(id = post.actorId))
|
||||
whenever(postRepository.save(eq(post))).doAnswer { throw ExposedSQLException(null, emptyList(), mock()) }
|
||||
whenever(postQueryService.findByApId(eq(post.apId))).doReturn(post)
|
||||
whenever(postRepository.save(eq(post))).doAnswer { throw DuplicateException() }
|
||||
whenever(postRepository.findByApId(eq(post.apId))).doReturn(post)
|
||||
|
||||
val createLocal = postServiceImpl.createRemote(post)
|
||||
|
||||
|
@ -139,8 +119,9 @@ class PostServiceImplTest {
|
|||
val post = PostBuilder.of()
|
||||
|
||||
whenever(actorRepository.findById(eq(post.actorId))).doReturn(UserBuilder.remoteUserOf(id = post.actorId))
|
||||
whenever(postRepository.save(eq(post))).doReturn(true)
|
||||
whenever(timelineService.publishTimeline(eq(post), eq(false))).doThrow(DuplicateKeyException::class)
|
||||
whenever(postRepository.save(eq(post))).doReturn(post)
|
||||
whenever(timelineService.publishTimeline(eq(post), eq(false))).doThrow(DuplicateException::class)
|
||||
whenever(postRepository.findByApId(eq(post.apId))).doReturn(post)
|
||||
|
||||
val createLocal = postServiceImpl.createRemote(post)
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ 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 kotlinx.coroutines.test.runTest
|
||||
|
@ -25,9 +24,6 @@ class ReactionServiceImplTest {
|
|||
@Mock
|
||||
private lateinit var apReactionService: APReactionService
|
||||
|
||||
@Mock
|
||||
private lateinit var reactionQueryService: ReactionQueryService
|
||||
|
||||
@InjectMocks
|
||||
private lateinit var reactionServiceImpl: ReactionServiceImpl
|
||||
|
||||
|
@ -36,7 +32,9 @@ class ReactionServiceImplTest {
|
|||
|
||||
val post = PostBuilder.of()
|
||||
|
||||
whenever(reactionQueryService.reactionAlreadyExist(eq(post.id), eq(post.actorId), eq(0))).doReturn(false)
|
||||
whenever(reactionRepository.existByPostIdAndActorIdAndEmojiId(eq(post.id), eq(post.actorId), eq(0))).doReturn(
|
||||
false
|
||||
)
|
||||
val generateId = TwitterSnowflakeIdGenerateService.generateId()
|
||||
whenever(reactionRepository.generateId()).doReturn(generateId)
|
||||
|
||||
|
@ -49,7 +47,9 @@ class ReactionServiceImplTest {
|
|||
fun `receiveReaction リアクションが既に作成されていることを検知出来ずに例外が発生した場合は何もしない`() = runTest {
|
||||
val post = PostBuilder.of()
|
||||
|
||||
whenever(reactionQueryService.reactionAlreadyExist(eq(post.id), eq(post.actorId), eq(0))).doReturn(false)
|
||||
whenever(reactionRepository.existByPostIdAndActorIdAndEmojiId(eq(post.id), eq(post.actorId), eq(0))).doReturn(
|
||||
false
|
||||
)
|
||||
val generateId = TwitterSnowflakeIdGenerateService.generateId()
|
||||
whenever(
|
||||
reactionRepository.save(
|
||||
|
@ -78,7 +78,9 @@ class ReactionServiceImplTest {
|
|||
@Test
|
||||
fun `receiveReaction リアクションが既に作成されている場合は何もしない`() = runTest() {
|
||||
val post = PostBuilder.of()
|
||||
whenever(reactionQueryService.reactionAlreadyExist(eq(post.id), eq(post.actorId), eq(0))).doReturn(true)
|
||||
whenever(reactionRepository.existByPostIdAndActorIdAndEmojiId(eq(post.id), eq(post.actorId), eq(0))).doReturn(
|
||||
true
|
||||
)
|
||||
|
||||
reactionServiceImpl.receiveReaction("❤", "example.com", post.actorId, post.id)
|
||||
|
||||
|
@ -88,8 +90,8 @@ class ReactionServiceImplTest {
|
|||
@Test
|
||||
fun `sendReaction リアクションが存在しないとき保存して配送する`() = runTest {
|
||||
val post = PostBuilder.of()
|
||||
whenever(reactionQueryService.findByPostIdAndActorIdAndEmojiId(eq(post.id), eq(post.actorId), eq(0))).doThrow(
|
||||
FailedToGetResourcesException::class
|
||||
whenever(reactionRepository.findByPostIdAndActorIdAndEmojiId(eq(post.id), eq(post.actorId), eq(0))).doReturn(
|
||||
null
|
||||
)
|
||||
val generateId = TwitterSnowflakeIdGenerateService.generateId()
|
||||
whenever(reactionRepository.generateId()).doReturn(generateId)
|
||||
|
@ -104,7 +106,7 @@ class ReactionServiceImplTest {
|
|||
fun `sendReaction リアクションが存在するときは削除して保存して配送する`() = runTest {
|
||||
val post = PostBuilder.of()
|
||||
val id = TwitterSnowflakeIdGenerateService.generateId()
|
||||
whenever(reactionQueryService.findByPostIdAndActorIdAndEmojiId(eq(post.id), eq(post.actorId), eq(0))).doReturn(
|
||||
whenever(reactionRepository.findByPostIdAndActorIdAndEmojiId(eq(post.id), eq(post.actorId), eq(0))).doReturn(
|
||||
Reaction(id, 0, post.id, post.actorId)
|
||||
)
|
||||
val generateId = TwitterSnowflakeIdGenerateService.generateId()
|
||||
|
@ -122,7 +124,7 @@ class ReactionServiceImplTest {
|
|||
@Test
|
||||
fun `removeReaction リアクションが存在する場合削除して配送`() = runTest {
|
||||
val post = PostBuilder.of()
|
||||
whenever(reactionQueryService.findByPostIdAndActorIdAndEmojiId(eq(post.id), eq(post.actorId), eq(0))).doReturn(
|
||||
whenever(reactionRepository.findByPostIdAndActorIdAndEmojiId(eq(post.id), eq(post.actorId), eq(0))).doReturn(
|
||||
Reaction(0, 0, post.id, post.actorId)
|
||||
)
|
||||
|
||||
|
|
|
@ -28,9 +28,6 @@ class RelationshipServiceImplTest {
|
|||
@Spy
|
||||
private val applicationConfig = ApplicationConfig(URL("https://example.com"))
|
||||
|
||||
@Mock
|
||||
private lateinit var actorQueryService: ActorQueryService
|
||||
|
||||
@Mock
|
||||
private lateinit var relationshipRepository: RelationshipRepository
|
||||
|
||||
|
@ -57,7 +54,7 @@ class RelationshipServiceImplTest {
|
|||
|
||||
@Test
|
||||
fun `followRequest ローカルの場合followRequestフラグがtrueで永続化される`() = runTest {
|
||||
whenever(actorQueryService.findById(eq(5678))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
||||
whenever(actorRepository.findById(eq(5678))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
||||
|
||||
relationshipServiceImpl.followRequest(1234, 5678)
|
||||
|
||||
|
@ -79,9 +76,9 @@ class RelationshipServiceImplTest {
|
|||
@Test
|
||||
fun `followRequest リモートの場合Followアクティビティが配送される`() = runTest {
|
||||
val localUser = UserBuilder.localUserOf(domain = "example.com")
|
||||
whenever(actorQueryService.findById(eq(1234))).doReturn(localUser)
|
||||
whenever(actorRepository.findById(eq(1234))).doReturn(localUser)
|
||||
val remoteUser = UserBuilder.remoteUserOf(domain = "remote.example.com")
|
||||
whenever(actorQueryService.findById(eq(5678))).doReturn(remoteUser)
|
||||
whenever(actorRepository.findById(eq(5678))).doReturn(remoteUser)
|
||||
|
||||
relationshipServiceImpl.followRequest(1234, 5678)
|
||||
|
||||
|
@ -144,9 +141,9 @@ class RelationshipServiceImplTest {
|
|||
@Test
|
||||
fun `followRequest 既にフォローしている場合は念の為フォロー承認を自動で行う`() = runTest {
|
||||
val remoteUser = UserBuilder.remoteUserOf(domain = "remote.example.com")
|
||||
whenever(actorQueryService.findById(eq(1234))).doReturn(remoteUser)
|
||||
whenever(actorRepository.findById(eq(1234))).doReturn(remoteUser)
|
||||
val localUser = UserBuilder.localUserOf(domain = "example.com")
|
||||
whenever(actorQueryService.findById(eq(5678))).doReturn(localUser)
|
||||
whenever(actorRepository.findById(eq(5678))).doReturn(localUser)
|
||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(
|
||||
Relationship(
|
||||
actorId = 1234,
|
||||
|
@ -212,8 +209,8 @@ class RelationshipServiceImplTest {
|
|||
|
||||
@Test
|
||||
fun `block ローカルユーザーの場合永続化される`() = runTest {
|
||||
whenever(actorQueryService.findById(eq(1234))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
||||
whenever(actorQueryService.findById(eq(5678))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
||||
whenever(actorRepository.findById(eq(1234))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
||||
whenever(actorRepository.findById(eq(5678))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
||||
|
||||
relationshipServiceImpl.block(1234, 5678)
|
||||
|
||||
|
@ -235,9 +232,9 @@ class RelationshipServiceImplTest {
|
|||
@Test
|
||||
fun `block リモートユーザーの場合永続化されて配送される`() = runTest {
|
||||
val localUser = UserBuilder.localUserOf(domain = "example.com")
|
||||
whenever(actorQueryService.findById(eq(1234))).doReturn(localUser)
|
||||
whenever(actorRepository.findById(eq(1234))).doReturn(localUser)
|
||||
val remoteUser = UserBuilder.remoteUserOf(domain = "remote.example.com")
|
||||
whenever(actorQueryService.findById(eq(5678))).doReturn(remoteUser)
|
||||
whenever(actorRepository.findById(eq(5678))).doReturn(remoteUser)
|
||||
|
||||
relationshipServiceImpl.block(1234, 5678)
|
||||
|
||||
|
@ -260,8 +257,8 @@ class RelationshipServiceImplTest {
|
|||
|
||||
@Test
|
||||
fun `acceptFollowRequest ローカルユーザーの場合永続化される`() = runTest {
|
||||
whenever(actorQueryService.findById(eq(1234))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
||||
whenever(actorQueryService.findById(eq(5678))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
||||
whenever(actorRepository.findById(eq(1234))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
||||
whenever(actorRepository.findById(eq(5678))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
||||
|
||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(5678), eq(1234))).doReturn(
|
||||
Relationship(
|
||||
|
@ -295,9 +292,9 @@ class RelationshipServiceImplTest {
|
|||
@Test
|
||||
fun `acceptFollowRequest リモートユーザーの場合永続化されて配送される`() = runTest {
|
||||
val localUser = UserBuilder.localUserOf(domain = "example.com")
|
||||
whenever(actorQueryService.findById(eq(1234))).doReturn(localUser)
|
||||
whenever(actorRepository.findById(eq(1234))).doReturn(localUser)
|
||||
val remoteUser = UserBuilder.remoteUserOf(domain = "remote.example.com")
|
||||
whenever(actorQueryService.findById(eq(5678))).doReturn(remoteUser)
|
||||
whenever(actorRepository.findById(eq(5678))).doReturn(remoteUser)
|
||||
|
||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(5678), eq(1234))).doReturn(
|
||||
Relationship(
|
||||
|
@ -352,8 +349,8 @@ class RelationshipServiceImplTest {
|
|||
|
||||
@Test
|
||||
fun `acceptFollowRequest フォローリクエストが存在せずforceがtrueのときフォローを承認する`() = runTest {
|
||||
whenever(actorQueryService.findById(eq(1234))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
||||
whenever(actorQueryService.findById(eq(5678))).doReturn(UserBuilder.remoteUserOf(domain = "remote.example.com"))
|
||||
whenever(actorRepository.findById(eq(1234))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
||||
whenever(actorRepository.findById(eq(5678))).doReturn(UserBuilder.remoteUserOf(domain = "remote.example.com"))
|
||||
|
||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(5678), eq(1234))).doReturn(
|
||||
Relationship(
|
||||
|
@ -416,7 +413,7 @@ class RelationshipServiceImplTest {
|
|||
|
||||
@Test
|
||||
fun `rejectFollowRequest ローカルユーザーの場合永続化される`() = runTest {
|
||||
whenever(actorQueryService.findById(eq(5678))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
||||
whenever(actorRepository.findById(eq(5678))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
||||
|
||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(5678), eq(1234))).doReturn(
|
||||
Relationship(
|
||||
|
@ -452,10 +449,10 @@ class RelationshipServiceImplTest {
|
|||
@Test
|
||||
fun `rejectFollowRequest リモートユーザーの場合永続化されて配送される`() = runTest {
|
||||
val localUser = UserBuilder.localUserOf(domain = "example.com")
|
||||
whenever(actorQueryService.findById(eq(1234))).doReturn(localUser)
|
||||
whenever(actorRepository.findById(eq(1234))).doReturn(localUser)
|
||||
|
||||
val remoteUser = UserBuilder.remoteUserOf(domain = "remote.example.com")
|
||||
whenever(actorQueryService.findById(eq(5678))).doReturn(remoteUser)
|
||||
whenever(actorRepository.findById(eq(5678))).doReturn(remoteUser)
|
||||
|
||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(5678), eq(1234))).doReturn(
|
||||
Relationship(
|
||||
|
@ -536,8 +533,8 @@ class RelationshipServiceImplTest {
|
|||
|
||||
@Test
|
||||
fun `unfollow ローカルユーザーの場合永続化される`() = runTest {
|
||||
whenever(actorQueryService.findById(eq(1234))).doReturn(UserBuilder.remoteUserOf(domain = "remote.example.com"))
|
||||
whenever(actorQueryService.findById(eq(5678))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
||||
whenever(actorRepository.findById(eq(1234))).doReturn(UserBuilder.remoteUserOf(domain = "remote.example.com"))
|
||||
whenever(actorRepository.findById(eq(5678))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(
|
||||
Relationship(
|
||||
actorId = 1234,
|
||||
|
@ -572,10 +569,10 @@ class RelationshipServiceImplTest {
|
|||
@Test
|
||||
fun `unfollow リモートユーザー場合永続化されて配送される`() = runTest {
|
||||
val localUser = UserBuilder.localUserOf(domain = "example.com")
|
||||
whenever(actorQueryService.findById(eq(1234))).doReturn(localUser)
|
||||
whenever(actorRepository.findById(eq(1234))).doReturn(localUser)
|
||||
|
||||
val remoteUser = UserBuilder.remoteUserOf(domain = "remote.example.com")
|
||||
whenever(actorQueryService.findById(eq(5678))).doReturn(remoteUser)
|
||||
whenever(actorRepository.findById(eq(5678))).doReturn(remoteUser)
|
||||
|
||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(
|
||||
Relationship(
|
||||
|
@ -617,6 +614,9 @@ class RelationshipServiceImplTest {
|
|||
|
||||
@Test
|
||||
fun `unfollow フォローしていなかった場合は何もしない`() = runTest {
|
||||
whenever(actorRepository.findById(eq(1234))).doReturn(UserBuilder.localUserOf(id = 1234))
|
||||
whenever(actorRepository.findById(eq(5678))).doReturn(UserBuilder.localUserOf(id = 5678))
|
||||
|
||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(
|
||||
Relationship(
|
||||
actorId = 1234,
|
||||
|
@ -636,7 +636,7 @@ class RelationshipServiceImplTest {
|
|||
|
||||
@Test
|
||||
fun `unblock ローカルユーザーの場合永続化される`() = runTest {
|
||||
whenever(actorQueryService.findById(eq(5678))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
||||
whenever(actorRepository.findById(eq(5678))).doReturn(UserBuilder.localUserOf(domain = "example.com"))
|
||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(
|
||||
Relationship(
|
||||
actorId = 1234,
|
||||
|
@ -671,10 +671,10 @@ class RelationshipServiceImplTest {
|
|||
@Test
|
||||
fun `unblock リモートユーザーの場合永続化されて配送される`() = runTest {
|
||||
val localUser = UserBuilder.localUserOf(domain = "example.com")
|
||||
whenever(actorQueryService.findById(eq(1234))).doReturn(localUser)
|
||||
whenever(actorRepository.findById(eq(1234))).doReturn(localUser)
|
||||
|
||||
val remoteUser = UserBuilder.remoteUserOf(domain = "remote.example.com")
|
||||
whenever(actorQueryService.findById(eq(5678))).doReturn(remoteUser)
|
||||
whenever(actorRepository.findById(eq(5678))).doReturn(remoteUser)
|
||||
|
||||
whenever(relationshipRepository.findByUserIdAndTargetUserId(eq(1234), eq(5678))).doReturn(
|
||||
Relationship(
|
||||
|
|
|
@ -2,6 +2,7 @@ package dev.usbharu.hideout.core.service.timeline
|
|||
|
||||
import dev.usbharu.hideout.application.service.id.TwitterSnowflakeIdGenerateService
|
||||
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.post.Visibility
|
||||
import dev.usbharu.hideout.core.domain.model.timeline.Timeline
|
||||
import dev.usbharu.hideout.core.domain.model.timeline.TimelineRepository
|
||||
|
@ -26,7 +27,7 @@ class TimelineServiceTest {
|
|||
private lateinit var followerQueryService: FollowerQueryService
|
||||
|
||||
@Mock
|
||||
private lateinit var actorQueryService: ActorQueryService
|
||||
private lateinit var actorRepository: ActorRepository
|
||||
|
||||
@Mock
|
||||
private lateinit var timelineRepository: TimelineRepository
|
||||
|
@ -44,7 +45,7 @@ class TimelineServiceTest {
|
|||
val localUserOf = UserBuilder.localUserOf(id = post.actorId)
|
||||
|
||||
whenever(followerQueryService.findFollowersById(eq(post.actorId))).doReturn(listOf)
|
||||
whenever(actorQueryService.findById(eq(post.actorId))).doReturn(localUserOf)
|
||||
whenever(actorRepository.findById(eq(post.actorId))).doReturn(localUserOf)
|
||||
whenever(timelineRepository.generateId()).doReturn(TwitterSnowflakeIdGenerateService.generateId())
|
||||
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ package dev.usbharu.hideout.core.service.user
|
|||
|
||||
import dev.usbharu.hideout.application.config.ApplicationConfig
|
||||
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.ActorRepository
|
||||
import dev.usbharu.hideout.core.domain.model.post.Post
|
||||
|
@ -70,14 +69,7 @@ class ActorServiceTest {
|
|||
val actorRepository = mock<ActorRepository> {
|
||||
onBlocking { nextId() } doReturn 113345L
|
||||
}
|
||||
val deletedActorQueryService = mock<DeletedActorQueryService> {
|
||||
onBlocking {
|
||||
findByNameAndDomain(
|
||||
eq("test"),
|
||||
eq("remote.example.com")
|
||||
)
|
||||
} doAnswer { throw FailedToGetResourcesException() }
|
||||
}
|
||||
|
||||
val userService =
|
||||
UserServiceImpl(
|
||||
actorRepository = actorRepository,
|
||||
|
|
|
@ -48,10 +48,7 @@ class AccountApiServiceImplTest {
|
|||
|
||||
@Mock
|
||||
private lateinit var relationshipRepository: RelationshipRepository
|
||||
|
||||
@Mock
|
||||
private lateinit var relationshipQueryService: RelationshipQueryService
|
||||
|
||||
|
||||
@Mock
|
||||
private lateinit var mediaService: MediaService
|
||||
|
||||
|
|
Loading…
Reference in New Issue